Modification based on TORCHVISION.UTILS, save single feature map ::param: tensor (batch, channel, H, W)
(tensor, path, normalize: bool = False, scale_each: bool = False,)
| 54 | plt.close() |
| 55 | |
| 56 | def save_image_saliancy_single(tensor, path, normalize: bool = False, scale_each: bool = False,): |
| 57 | """ |
| 58 | Modification based on TORCHVISION.UTILS, save single feature map |
| 59 | ::param: tensor (batch, channel, H, W) |
| 60 | """ |
| 61 | # grid = make_grid(tensor.detach(), normalize=normalize, scale_each=scale_each, nrow=32) |
| 62 | grid = make_grid(tensor.detach(), normalize=normalize, scale_each=scale_each, nrow=1) |
| 63 | # Add 0.5 after unnormalizing to [0, 255] to round to nearest integer |
| 64 | ndarr = grid.mul(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to('cpu', torch.uint8).numpy() |
| 65 | fig = plt.figure() |
| 66 | # plt.imshow(ndarr[:,:,0], cmap='plasma') # viridis, jet |
| 67 | plt.imshow(ndarr[:,:,0], cmap='jet') # viridis, jet |
| 68 | plt.axis('off') |
| 69 | fig.savefig(path, bbox_inches='tight',dpi=fig.dpi,pad_inches=0.0) |
| 70 | plt.close() |
| 71 | |
| 72 | def print_feature_examples(features, path): |
| 73 | """ |