question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Graph disconected: transfer-learning model with top-layer

See original GitHub issue

I built the transfer-learning model below. top_layer is used to resize images for utilizing more information of images .

conv_base = MobileNetV3Small(weights=‘imagenet’, include_top=False, input_shape=(224, 224, 3))

input_width=450 input_height=450
inputs = tf.keras.Input(shape=(input_height, input_width, 3))

top_layer = layers.Conv2D(filters=3, kernel_size=3, strides=1)(inputs) top_layer = layers.MaxPool2D(pool_size=(2, 2))(top_layer)

x = conv_base(top_layer, training=False) x = layers.GlobalAveragePooling2D()(x) #x = layers.Dropout(0.2)(x)

outputs = layers.Dense(1)(x) outputs = layers.Activation(“sigmoid”)(outputs)

model = Model(inputs, outputs)

Then when I try to call to GradCam I get: ValueError: Graph disconnected:

I reffered this site. But I am using top_layer, so I could not do same way. https://stackoverflow.com/questions/60623869/gradcam-with-guided-backprop-for-transfer-learning-in-tensorflow-2-0

How can I solve this? Could you give me any idea?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
keisencommented, Aug 3, 2021

@amessalas , you can avoid the error by improving get_model() function to as follows

def get_model():
    base_model = VGG16(
        weights="imagenet", include_top=False, input_shape=(32, 32, 3)
    )
    base_model.trainable = False
    x = base_model.output
    x = GlobalAveragePooling2D()(x)
    outputs = Dense(10, activation='softmax')(x)
    model = Model(base_model.inputs, outputs)
    return model

Thanks!

0reactions
rEstelacommented, Feb 7, 2022

Hi @keisen !

I have a similar problem here, don’t know if you could help me.

This is the model i need to use grad-cam: This is a binary classification problem.


Model: “functional_1”


Layer (type) Output Shape Param # Connected to


input_1 (InputLayer) [(None, 141, 898, 1 0 []
)]

input_2 (InputLayer) [(None, 12, 144, 22 0 []
4, 1)]

sequential (Sequential) (None, 64) 26448 [‘input_1[0][0]’]

sequential_1 (Sequential) (None, 96) 77424 [‘input_2[0][0]’]

concatenate (Concatenate) (None, 160) 0 [‘sequential[0][0]’,
‘sequential_1[0][0]’]

dense (Dense) (None, 16) 2576 [‘concatenate[0][0]’]

dense_1 (Dense) (None, 1) 17 [‘dense[0][0]’]

================================================================================================== Total params: 106,465 Trainable params: 105,697 Non-trainable params: 768


When i run Grad-Cam, i got this:

ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 12, 144, 224, 1), dtype=tf.float32, name=‘conv3d_input’), name=‘conv3d_input’, description=“created by layer ‘conv3d_input’”) at layer “conv3d”. The following previous layers were accessed without issue: []

Running ScoreCam i got the same answer…

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot obtain value for tensor KerasTensor() Transfer learning ...
Graph disconnected : cannot obtain value for tensor KerasTensor() Transfer learning ; 'old.model') # removes top 2 activation layers ; for i in ......
Read more >
Transfer learning and fine-tuning | TensorFlow Core
Transfer learning is usually done for tasks where your dataset has too little data to train a full-scale model from scratch.
Read more >
the following previous layers were accessed without issue: []
model = Model(label_inputs, dense). Open side panel. ValueError: Graph disconnected: cannot obtain value for tensor Tensor...The following previous layers ...
Read more >
ValueError: Graph disconnected - How to split a keras model ...
It is not possible to create the submodel as you define it because the LSTM1_decoder and LSTM2_decoder layers both depend on previous model...
Read more >
Chapter 7. Advanced deep-learning best practices
Using the Keras functional API, you can build graph-like models, share a layer across different inputs, and use Keras models just like Python...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found