代码拉取完成,页面将自动刷新
import numpy as np
import os
import cv2
# raw_data_path: directory where the downloaded images are
# save_path: directory where the numpy images will be
raw_data_path = "data/raw_data/coast"
save_path = "data/prepared_data/"
files = os.listdir(raw_data_path)
input_shape = (256, 256)
# batch: each file will have N images
batch = 1000
# Dumping numpy batch images to save_path
counter = 1
def dumpy_numpy(data):
global counter
file_path = os.path.join(save_path, str(counter))
np.save(file_path, data)
counter += 1
# Converting to numpy files
bulk = []
if not len(files):
print("No images in: ", raw_data_path)
for i, file in enumerate(files, 1):
try:
image_path = os.path.join(raw_data_path, file)
image = cv2.imread(image_path)
image = cv2.resize(image, input_shape)
bulk.append(image)
except Exception as e:
print("error: ", e)
print("file name: ", image_path)
print("Proccessed: %s / %s image" %(i, len(files)))
if len(bulk) >= batch or i == len(files):
print("Dumping batch: ", len(bulk))
dumpy_numpy(bulk)
bulk = []
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。