MCPcopy Create free account
hub / github.com/ActiveVisionLab/DFNet / save_image_saliancy

Function save_image_saliancy

script/utils/utils.py:41–54  ·  view source on GitHub ↗

Modification based on TORCHVISION.UTILS ::param: tensor (batch, channel, H, W)

(tensor, path, normalize: bool = False, scale_each: bool = False,)

Source from the content-addressed store, hash-verified

39 return model
40
41def save_image_saliancy(tensor, path, normalize: bool = False, scale_each: bool = False,):
42 """
43 Modification based on TORCHVISION.UTILS
44 ::param: tensor (batch, channel, H, W)
45 """
46 # grid = make_grid(tensor.detach(), normalize=normalize, scale_each=scale_each, nrow=32)
47 grid = make_grid(tensor.detach(), normalize=normalize, scale_each=scale_each, nrow=6)
48 # Add 0.5 after unnormalizing to [0, 255] to round to nearest integer
49 ndarr = grid.mul(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to('cpu', torch.uint8).numpy()
50 fig = plt.figure()
51 plt.imshow(ndarr[:,:,0], cmap='jet') # viridis, plasma
52 plt.axis('off')
53 fig.savefig(path, bbox_inches='tight',dpi=fig.dpi,pad_inches=0.0)
54 plt.close()
55
56def save_image_saliancy_single(tensor, path, normalize: bool = False, scale_each: bool = False,):
57 """

Callers 6

tmp_plotFunction · 0.90
tmp_plot2Function · 0.90
tmp_plot3Function · 0.90
tmp_plot2Function · 0.90
print_feature_examplesFunction · 0.85
plot_featuresFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected