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

TypeError: 'Compose' object is not iterable #5

Open
chenhaoxing opened this issue Jul 26, 2021 · 2 comments
Open

TypeError: 'Compose' object is not iterable #5

chenhaoxing opened this issue Jul 26, 2021 · 2 comments

Comments

@chenhaoxing
Copy link

Traceback (most recent call last):
File "moby_linear.py", line 385, in
main(config)
File "moby_linear.py", line 174, in main
train_one_epoch(config, model, criterion, data_loader_train, optimizer, epoch, mixup_fn, lr_scheduler)
File "moby_linear.py", line 199, in train_one_epoch
for idx, (samples, targets) in enumerate(data_loader):
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 435, in next
data = self._next_data()
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
return self._process_data(data)
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
data.reraise()
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/_utils.py", line 428, in reraise
raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
data = fetcher.fetch(index)
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/haoxing/Transformer-SSL/data/custom_image_folder.py", line 24, in getitem
for t in self.transform:
TypeError: 'Compose' object is not iterable

@xianxianY
Copy link

Traceback (most recent call last):
File "moby_linear.py", line 385, in
main(config)
File "moby_linear.py", line 174, in main
train_one_epoch(config, model, criterion, data_loader_train, optimizer, epoch, mixup_fn, lr_scheduler)
File "moby_linear.py", line 199, in train_one_epoch
for idx, (samples, targets) in enumerate(data_loader):
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 435, in next
data = self._next_data()
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
return self._process_data(data)
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
data.reraise()
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/_utils.py", line 428, in reraise
raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
data = fetcher.fetch(index)
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/haoxing/.conda/envs/chx/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/haoxing/Transformer-SSL/data/custom_image_folder.py", line 24, in getitem
for t in self.transform:
TypeError: 'Compose' object is not iterable

maybe you can try return [transform] in build.py line142

@hucorz
Copy link

hucorz commented Apr 10, 2022

I change the code in "data/custom_image_folder.py" line 24-25

orignal code

if self.transform is not None:
            for t in self.transform:
                ret.append(t(image))
        else:
            ret.append(image)

changed code

if self.transform is not None:
    # for t in self.transform:
    ret.append(self.transform(image))
else:
    ret.append(image)

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

3 participants