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)
| 84 | ### |
| 85 | |
| 86 | def plot_features(features, path='f', isList=True): |
| 87 | """ |
| 88 | print feature maps |
| 89 | :param features: (3, [batch, H, W]) or [3, batch, H, W] |
| 90 | :param path: save image path |
| 91 | :param isList: wether the features is an list |
| 92 | :return: |
| 93 | """ |
| 94 | kwargs = {'normalize' : True, } # 'scale_each' : True |
| 95 | |
| 96 | if isList: |
| 97 | dim = features[0].dim() |
| 98 | else: |
| 99 | dim = features.dim() |
| 100 | assert(dim==3 or dim==4) |
| 101 | |
| 102 | if dim==4 and isList: |
| 103 | print_feature_examples(features, path) |
| 104 | elif dim==4 and (isList==False): |
| 105 | fn = path |
| 106 | lvl, b, H, W = features.shape |
| 107 | for i in range(features.shape[0]): |
| 108 | fn = path + '{}.png'.format(i) |
| 109 | save_image_saliancy(features[i][None,...].permute(1,0,2,3).cpu(), fn, normalize=True) |
| 110 | |
| 111 | # # concat everything |
| 112 | # features = features.reshape([-1, H, W]) |
| 113 | # # save_image(features[None,...].permute(1,0,2,3).cpu(), fn, **kwargs) |
| 114 | # save_image_saliancy(features[None,...].permute(1,0,2,3).cpu(), fn, normalize=True) |
| 115 | |
| 116 | elif dim==3 and isList: # print all images in the list |
| 117 | for i in range(len(features)): |
| 118 | fn = path + '{}.png'.format(i) |
| 119 | # save_image(features[i][None,...].permute(1,0,2,3).cpu(), fn, **kwargs) |
| 120 | save_image_saliancy(features[i][None,...].permute(1,0,2,3).cpu(), fn, normalize=True) |
| 121 | elif dim==3 and (isList==False): |
| 122 | fn = path |
| 123 | save_image_saliancy(features[None,...].permute(1,0,2,3).cpu(), fn, normalize=True) |
| 124 | |
| 125 | def sample_homography_np( |
| 126 | shape, shift=0, perspective=True, scaling=True, rotation=True, translation=True, |
no test coverage detected