Skip to content Skip to sidebar Skip to footer

Valueerror: A Merge Layer Should Be Called On A List Of Inputs. Tensorflow Keras

I am currently trying to use the first 50 layers of the MobileNetV2. Therefore, I want to extract those layers and create a new model. I thought I could just call every layer, but

Solution 1:

My guess is that the MobileNetV2 is not a sequential model, i.e. the layers graph is not linear. If you want just the output of the model and not any intermediate layer outputs, I think following code should do the job (even though it seems that you want to compute the last layer before output, the result still should be what you want):

import tensorflow as tf
from keras.models import Model

mobile_net=tf.keras.applications.mobilenet_v2.MobileNetV2(input_shape=(224,224,3), alpha=0.5, include_top=False, weights='imagenet')


inputs = Input(shape=(224, 224, 3))
output = mobile_net(inputs)

Solution 2:

I may be late but I guess this following code will do it for you

pre_trained_model = MobileNetV2(input_shape = (256, 256, 3), 
                            include_top = False, 
                            weights = "imagenet" )
last_layer = pre_trained_model.get_layer('block_15_project_BN'#the name of the last layer you want from the model)
last_output = last_layer.output
input_l = pre_trained_model.input
base_model1 = tf.keras.Model(input_l, last_output
                         )

Post a Comment for "Valueerror: A Merge Layer Should Be Called On A List Of Inputs. Tensorflow Keras"