TypeError: Caught TypeError in DataLoader worker process 0

username: aimen_ea
cooked: <p>This is the following error I get:<br>
[rank0]: Traceback (most recent call last):<br>
[rank0]:   File “/scistor/guest/aak580/projects/sclicom/tools/extract_features/train.py”, line 46, in <br>
[rank0]:     main()<br>
[rank0]:   File “/scistor/guest/aak580/projects/sclicom/tools/extract_features/train.py”, line 38, in main<br>
[rank0]:     cli.trainer.fit(<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer.py”, line 544, in fit<br>
[rank0]:     call._call_and_handle_interrupt(<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/trainer/call.py”, line 43, in _call_and_handle_interrupt<br>
[rank0]:     return trainer.strategy.launcher.launch(trainer_fn, *args, trainer=trainer, **kwargs)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/strategies/launchers/subprocess_script.py”, line 105, in launch<br>
[rank0]:     return function(*args, **kwargs)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer.py”, line 580, in _fit_impl<br>
[rank0]:     self._run(model, ckpt_path=ckpt_path)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer.py”, line 987, in _run<br>
[rank0]:     results = self._run_stage()<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer.py”, line 1033, in _run_stage<br>
[rank0]:     self.fit_loop.run()<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/fit_loop.py”, line 205, in run<br>
[rank0]:     self.advance()<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/fit_loop.py”, line 363, in advance<br>
[rank0]:     self.epoch_loop.run(self._data_fetcher)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/training_epoch_loop.py”, line 140, in run<br>
[rank0]:     self.advance(data_fetcher)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/training_epoch_loop.py”, line 212, in advance<br>
[rank0]:     batch, _, __ = next(data_fetcher)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/fetchers.py”, line 133, in <strong>next</strong><br>
[rank0]:     batch = super().<strong>next</strong>()<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/fetchers.py”, line 60, in <strong>next</strong><br>
[rank0]:     batch = next(self.iterator)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/utilities/combined_loader.py”, line 341, in <strong>next</strong><br>
[rank0]:     out = next(self._iterator)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/utilities/combined_loader.py”, line 78, in <strong>next</strong><br>
[rank0]:     out[i] = next(self.iterators[i])<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/dataloader.py”, line 631, in <strong>next</strong><br>
[rank0]:     data = self._next_data()<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/dataloader.py”, line 1346, in _next_data<br>
[rank0]:     return self._process_data(data)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/dataloader.py”, line 1372, in _process_data<br>
[rank0]:     data.reraise()<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/_utils.py”, line 705, in reraise<br>
[rank0]:     raise exception<br>
[rank0]: TypeError: Caught TypeError in DataLoader worker process 0.<br>
[rank0]: Original Traceback (most recent call last):<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py”, line 308, in _worker_loop<br>
[rank0]:     data = fetcher.fetch(index)  # type: ignore[possibly-undefined]<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py”, line 54, in fetch<br>
[rank0]:     return self.collate_fn(data)<br>
[rank0]:   File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightly/data/multi_view_collate.py”, line 62, in <strong>call</strong><br>
[rank0]:     views = [<span class="chcklst-box fa fa-square-o fa-fw"></span> for _ in range(len(batch[0][0]))]<br>
[rank0]: TypeError: object of type ‘Image’ has no len()</p>
<p>I work with bmp images transformed to tiff images and enhanced with exposure.equalize_adapthist.</p>
<p>The paths to the images are correct, they are csv files containing the image name, diagnosis and location.</p>
<p>Please if someone can help me, I would apreciate it. If needed some code please let me know.</p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="aimen_ea" data-post="1" data-topic="202721">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/aimen_ea/48/63308_2.png" class="avatar"> aimen_ea:</div>
<blockquote>
<p>[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightly/data/multi_view_collate.py”, line 62, in <strong>call</strong><br>
[rank0]: views = [ for _ in range(len(batch[0][0]))]<br>
[rank0]: TypeError: object of type ‘Image’ has no len()</p>
</blockquote>
</aside>
<p>I’m not familiar with the <code>lightly</code> package but it seems <code>batch[0][0]</code> should be an object providing a <code>len</code> method while the passed <code>Image</code> fails, so check which inputs are supported and maybe transform the image to a tensor if needed.</p>