print feature maps :param features: (3, [batch, H, W]) or [3, batch, H, W] :param path: save image path :param isList: wether the features is an list :return:
(features, path='f', isList=True)
| 101 | |
| 102 | |
| 103 | def plot_features(features, path='f', isList=True): |
| 104 | """ |
| 105 | print feature maps |
| 106 | :param features: (3, [batch, H, W]) or [3, batch, H, W] |
| 107 | :param path: save image path |
| 108 | :param isList: wether the features is an list |
| 109 | :return: |
| 110 | """ |
| 111 | kwargs = {'normalize': True, } # 'scale_each' : True |
| 112 | |
| 113 | if isList: |
| 114 | dim = features[0].dim() |
| 115 | else: |
| 116 | dim = features.dim() |
| 117 | assert (dim == 3 or dim == 4) |
| 118 | |
| 119 | if dim == 4 and isList: |
| 120 | print_feature_examples(features, path) |
| 121 | elif dim == 4 and (isList == False): |
| 122 | fn = path |
| 123 | lvl, b, H, W = features.shape |
| 124 | for i in range(features.shape[0]): |
| 125 | fn = path + '{}.png'.format(i) |
| 126 | save_image_saliancy(features[i][None, ...].permute(1, 0, 2, 3).cpu(), fn, normalize=True) |
| 127 | |
| 128 | # # concat everything |
| 129 | # features = features.reshape([-1, H, W]) |
| 130 | # # save_image(features[None,...].permute(1,0,2,3).cpu(), fn, **kwargs) |
| 131 | # save_image_saliancy(features[None,...].permute(1,0,2,3).cpu(), fn, normalize=True) |
| 132 | |
| 133 | elif dim == 3 and isList: # print all images in the list |
| 134 | for i in range(len(features)): |
| 135 | fn = path + '{}.png'.format(i) |
| 136 | # save_image(features[i][None,...].permute(1,0,2,3).cpu(), fn, **kwargs) |
| 137 | save_image_saliancy(features[i][None, ...].permute(1, 0, 2, 3).cpu(), fn, normalize=True) |
| 138 | elif dim == 3 and (isList == False): |
| 139 | fn = path |
| 140 | save_image_saliancy(features[None, ...].permute(1, 0, 2, 3).cpu(), fn, normalize=True) |
nothing calls this directly
no test coverage detected