Skip to content

Instantly share code, notes, and snippets.

View totti0223's full-sized avatar

yosuke toda totti0223

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@totti0223
totti0223 / tomato_image_analysis_cnn_segmentation.ipynb
Last active July 27, 2020 05:10
tomato_image_analysis_CNN_segmentation.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@totti0223
totti0223 / file1.txt
Last active May 22, 2019 01:20
生物学者がディープラーニング可視化技術を実装しながら理解したい #2 Grad-CAM編 ref: https://qiita.com/totti0223/items/f57f917a32dddfae728f
#勾配を特徴マップごとに平均化します。
weights = np.mean(grads_val, axis=(0, 1))
#平均化したものと中間出力の内積をとります。(特徴マップごとにweightを乗算し、すべて足します)
grad_cam = np.dot(out_val, weights)
#ここで、grad_cam大きさは14*14です。もとの画像に重ね合わせるためリサイズします。
from scipy.ndimage.interpolation import zoom
grad_cam = zoom(grad_cam, images.shape[0]/grad_cam.shape[0])
@totti0223
totti0223 / file0.txt
Last active May 22, 2019 01:20
生物学者がディープラーニング可視化技術を実装しながら理解したい #1 ref: https://qiita.com/totti0223/items/122b4be9bbaafa40d9e9
#準備するkerasのtensor
target_data = 勾配を求めたいデータ
loss = 定義した損失
#要の勾配を定義する式。下記式は「target_dataのどこを微少変化させるとlossの値に影響が出るか」を微分した値で表現したデータを得るためのもの。得られるgradientsのshapeはtarget_dataと同じ
gradients = K.gradients(loss,target_data)[0]
#関数として定義。input_dataとK.leraning_phase()をいれてgradientを返す関数。
backprop_fn = K.function([input_data, K.learning_phase()], [gradients])