0

I wanted to merge two sequential models into one using a Merge layer but it is showing me an error. I am working with images, with size 128x128 (RGB image) and batch size is 32.

The error is:

ValueError: The model expects 3 input arrays, but only received one array. Found: array with shape (32, 3, 128, 128)

The model is defined as:

model = Sequential() leftBranch = Sequential() 

leftBranch.add(Reshape((3,128,128), input_shape=(3, img_width, img_height))) 
leftBranch.add(Convolution2D(14, 3, 1, activation='relu')) 
leftBranch.add(ZeroPadding2D((1, 1))) 
leftBranch.add(Flatten()) 

rightBranch = Sequential() 
rightBranch.add(Reshape((3,128,128), input_shape=(3, img_width, img_height))) 
rightBranch.add(Convolution2D(14, 1, 3, activation='relu')) 
rightBranch.add(MaxPooling2D((2, 2), strides=(2, 2))) 
rightBranch.add(Flatten()) 

centralBranch = Sequential() 
centralBranch.add(Reshape((3,128,128), input_shape=(3, img_width, img_height))) 
centralBranch.add(Convolution2D(14, 5, 5, activation='relu'))
centralBranch.add(MaxPooling2D((2, 2), strides=(2, 2)))
centralBranch.add(Flatten()) 
merged = Merge([leftBranch, centralBranch, rightBranch], mode='concat') 

model = Sequential() 
model.add(merged) model.add(Dense(64)) 
model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(1)) 
model.add(Activation('sigmoid'))

Error coming is :

ValueError: The model expects 3 input arrays, but only received one array. Found: array with shape (32, 3, 128, 128)

So, whats is the proper way to concatenate two sequential model with convolutional layers. I just want to Merge convolutional layers output like I did it here.

Blade
  • 984
  • 3
  • 12
  • 34
Rapa
  • 43
  • 9

0 Answers0