Problem with keras.Dense. The last dimension of the inputs to a Dense layer should be defined. Found None. Full input shape received: (None, None)

35 views Asked by At

I wrote some python code to develop a siamese network. The sub-clase from keras.Model is:

class modelSIAMESE(keras.Model): def init(self): super().init() input_shape = target_shape + (3,) input_a = Input(shape = input_shape) input_b = Input(shape = input_shape) input_activation = 'relu' hidden_activation = 'relu' output_activation = 'sigmoid' self.conv1 = Conv2D(128, kernel_size = (3, 3), activation=input_activation, input_shape=input_shape) self.pool1 = MaxPooling2D(pool_size = (2, 2)) self.conv2 = Conv2D(128, kernel_size = (3, 3), activation=hidden_activation) self.pool2 = MaxPooling2D(pool_size = (2, 2)) self.conv3 = Conv2D(128, kernel_size = (3, 3), activation=hidden_activation) self.pool3 = MaxPooling2D(pool_size = (2, 2)) self.flatten = Flatten() self.dense1 = Dense(128, activation="relu", input_shape=(None,)) # Procesar las imágenes de entrada a través de las capas compartidas self.norm_a = layers.BatchNormalization() #(self.flatten(self.pool3(self.conv3(self.pool2(self.conv2(self.pool1(self.conv1(input_a)))))))) self.norm_b = layers.BatchNormalization() #(self.flatten(self.pool3(self.conv3(self.pool2(self.conv2(self.pool1(self.conv1(input_b)))))))) # Definir la capa de comparación self.distance = keras.layers.Subtract() self.prediction = Dense(units=1, activation=output_activation, input_shape=(None,None)) self.dropout = keras.layers.Dropout(0.5) def call(self, inputs, training=False): input_a = inputs["input_a"] input_b = inputs["input_b"] x = self.conv1(input_a) y = self.conv1(input_b) x = self.pool1(x) y = self.pool1(y) x = self.conv2(x) y = self.conv2(y) x = self.pool2(x) y = self.pool2(y) x = self.conv3(x) y = self.conv3(y) x = self.pool3(x) y = self.pool3(y) x = self.dense1(x) y = self.dense1(y) x = self.norm_a(x) y = self.norm_b(y) x = self.flatten(x) y = self.flatten(y) d = self.distance([x, y]) # d = K.abs(d) d = self.dropout(d, training=training) return self.prediction(d)

But, when is running the compile and training methods, I received a exception error similar with my title, where the focused line is "return self.prediction(d)". I would be very grateful if someone could tell me where the error is and what code I should modify.

I have tried different ways and still can't solve it.

0

There are 0 answers