0

I want to enter multiple images(8) to the same CNN model at the same time. I built the bellow model:

inputShape = (height, width, depth)
input1 = Input(shape=(inputShape), name='input1')
input2 = Input(shape=(inputShape), name='input2')
input3 = Input(shape=(inputShape), name='input3')
input4 = Input(shape=(inputShape), name='input4')
input5 = Input(shape=(inputShape), name='input5')
input6 = Input(shape=(inputShape), name='input6')
input7 = Input(shape=(inputShape), name='input7')
input8 = Input(shape=(inputShape), name='input8')
x = concatenate([input1, input2, input3, input4, input5, input6, input7, input8])
conv_1 = Conv2D(filters=32, kernel_size=(3, 3), padding="same", activation="relu", name="conv_1")(x)
batch_norm_1 = BatchNormalization(axis=chanDim)(conv_1)
max_pool1 = MaxPooling2D(pool_size=(2, 2))(batch_norm_1)
drop_out1 = Dropout(0.25)(max_pool1)

conv_2 = Conv2D(filters=64, kernel_size=(3, 3), padding="same", activation="relu", name="conv_2")(drop_out1)
batch_norm_2 = BatchNormalization(axis=chanDim)(conv_2)
max_pool2 = MaxPooling2D(pool_size=(2, 2))(batch_norm_2)
drop_out2 = Dropout(0.25)(max_pool2)

out_01 = Flatten()(drop_out2)
out_02 = Dense(128, activation="relu")(out_01)
out_03 = BatchNormalization(axis=chanDim)(out_02)
out = Dropout(0.5)(out_03)

out2 = Dense(classes, activation="softmax")(out)
model = Model([input1, input2, input3, input4, input5, input6, input7, input8], out2)

ans this is my training

(trainX, testX, trainY, testY) = train_test_split(data, labels, test_size=0.2,                                      random_state=42)
aug = ImageDataGenerator(rotation_range=25, width_shift_range=0.1, height_shift_range=0.1, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode="nearest")
model.compile(loss="categorical_crossentropy", optimizer= opt,
          metrics=["accuracy"])
model.fit_generator( aug.flow(trainX, trainY, batch_size=BS), validation_data=(testX, testY), steps_per_epoch=len(trainX) // BS, epochs=EPOCHS, verbose=1)

I'm faced a problem with training the model, (trainnX, testX, trainY, testY) take one image, how can I make it take 8 images and how can I separate them in training and testing set. I have the following error:

ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 8 array(s), but instead got the following list of 1 arrays: [array([[[[0.96470588, 0.00392157, 0.01568627], ...
TypeError: 'NoneType' object is not callable

Can anyone please help me, Thanks alot.

Edit: I specify trainX, testX as a list as following:

([trainX], [testX], trainY, testY) = train_test_split(data, labels, test_size=0.2, random_state=42)
model.fit_generator(aug.flow([trainX], trainY, batch_size=BS), validation_data=([testX], testY), steps_per_epoch=len(trainX) // BS, epochs=EPOCHS, verbose=1)

but it give me the following error:

too many values to unpack (expected 1)

How can I determine them as a list of 8 images please?

hh tt
  • 395
  • 5
  • 22
  • trainX and testX should be of contains list 8 images for each batch. And also why are you using multi input? If the images are sequential you can use either Conv2DLSTM or Conv3D. – Mitiku Feb 23 '19 at 09:09
  • @Mitiku yes, the images are sequential. I cropped the image into 8 segments and I want to enter each 8 segments at the same time. does Conv2DLSTM or Conv3D useful in my case and which one is better? can you have any link clarify that. Thank you very much. – hh tt Feb 23 '19 at 12:32
  • If the length of sequences is always 8, then Conv3D could work, but if you want to deal with variable length sequences, Conv2DLSTM is a better choice. – Mitiku Feb 23 '19 at 12:41
  • yes, the length is always 8. I will try it. thank you. – hh tt Feb 23 '19 at 13:25
  • @Mitiku I determine trainX, testX as a list but it give me another error, I edited the post. I cannot able to use 3DConv and 3DMaxpooling, do you have any link. – hh tt Feb 23 '19 at 15:04

0 Answers0