Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1-3転移学習のエラーについて #213

Open
koukinano opened this issue Jan 4, 2023 · 0 comments
Open

1-3転移学習のエラーについて #213

koukinano opened this issue Jan 4, 2023 · 0 comments

Comments

@koukinano
Copy link

小川様

お世話になります。
突然のメッセージ失礼します。この書籍を拝読し勉強させていただいております初学者です。
書籍に記載されている転移学習のコードを利用し、グレースケールの画像をカラー画像に変換し、
学習させてみようとしたところ以下のようなエラーが出力されました。
画像をグレースケールからカラー画像に変換するときにnumpyに変換したことが原因?なのかなと思っているのですが、
なぜnumpyに変換することでエラーが出力されるか理解できなかったので質問させていただきました。
お手数ですが、解答いただけると幸いです。

TypeError Traceback (most recent call last)
Cell In[33], line 3
1 # 学習・検証を実行する
2 num_epochs=2
----> 3 train_model(net, dataloaders_dict, criterion, optimizer, num_epochs=num_epochs)

Cell In[32], line 27, in train_model(net, dataloaders_dict, criterion, optimizer, num_epochs)
23 continue
25 # データローダーからミニバッチを取り出すループ
26 #for inputs, labels in tqdm(dataloaders_dict[phase]):
---> 27 for inputs, labels in dataloaders_dict[phase]:
28
29 # optimizerを初期化
30 optimizer.zero_grad()
32 # 順伝搬(forward)計算

File ~/pytorch/lib/python3.8/site-packages/torch/utils/data/dataloader.py:628, in _BaseDataLoaderIter.next(self)
625 if self._sampler_iter is None:
626 # TODO(pytorch/pytorch#76750)
627 self._reset() # type: ignore[call-arg]
--> 628 data = self._next_data()
629 self._num_yielded += 1
630 if self._dataset_kind == _DatasetKind.Iterable and
631 self._IterableDataset_len_called is not None and
...
31 width, height = img.size
32 return [channels, height, width]
---> 33 raise TypeError(f"Unexpected type {type(img)}")

TypeError: Unexpected type <class 'numpy.ndarray'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant