MCPcopy Create free account
hub / github.com/UVA-Computer-Vision-Lab/FrameINO / vis_PCA

Function vis_PCA

preprocess/SpaTrackV2_code/utils/model_utils.py:422–444  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

420 ) # B C R1 R2 1 -> B R1 R2 C
421
422def 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 ))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected