visualize the PCA of the feature maps args: fmaps: feature maps 1 C H W save_dir: the directory to save the PCA visualization
(fmaps, save_dir)
| 420 | ) # B C R1 R2 1 -> B R1 R2 C |
| 421 | |
| 422 | def vis_PCA(fmaps, save_dir): |
| 423 | """ |
| 424 | visualize the PCA of the feature maps |
| 425 | args: |
| 426 | fmaps: feature maps 1 C H W |
| 427 | save_dir: the directory to save the PCA visualization |
| 428 | """ |
| 429 | |
| 430 | pca = PCA(n_components=3) |
| 431 | fmap_vis = fmaps[0,...] |
| 432 | fmap_vnorm = ( |
| 433 | (fmap_vis-fmap_vis.min())/ |
| 434 | (fmap_vis.max()-fmap_vis.min())) |
| 435 | H_vis, W_vis = fmap_vis.shape[1:] |
| 436 | fmap_vnorm = fmap_vnorm.reshape(fmap_vnorm.shape[0], |
| 437 | -1).permute(1,0) |
| 438 | fmap_pca = pca.fit_transform(fmap_vnorm.detach().cpu().numpy()) |
| 439 | pca = fmap_pca.reshape(H_vis,W_vis,3) |
| 440 | plt.imsave(save_dir, |
| 441 | ( |
| 442 | (pca-pca.min())/ |
| 443 | (pca.max()-pca.min()) |
| 444 | )) |
nothing calls this directly
no outgoing calls
no test coverage detected