对于多尺度 CNN 模型,我的数据集包含 10 个类,每类 2880 张图像。在训练模型时,Keras 生成器在 colab 中无效。
如何使用图像及其标签创建 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 ?