Mon Feb 1 09:11:32 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.104 Driver Version: 410.104 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 Tesla V100-DGXS... On | 00000000:07:00.0 Off | 0 |
| N/A 65C P0 286W / 300W | 31558MiB / 32478MiB | 97% Default |
+-------------------------------+----------------------+----------------------+
| 1 Tesla V100-DGXS... On | 00000000:08:00.0 Off | 0 |
| N/A 61C P0 228W / 300W | 2630MiB / 32478MiB | 94% Default |
+-------------------------------+----------------------+----------------------+
| 2 Tesla V100-DGXS... On | 00000000:0E:00.0 Off | 0 |
| N/A 63C P0 238W / 300W | 5264MiB / 32478MiB | 98% Default |
+-------------------------------+----------------------+----------------------+
| 3 Tesla V100-DGXS... On | 00000000:0F:00.0 Off | 0 |
| N/A 63C P0 248W / 300W | 14704MiB / 32478MiB | 96% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+
1 2 3 4 5 6 7 8 9 10 11
# using gpu:/2 import tensorflow as tf import os os.environ["CUDA_VISIBLE_DEVICES"] = "2"
gpus = tf.config.experimental.list_physical_devices('GPU') if gpus: try: tf.config.experimental.set_memory_growth(gpus[0], True) except RuntimeError as e: print(e)
Setup
1 2 3 4 5 6 7 8 9 10 11 12 13
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt
from keras.applications import VGG16 from keras import layers from keras import models from keras.applications.vgg16 import preprocess_input, decode_predictions
img_path = '../sungjin/dog/test/bo/bo_26.jpg' img = image.load_img(img_path,target_size=(224,224)) x = image.img_to_array(img) x = np.expand_dims(x,axis=0) x = preprocess_input(x)
For each class c in the CNN, Grad−CAM is calculated with a linear combination of the k-th feature maps of the convolutional layer $A_k$ and the importance weight αc K, followed by ReLU activation:
1 2
# layer which calculate `score class` conv_layer = model.get_layer("block5_conv3")