Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This code combine image and mask for image detection?
How can i correct that error?

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

This is the code used for training:

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)

This is the model I'm using:

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'])
like image 248
Wael Eid Avatar asked Dec 03 '22 21:12

Wael Eid


1 Answers

The selected answer is inaccurate. The reason why the code is failing is not because the tuples are of the ((input1,output1), (input2,output2)), ...), but because they are of the type (((input1, class1), (input2, class2), ...), ((output1, class1), (output2, class2), ...)).

You could have fixed your problem by simply adding class_mode=None to your flow_from_directory calls.

like image 85
Ricardo Magalhães Cruz Avatar answered Dec 06 '22 10:12

Ricardo Magalhães Cruz