gpt4 book ai didi

python - batch_size = x.shape[0] AttributeError : 'tuple' object has no attribute 'shape'

转载 作者:行者123 更新时间:2023-11-28 19:53:11 24 4
gpt4 key购买 nike

此代码结合了图像和掩码以进行图像检测?
我该如何纠正该错误?

batch_size = x.shape[0] AttributeError: 'tuple' object has no attribute 'shape'

这是用于训练的代码:

train_datagen = ImageDataGenerator(
rescale=1. / 255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
train_datagen_1 = ImageDataGenerator(
rescale=1. / 255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)


train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(200, 150),
batch_size=1
)
train_generator_1= train_datagen_1.flow_from_directory(
train_data_dir_1,
target_size=(200, 150),
batch_size=1)
train_generator_2 = zip( train_generator, train_generator_1)

model.fit_generator(
train_generator_2,
steps_per_epoch=nb_train_samples // batch_size,
epochs=50)

这是我正在使用的模型:

model = Sequential() 
model.add(Conv2D(32, (3, 3), input_shape=(200, 150, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(20)) model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(90000))
model.add(Activation('sigmoid'))
model.compile(loss='mse', optimizer='rmsprop', metrics=['accuracy'])

最佳答案

所选答案不准确。代码失败的原因不是因为元组属于 ((input1,output1), (input2,output2)), ...),而是因为它们属于 类型>(((input1, class1), (input2, class2), ...), ((output1, class1), (output2, class2), ...))

您可以通过简单地将 class_mode=None 添加到您的 flow_from_directory 调用来解决您的问题。

关于python - batch_size = x.shape[0] AttributeError : 'tuple' object has no attribute 'shape' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46269642/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com