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?

More than 1 year has passed since last update.

Pytorchで画像を使う~縦横チャンネルってどうするんだっけ~

Posted at

はじめに

pytorchでちゃんと画像を使おうとしたときに、チャンネル数と縦横ってどうやって返還すんだっけ?という初歩の初歩のところで躓いてしまったので残します。

状況

OpenCVで画像を読み込んで、下記のコードで変換しようとしていました。

transform_train = A.Compose([
    A.Resize(image_size, image_size),
    A.Normalize()
])

このコードではエラーが出ます。
[24, 3, 3, 3]にしたいのですが、なんかうまくなっていません。

RuntimeError: Given groups=1, weight of size [24, 3, 3, 3], expected input[2, 24, 25, 5] to have 3 channels, but got 256 channels instead

解決策

なんてことはないですが、ToTensorV2を入れるだけで解決しました。
処理がどうなっているか詳しくは調べていませんが、それだけです。

transform_train = A.Compose([
    A.Resize(image_size, image_size),
    A.Normalize(),
    ToTensorV2()
])

終わりに

そもそもpytorchを使っているのにtensor型への変換をするコードを書いていなかったのでそこからも気づけたのにかなり時間をかけてしまいました。
どこかで 「15分探して解決しなかったら記事をかけ」 と見た記憶があるので、非常に恥ずかしいミスですが記事にします。

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?