如何使用PyTorch的Feature Extractor輸出進行t-SNE視覺化?

conda install tsnecuda cuda100 -c cannylab
  1. 程式載入model後,使用pdb進行trace
  2. 觀察model的架構(在breakpoint輸入model,會顯示模型的架構)
  3. 找出model當中,分類器之前的的卷積層(倒數第一個卷積層)
  4. 如果是ResNet的話,有avgpool,直接接到register_forward_hook即可;如果是MobileNetv2的話,需要把output再次經過avg_pool2d(詳情見下方程式碼),最後才能拿來進行t-SNE視覺化。
  5. 至於我為何會選adaptive_avg_pool2d,是因為根據torchvision.models.mobilenetv2,這邊在_forward_impl時的pooling層就是選用adaptive_avg_pool2d

--

--

--

Machine Learning | Deep Learning | https://linktr.ee/yanwei

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yanwei Liu

Yanwei Liu

Machine Learning | Deep Learning | https://linktr.ee/yanwei

More from Medium

TensorFlow Image Processing

XMAS Project — Part 3: Image Classification from an Engineer’s Perspective

Convolutional neural networks

Penguins from Head to Toe — How Penguins Can Help You Master Image Classification Process