0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

tf-explainのGrad CAMとOcclusion Sensitivityを見比べる

Last updated at Posted at 2020-03-20

#目的
tf-explainのGrad CAMとOcclusion Sensitivityを見比べる。

尚、tf-explainと
tf-explainのGrad CAMについては、
全22行のコードでGradCAM。tf_explainは、使い易いかも、お薦め!
をみて下さい。

#結果

Occlusion Sensitivity を動かすソース

超、簡単!!

occlu_sens_cat2_2nd_224.py
import tensorflow as tf

from tf_explain.core.occlusion_sensitivity import OcclusionSensitivity

IMAGE_PATH = "./cat2_2nd_224.jpg"

if __name__ == "__main__":
    model = tf.keras.applications.vgg16.VGG16(weights="imagenet", include_top=True)

    img = tf.keras.preprocessing.image.load_img(IMAGE_PATH, target_size=(224, 224))
    img = tf.keras.preprocessing.image.img_to_array(img)

    model.summary()
    data = ([img], None)

    tabby_cat_class_index = 281
    explainer = OcclusionSensitivity()##
    # Compute OcclusionSensitivity on VGG16
    grid = explainer.explain(
        data, model, class_index=tabby_cat_class_index, patch_size=32
    )

    explainer.save(grid, ".", "grad_cam_cat2_2nd_224Ocu32b.png")

結果

Grad CAM

grad_cam_cat2_2nd_224.png

Occlusion Sensitivity(patch_size = 32)

grad_cam_cat2_2nd_224Ocu32b.png

Occlusion Sensitivity(patch_size = 64)
これをみると、patch_size = 64は、ちょっと、サイズが大きすぎる気がしますが、この関数の作りにもよるかと。。。。
微妙に、tf-explainは、ノリが悪い???
(ここでのノリが悪いとは、 tabby_cat のポイントは、目の上、すなわち、額の部分の「M」の文字に見える模様であり、その部分にきっちりフォーカスがあたっていない意。)

grad_cam_cat2_2nd_224Ocu64b.png

patch_sizeをどうするかは、難しい!!!

#まとめ
微妙ー。(再掲)微妙に、tf-explainは、ノリが悪い???
(ここでのノリが悪いとは、 tabby_cat のポイントは、目の上、すなわち、額の部分の「M」の文字に見える模様であり、その部分にきっちりフォーカスがあたっていない意。)
コメントなどあれば、お願いしますっ。

0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?