IMAGE_NAME = "000700.png"
img_path = f'../output/cams/{IMAGE_NAME}'Salience Entropy
One of the most straightforward ways of statistically summarizing the model’s salience is to study the entropy of generated salience maps. In terms of explainable-AI, well trained models typically have focused salience on the object it is classifying. High accuracy scores with unfocused salience maps may be indicators that the model has overfit the traiining data.
Measuring Entropy
Define parameters
Calculate Entropy
Read in the image
cam = mpimg.imread(img_path)Calculate entropy
entropy = skimage.measure.shannon_entropy(cam)Normalize Entropy
The normalization factor Sˆpmax(m,n) plays a key role in getting accurate estimates of the entropy in case of low- and varying-resolution and quantized data (such as Grad-CAMs) and requires a commentary.
normalized_entropy = round(entropy / 5.614, 3)
print(normalized_entropy)1.293
Display Image
fig = plt.figure(figsize=(10., 8.), facecolor='white')
grid = ImageGrid(fig, 111, # similar to subplot(111)
nrows_ncols=(1, 1), # creates 2x2 grid of axes
axes_pad=0.1, # pad between axes in inch.
)
for index, (ax, im) in enumerate(zip(grid, [cam])):
# Iterating over the grid returns the Axes.
ax.axis('off')
ax.grid(b=None)
ax.imshow(im)
ax.set_title("Normalized Entropy: " + str(normalized_entropy), fontsize=30)
fig.set_size_inches(18, 9)
plt.show()ValueError: keyword grid_b is not recognized; valid keywords are ['size', 'width', 'color', 'tickdir', 'pad', 'labelsize', 'labelcolor', 'zorder', 'gridOn', 'tick1On', 'tick2On', 'label1On', 'label2On', 'length', 'direction', 'left', 'bottom', 'right', 'top', 'labelleft', 'labelbottom', 'labelright', 'labeltop', 'labelrotation', 'grid_agg_filter', 'grid_alpha', 'grid_animated', 'grid_antialiased', 'grid_clip_box', 'grid_clip_on', 'grid_clip_path', 'grid_color', 'grid_dash_capstyle', 'grid_dash_joinstyle', 'grid_dashes', 'grid_data', 'grid_drawstyle', 'grid_figure', 'grid_fillstyle', 'grid_gapcolor', 'grid_gid', 'grid_in_layout', 'grid_label', 'grid_linestyle', 'grid_linewidth', 'grid_marker', 'grid_markeredgecolor', 'grid_markeredgewidth', 'grid_markerfacecolor', 'grid_markerfacecoloralt', 'grid_markersize', 'grid_markevery', 'grid_mouseover', 'grid_path_effects', 'grid_picker', 'grid_pickradius', 'grid_rasterized', 'grid_sketch_params', 'grid_snap', 'grid_solid_capstyle', 'grid_solid_joinstyle', 'grid_transform', 'grid_url', 'grid_visible', 'grid_xdata', 'grid_ydata', 'grid_zorder', 'grid_aa', 'grid_c', 'grid_ds', 'grid_ls', 'grid_lw', 'grid_mec', 'grid_mew', 'grid_mfc', 'grid_mfcalt', 'grid_ms']
