torch.saveとstate_dictの違い
![Thumbnail of post image 187](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/samuel-yongbo-kwon-wrQsfMKwElI-unsplash.jpg?resize=150%2C150&ssl=1)
Pytorchで学習したモデルを保存する時は
torch.save(model.state_dict(), model_path)でモデルを保存することが推奨される.
state_dictがsaveで直接保存す ...
AttributeError: ‘_IncompatibleKeys’ object has no attribute ‘to’
![Thumbnail of post image 005](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/danielle-macinnes-IuLgi9PWETU-unsplash.jpg?resize=150%2C150&ssl=1)
Pytorchを使っている時に出たエラー.これがでたときには,モデルの読み込みの順番でエラーが発生していることが多い.少し順番を変えてあげればケロっとエラーが解消されることが多い.
よくあるエラーが,.load_state ...
VGG16 pre-trainedの中間層を用いたモデル構築例[pytorch]
![Thumbnail of post image 091](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/sambazon-qfIVXu7nxGU-unsplash.jpg?resize=150%2C150&ssl=1)
import osimport globimport randomimport numpy as npimport pandas as pdfrom sklearn.model_selection import train_test_spl ...
TensorDatasetで生画像をTensor化して読み込む[PyTorch]
![Thumbnail of post image 123](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/anna-sullivan-IUXR0sqs-mY-unsplash.jpg?resize=150%2C150&ssl=1)
from glob import globfrom PIL import Imageimport numpy as npimport torchimport torch.utils.data as data_utilsfrom torchv ...
Pytorch v0.4のコードをv0.3で動かす際には.dataに注意[Pytorch]
![Thumbnail of post image 192](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/taylor-heery-71sp4JBYO-U-unsplash-2.jpg?resize=150%2C150&ssl=1)
Pytorchのコードを見ているとミニバッチごとのlossやaccuracyを計算する際、.dataを用いて値を取り出されることが頻繁にある。
よくある例:
for i in range(0, 2 * POS_NEG ...PytorchがGPUを使っているかを確認する方法[Pytorch]
![Thumbnail of post image 147](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/debby-hudson-EjCS2TsPjh8-unsplash.jpg?resize=150%2C150&ssl=1)
import torchprint(torch.cuda.is_available())>>Truetorch.cuda.get_device_name(0)>>'GeForce GTX 1080 Ti'
Pytorchに関する基礎知識 ...