Graph disconected: transfer-learning model with top-layer
See original GitHub issueI 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:
- Created 2 years ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
@amessalas , you can avoid the error by improving
get_model()
function to as followsThanks!
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…