TypeError: Caught TypeError in DataLoader worker process 0

This is the following error I get:
[rank0]: Traceback (most recent call last):
[rank0]: File “/scistor/guest/aak580/projects/sclicom/tools/extract_features/train.py”, line 46, in
[rank0]: main()
[rank0]: File “/scistor/guest/aak580/projects/sclicom/tools/extract_features/train.py”, line 38, in main
[rank0]: cli.trainer.fit(
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer.py”, line 544, in fit
[rank0]: call._call_and_handle_interrupt(
[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
[rank0]: return trainer.strategy.launcher.launch(trainer_fn, *args, trainer=trainer, **kwargs)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/strategies/launchers/subprocess_script.py”, line 105, in launch
[rank0]: return function(*args, **kwargs)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer.py”, line 580, in _fit_impl
[rank0]: self._run(model, ckpt_path=ckpt_path)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer.py”, line 987, in _run
[rank0]: results = self._run_stage()
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer.py”, line 1033, in _run_stage
[rank0]: self.fit_loop.run()
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/fit_loop.py”, line 205, in run
[rank0]: self.advance()
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/fit_loop.py”, line 363, in advance
[rank0]: self.epoch_loop.run(self._data_fetcher)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/training_epoch_loop.py”, line 140, in run
[rank0]: self.advance(data_fetcher)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/training_epoch_loop.py”, line 212, in advance
[rank0]: batch, _, __ = next(data_fetcher)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/fetchers.py”, line 133, in next
[rank0]: batch = super().next()
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/loops/fetchers.py”, line 60, in next
[rank0]: batch = next(self.iterator)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/utilities/combined_loader.py”, line 341, in next
[rank0]: out = next(self._iterator)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightning/pytorch/utilities/combined_loader.py”, line 78, in next
[rank0]: out[i] = next(self.iterators[i])
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/dataloader.py”, line 631, in next
[rank0]: data = self._next_data()
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/dataloader.py”, line 1346, in _next_data
[rank0]: return self._process_data(data)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/dataloader.py”, line 1372, in _process_data
[rank0]: data.reraise()
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/_utils.py”, line 705, in reraise
[rank0]: raise exception
[rank0]: TypeError: Caught TypeError in DataLoader worker process 0.
[rank0]: Original Traceback (most recent call last):
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py”, line 308, in _worker_loop
[rank0]: data = fetcher.fetch(index) # type: ignore[possibly-undefined]
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py”, line 54, in fetch
[rank0]: return self.collate_fn(data)
[rank0]: File “/scistor/guest/aak580/.conda/envs/sclicom/lib/python3.10/site-packages/lightly/data/multi_view_collate.py”, line 62, in call
[rank0]: views = [ for _ in range(len(batch[0][0]))]
[rank0]: TypeError: object of type ‘Image’ has no len()

I work with bmp images transformed to tiff images and enhanced with exposure.equalize_adapthist.

The paths to the images are correct, they are csv files containing the image name, diagnosis and location.

Please if someone can help me, I would apreciate it. If needed some code please let me know.

I’m not familiar with the lightly package but it seems batch[0][0] should be an object providing a len method while the passed Image fails, so check which inputs are supported and maybe transform the image to a tensor if needed.