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 3 years have passed since last update.

pytorchのtorch.utils.data.DataLoaderは無限イテレータに対応していない

Posted at

表題の通り、pytorchのtorch.utils.data.DataLoaderは無限イテレータに対応していない。以下でそれを確かめる。

import torch.utils.data


def data_generator():
    while True:
        yield torch.Tensor([1,2,3])
        
dataloader = torch.utils.data.DataLoader(my_data, batch_size=2)

for i, z in enumerate(dataloader):
    print(z)
    if i > 10:
        break

上のコードを実行すると次のようになる。

TypeError: object of type 'generator' has no len()

len()を持っていないとダメみたいです。動きませんね。

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?