tabayashi0117 / Score-CAM

MIT License
56 stars 19 forks source link

Guided Score-CAM part incompatible with TF2.2 #7

Closed alexTse824 closed 3 years ago

alexTse824 commented 3 years ago

Hello I am training VGG16 on my own dataset with TF2.2. The Score-CAM part seemed fine. But when i working on the Guided Score-CAM part, it raise the error 'Tensor is not an element of this graph.' Here's the code:

`

layer_name = 'block5_conv3'

img_path = '1.jpg'

img_array = read_and_preprocess_img(img_path, size=(224,224))

model = load_model('my_model.h5')

guided_model = build_guided_model(model)

tf.compat.v1.disable_eager_execution()

saliency = GuidedBackPropagation(guided_model, img_array, layer_name)

`

Error screenshot:

截屏2020-11-23 下午11 36 07

This is my model: `conv_base = VGG16(include_top=False, weights='imagenet',input_shape=(224, 224, 3))

top_layer = Flatten()(conv_base.output)

top_layer = Dense(256, activation='relu')(top_layer)

top_layer = Dense(3, activation='softmax')(top_layer)

model = Model(inputs=conv_base.input, outputs=top_layer)

model.compile(optimizer=SGD(lr=1e-4), loss='categorical_crossentropy', metrics=['accuracy'])`

Any help would be appreciated, thanks!

kecsap commented 3 years ago

What is the output of model.summary() after model.compile()?

alexTse824 commented 3 years ago

What is the output of model.summary() after model.compile()?

截屏2020-11-24 上午10 21 02
tabayashi0117 commented 3 years ago

Hello @alexTse824 . Thank you for your comment. Unfortunately, I could not reproduce your error. However, I updated this repository to TensorFlow 2.3.1. All keras have been changed to tf.keras. Please try to use this.

alexTse824 commented 3 years ago

Hello @alexTse824 . Thank you for your comment. Unfortunately, I could not reproduce your error. However, I updated this repository to TensorFlow 2.3.1. All keras have been changed to tf.keras. Please try to use this.

Thanks for the update! I really appreciate that.