TypeError:flow()缺少1个必需的位置参数:“ x”

我尝试运行此代码,但仍然遇到问题。

在这段代码中,我使用了预训练的神经resnet50,并尝试提取深层特征并预测我的课程。

请,如果有人遇到此错误,请告诉我该如何解决?

谢谢

NUM_CLASSES = 2
CHANNELS = 3
IMAGE_RESIZE = 224
REsnET50_POOLING_AVERAGE = 'avg'
DENSE_LAYER_actIVATION = 'softmax'
OBJECTIVE_FUNCTION = 'binary_crossentropy'
LOSS_METRICS = ['accuracy']
NUM_EPOCHS = 10
EARLY_STOP_PATIENCE = 3
STEPS_PER_EPOCH_TRAINING = 10
STEPS_PER_EPOCH_VALIDATION = 10
batch_size = 32
from keras.models import load_model
BATCH_SIZE_TRAINING = 100
BATCH_SIZE_VALIDATION = 100
image_size = IMAGE_RESIZE
WEIGHTS_PATH = "C:\\Users\\Desktop\\REsnET  \\resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5"
model = Sequential()
train_data_dir = "C:\\Users\\Desktop\\REsnET"
model = Resnet50(include_top=True,weights='imagenet')
model.layers.pop()
model = Model(input=model.input,output=model.layers[-1].output)
model.summary()
model.compile(loss='binary_crossentropy',optimizer=SGD(lr=0.01,momentum=0.9),metrics=['binary_accuracy'])

data_dir = "C:\\Users\\Desktop\\REsnET"
data_generator = ImageDataGenerator(preprocessing_function=preprocess_input)

train_datagenerator = ImageDataGenerator(rescale=1./255,shear_range=0.2,zoom_range=0.2,horizontal_flip=True,validation_split=0.2)
train_generator = train_datagenerator.flow_from_directory(
    train_data_dir,target_size=(image_size,image_size),batch_size=BATCH_SIZE_TRAINING,class_mode='categorical',shuffle=False,subset='training') # set as training data


validation_generator = train_datagenerator.flow_from_directory(
    train_data_dir,# same directory as training data kifkif
    target_size=(image_size,subset='validation') # set as validation data

generator = data_generator.flow(batch_size=batch_size)
batch_size = 32
X_train = np.zeros((len(train_generator.images_ids_in_subset),2048))
Y_train = np.zeros((len(train_generator.images_ids_in_subset),2))
nb_batches = int(len(train_generator.images_ids_in_subset) / batch_size) + 1

让我知道您是否有此问题

感谢您的帮助

gaoboxingf 回答:TypeError:flow()缺少1个必需的位置参数:“ x”

删除此行

generator = data_generator.flow(batch_size=batch_size)

如果您的代码到此结束,它什么也不做。

flow方法用于转换ram数据中已经存在的数据,但是您的代码没有。

本文链接:https://www.f2er.com/3150434.html

大家都在问