THU-MIG / yolov10

YOLOv10: Real-Time End-to-End Object Detection [NeurIPS 2024]
https://arxiv.org/abs/2405.14458
GNU Affero General Public License v3.0
9.9k stars 978 forks source link

Google Colab with TypeError: unhashable type: 'numpy.ndarray' #440

Closed subwheel closed 1 month ago

subwheel commented 1 month ago

When I was training my own custom dataset, I used Google Colab. At the first two attempt, my code runs successfully. My code is: !yolo task=detect mode=train epochs=240 batch=12 plots=True model=weights/yolov10x.pt data=data.yaml device=0 But when I tried to execute the code the third time, while I only modified my epoch, some error code was reported:

Epoch GPU_mem box_om cls_om dfl_om box_oo cls_oo dfl_oo Instances Size 0% 0/485 [00:00<?, ?it/s] Traceback (most recent call last): File "/usr/local/bin/yolo", line 8, in sys.exit(entrypoint()) File "/usr/local/lib/python3.10/dist-packages/ultralytics/cfg/init.py", line 594, in entrypoint getattr(model, mode)(**overrides) # default args from model File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/model.py", line 657, in train self.trainer.train() File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/trainer.py", line 213, in train self._do_train(world_size) File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/trainer.py", line 363, in _do_train for i, batch in pbar: File "/usr/local/lib/python3.10/dist-packages/tqdm/std.py", line 1181, in iter for obj in iterable: File "/usr/local/lib/python3.10/dist-packages/ultralytics/data/build.py", line 49, in iter yield next(self.iterator) File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 630, in next data = self._next_data() File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 1344, in _next_data return self._process_data(data) File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 1370, in _process_data data.reraise() File "/usr/local/lib/python3.10/dist-packages/torch/_utils.py", line 706, in reraise raise exception TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/worker.py", line 309, in _worker_loop data = fetcher.fetch(index) # type: ignore[possibly-undefined] File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 52, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.10/dist-packages/ultralytics/data/base.py", line 253, in getitem return self.transforms(self.get_image_and_label(index)) File "/usr/local/lib/python3.10/dist-packages/ultralytics/data/augment.py", line 74, in call data = t(data) File "/usr/local/lib/python3.10/dist-packages/ultralytics/data/augment.py", line 866, in call new = self.transform(image=im, bboxes=bboxes, class_labels=cls) # transformed File "/usr/local/lib/python3.10/dist-packages/albumentations/core/composition.py", line 334, in call self.preprocess(data) File "/usr/local/lib/python3.10/dist-packages/albumentations/core/composition.py", line 368, in preprocess p.preprocess(data) File "/usr/local/lib/python3.10/dist-packages/albumentations/core/utils.py", line 125, in preprocess data = self.add_label_fields_to_data(data) File "/usr/local/lib/python3.10/dist-packages/albumentations/core/utils.py", line 185, in add_label_fields_to_data encoded_labels = encoder.fit_transform(data[label_field]) File "/usr/local/lib/python3.10/dist-packages/albumentations/core/utils.py", line 60, in fit_transform self.fit(y) File "/usr/local/lib/python3.10/dist-packages/albumentations/core/utils.py", line 48, in fit unique_labels = sorted(set(y)) TypeError: unhashable type: 'numpy.ndarray'

I barely change anything compared to the previous attempts, why those attempts were able to execute but not this time? How should I fix this problem?

kunsungwoo commented 1 month ago

I also have the same problem.

hikki-e commented 1 month ago

It seems like it is related to library compatibility, as everything works fine if you use the latest version of all libraries, but with older version(as in my case, with ultralytics==8.0.114) you get this error

galang006 commented 1 month ago

!pip install albumentations==1.4

Akash1362000 commented 1 month ago

Thanks @galang006. Your solution works like a charm!

sriramsowmithri9807 commented 1 month ago

CLEAR EXPLAINATION: @subwheel The error you're encountering during your YOLO training, specifically the "TypeError: unhashable type: 'numpy.ndarray'," suggests a problem with how your dataset is being processed, likely related to the format of your labels or bounding boxes. To resolve this, first ensure that your dataset is in the correct format expected by YOLO, where each image has a corresponding label file with bounding box coordinates and class labels formatted correctly. If you've implemented any data augmentation techniques, verify that they are compatible with the input data types, as mismatches can lead to errors. Consider reverting any recent changes to your training configuration, including modifications to epochs or other hyperparameters, especially since the code worked successfully in previous attempts. Additionally, check for library version compatibility and clear any cached datasets or models that might be causing conflicts. If you're still having trouble, running your code on the CPU instead of the GPU might provide more informative error messages. Lastly, ensure that your label files contain lines formatted as "class_id center_x center_y width height," with normalized values between 0 and 1 for proper processing. By addressing these aspects, you should be able to resolve the issue and continue training effectively.

subwheel commented 1 month ago

@sriramsowmithri9807 @galang006 Thanks for the help! My code can now run successfully!

IlhamPratama01 commented 1 month ago

!pip install albumentations==1.4

Thanks, it actually worked!

ateffal commented 1 month ago

should it be installed before ultralytics ?

ateffal commented 1 month ago

Thanks guys ! it worked for me too - installed albumentations==1.4 before ultralytics ! But this this is problematic, we don't really know which version of ultralytics works with which version of a albumentations. I'm saying this because the notebook worked fine a couple of days ago without !pip install albumentations==1.4 !

thasan3003 commented 1 month ago

Thanks to @galang006

PrasadCodesML commented 1 month ago

Thanks so much @galang006

SecretBlackStar commented 1 month ago

Thanks so much @galang006. You are a lifesaver.

armanivers commented 1 month ago

I used to work on ultralytics 8.2.50 and albumentations 1.4.11, then I updated both, my notebook stopped working like it did for all of you. Then I downgraded both ultralytics and albumentations with pip install -U ultralytics==8.2.50 albumentations==1.4.11 but when I run the scripts, yolov8 doesn't detect albumentations (as if it isn't installed), when I try albumentations==1.4 it does get detected again, but I'd prefer having 1.4.11 which includes some changes. Any ideas?

AI-MHT commented 1 month ago

!pip install albumentations==1.4

its work chef thanks alot

tushark01 commented 1 month ago

!pip install albumentations==1.4

Thanks man !

Ahlem-mag commented 1 month ago

Thanks to @galang006

jonathanEdmundW commented 2 weeks ago

!pip install albumentations==1.4

Thank you!