Modification based on TORCHVISION.UTILS ::param: tensor (batch, channel, H, W)
(tensor, path, normalize: bool = False, scale_each: bool = False,)
| 39 | return model |
| 40 | |
| 41 | def 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 | |
| 56 | def save_image_saliancy_single(tensor, path, normalize: bool = False, scale_each: bool = False,): |
| 57 | """ |
no outgoing calls
no test coverage detected