0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

初めてのPytorch #変換

0
Posted at

テストデータを受け取る際に処理しやすい値に変換する処理

Lambdaを使用するためimportを追加
[0,0,0,0,0,0,0,0,0,0]を作成しyの値を1に変化させる
例:y=3なら[0,0,0,1,0,0,0,0,0,0]
これを行うことで誤差を計算しやすくしている

import torch
from torchvision import datasets
from torchvision.transforms import ToTensor, Lambda

ds = datasets.FashionMNIST(
    root="data",
    train=True,
    download=True,
    transform=ToTensor(),
    target_transform=Lambda(lambda y: torch.zeros(10, dtype=torch.float).scatter_(0, torch.tensor(y), value=1))
)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?