Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value Error: Graph disconnected #165

Open
mohamedabdallah1996 opened this issue Mar 21, 2021 · 1 comment
Open

Value Error: Graph disconnected #165

mohamedabdallah1996 opened this issue Mar 21, 2021 · 1 comment

Comments

@mohamedabdallah1996
Copy link

I face this error after putting GradCAMCallback in the fit function. I don't understand why this happens because it raises this error after training one epoch. if the graph is disconnected I think the model will be broken and it won't be able to finish even one epoch.

this is my code:

def encoding_model():
      base_model = VGGFace(model='vgg16', include_top=False, input_shape=(224, 224, 3), pooling='avg')
      base_model.trainable = False
      flatten = Flatten()(base_model.layers[-2].output)
      fc1 = Dense(256, activation='relu', kernel_regularizer=regularizers.l2(0.1))(flatten)    
      drop1 = Dropout(0.3)(fc1)
      output = Dense(128)(drop1)

      model = Model(inputs=base_model.input, outputs=output)
      return model

def build_model():
      input1 = Input(input_shape)
      input2 = Input(input_shape)

      encoding = encoding_model()
      
      output1 = encoding.call(input1)
      output2 = encoding.call(input2)
      euclidean_distance = Lambda(euclidean_distance)([output1, output2]) 
      
      model = Model(inputs=[input1, input2], outputs=euclidean_distance)
      model.compile(...)

      return model`
`

image

full error message:
ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='input_10'), name='input_10', description="created by layer 'input_10'") at layer "conv1_1". The following previous layers were accessed without issue: ['conv1_1', 'conv1_1']

@andreafortini
Copy link

I faced the same problem when I trying to build a model with transfer learning as your case and I trying to access the layers inside the inner model. The inner model is signed as "Functional" if you check model.summary().

Try to don't leave default value layer_name=None into constructor of GradCAMCallback and put the last convolutional layer of your model: "conv5_3"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants