2022-03-21 14:31:44 +01:00
|
|
|
import argparse
|
2022-03-21 10:14:00 +01:00
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
2022-03-21 14:31:44 +01:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Calculate the froc metrics and store in froc_metrics.yml')
|
|
|
|
parser.add_argument('-experiment',
|
|
|
|
help='Title of experiment')
|
|
|
|
parser.add_argument('--series', '-s',
|
|
|
|
metavar='[series_name]', required=True, nargs='+',
|
|
|
|
help='List of series to include')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
########## constants #################
|
|
|
|
SERIES = args.series
|
|
|
|
series_ = '_'.join(args.series)
|
|
|
|
EXPERIMENT = args.experiment
|
|
|
|
SALIENCY_DIR = f'./../train_output/{EXPERIMENT}_{series_}/saliency.npy'
|
|
|
|
IMAGES_DIR = f'./../train_output/{EXPERIMENT}_{series_}/images_list.npy'
|
|
|
|
SEGMENTATION_DIR = f'./../train_output/{EXPERIMENT}_{series_}/segmentations.npy'
|
2022-03-23 17:00:22 +01:00
|
|
|
SLIDE = 10
|
2022-03-21 14:31:44 +01:00
|
|
|
|
|
|
|
########## load saliency map ############
|
|
|
|
heatmap = np.load(SALIENCY_DIR)
|
2022-03-21 10:14:00 +01:00
|
|
|
heatmap = np.squeeze(heatmap)
|
|
|
|
|
2022-03-21 14:31:44 +01:00
|
|
|
######### load images and segmentations ###########
|
|
|
|
images_list = np.load(IMAGES_DIR)
|
|
|
|
images_list = np.squeeze(images_list)
|
|
|
|
segmentations = np.load(SEGMENTATION_DIR)
|
|
|
|
######## take average ##########
|
|
|
|
# len(heatmap) is smaller then maximum number of images
|
|
|
|
# if len(heatmap) < 100:
|
|
|
|
# heatmap = np.mean(abs(heatmap),axis=0)
|
|
|
|
heatmap = abs(heatmap)
|
|
|
|
|
|
|
|
fig, axes = plt.subplots(2,len(SERIES))
|
|
|
|
print(np.shape(axes))
|
2022-03-21 10:14:00 +01:00
|
|
|
print(np.shape(heatmap))
|
2022-03-21 14:31:44 +01:00
|
|
|
print(np.shape(images_list))
|
2022-03-23 17:00:22 +01:00
|
|
|
max_value = np.amax(heatmap[:,:,SLIDE,:])
|
|
|
|
min_value = np.amin(heatmap[:,:,SLIDE,:])
|
2022-03-21 10:14:00 +01:00
|
|
|
|
2022-03-21 14:31:44 +01:00
|
|
|
for indx in range(len(SERIES)):
|
|
|
|
print(indx)
|
2022-03-23 17:00:22 +01:00
|
|
|
axes[0,indx].imshow(np.transpose(images_list[:,:,SLIDE,indx]),cmap='gray')
|
|
|
|
im = axes[1,indx].imshow(np.transpose(np.squeeze(heatmap[:,:,SLIDE,indx])),vmin=min_value, vmax=max_value)
|
2022-03-21 14:31:44 +01:00
|
|
|
axes[0,indx].set_title(SERIES[indx])
|
|
|
|
axes[0,indx].set_axis_off()
|
|
|
|
axes[1,indx].set_axis_off()
|
2022-03-21 10:14:00 +01:00
|
|
|
|
|
|
|
cbar = fig.colorbar(im, ax=axes.ravel().tolist(), shrink=0.5, orientation='horizontal')
|
2022-03-21 14:31:44 +01:00
|
|
|
cbar.set_ticks([min_value,max_value])
|
|
|
|
cbar.set_ticklabels(['less important', 'important'])
|
|
|
|
fig.suptitle('Saliency map', fontsize=16)
|
|
|
|
plt.savefig(f'./../train_output/{EXPERIMENT}_{series_}/saliency_map.png', dpi=300)
|
2022-03-21 10:14:00 +01:00
|
|
|
|