我将keras文档提供的代码用于ImageDataGenerator 而且我不断收到此错误
文件“ C:\ Users \ abirf \ AppData \ Local \ Continuum \ anaconda3 \ envs \ deep_learning \ lib \ site-packages \ keras \ engine \ training_utils.py”,第34行,位于standardize_single_array elif x.ndim == 1:
AttributeError:“ zip”对象没有属性“ ndim”
X_path= os.path.join('......./train_data/', 'images') # input image
Y_path = os.path.join('......../train_data/', 'masks') # ground-truth label
# we create two instances with the same arguments
data_gen_args = dict(#featurewise_center=True,
#featurewise_std_normalization=True,
rotation_range=45.,
#width_shift_range=0.1,
#height_shift_range=0.1,
zoom_range=[0.2])
seed = 1
image_datagen = ImageDataGenerator(**data_gen_args)
mask_datagen = ImageDataGenerator(**data_gen_args)
image_generator = image_datagen.flow_from_directory(X_path , class_mode=None, seed=seed,batch_size = 1,
target_size=(img_col,img_row),color_mode='grayscale')
mask_generator = mask_datagen.flow_from_directory( Y_path, class_mode=None, seed=seed,batch_size = 1 ,target_size=(img_col, img_row),color_mode='grayscale')
num_train = len(image_generator)
train_generator = zip(image_generator, mask_generator)
model = model.fit(train_generator, steps_per_epoch=num_train, shuffle=True, validation_split=0.1 , batch_size=16, epochs=50,callbacks=[earlystopper, checkpointer])
有人可以向我解释怎么了吗?
答案 0 :(得分:0)
在以下行中:
model = model.fit(train_generator, steps_per_epoch=num_train, shuffle=True, validation_split=0.1 , batch_size=16, epochs=50,callbacks=[earlystopper, checkpointer])
第一个参数是zip函数返回的zip
对象。根据Keras文档,model.fit()
可以采用多种格式,其中第一种是numpy数组,这是期望的类,因为它是具有ndim
(维数)属性的类,因此出现错误消息。
https://keras.io/api/models/model_training_apis/
无论您要发送的第一个参数是什么,您都可能希望将zip
对象转换为列表。为此,请使用list(train_generator)
,如果要使用numpy数组,则可以使用np.array(trainGeneratorList)
,trainGeneratorList
是list
函数的帮助。