对于多尺度CNN模型,我的数据集包含10个类,每个2880张图像。 Keras生成器在训练模型时不能有效地协同工作。
如何使用图像及其标签创建npz文件。
def get_training_data(datafolder):
print("Loading training data...")
training_data = []
#Finds all files in datafolder
filenames = os.listdir(datafolder)
for filename in tqdm(filenames):
#Combines folder name and file name.
path = os.path.join(datafolder,filename)
#Opens an image as an Image object.
image = Image.open(path)
#Resizes to a desired size.
image = image.resize((image_width,image_height),)
#Creates an array of pixel values from the image.
pixel_array = np.asarray(image)
training_data.append(pixel_array)
#training_data is converted to a numpy array
training_data = np.reshape(training_data,(-1,image_width,image_height,channels))
return training_data
image_width=800
image_height=800
channels=3
x=get_training_data("/content/drive/My Drive/DL_2_Dataset/data/Week1")
x2=get_training_data("/content/drive/My Drive/DL_2_Dataset/data/Week1")
以上代码用于从dir创建numpy数组, 和
np.savez_compressed('new', week1=x, week2=x2)````
Saved into npz file,how to load labels for images ?