roboflow / notebooks

Examples and tutorials on using SOTA computer vision models and techniques. Learn everything from old-school ResNet, through YOLO and object-detection transformers like DETR, to the latest models like Grounding DINO and SAM.
https://roboflow.com/models
5.58k stars 880 forks source link

Yolov8 Roboflow Notebook Error - Albumentations Package #311

Closed Amir-Voloshin closed 2 months ago

Amir-Voloshin commented 2 months ago

Search before asking

Notebook name

Notebook: YOLOv8 Object Detection

Bug

When beginning training on the first epoch, this unhashable type error arises: Traceback (most recent call last): File "/usr/local/bin/yolo", line 8, in <module> sys.exit(entrypoint()) File "/usr/local/lib/python3.10/dist-packages/ultralytics/cfg/__init__.py", line 445, in entrypoint getattr(model, mode)(**overrides) # default args from model File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/model.py", line 341, in train self.trainer.train() File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/trainer.py", line 191, in train self._do_train(world_size) File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/trainer.py", line 325, 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 42, 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 <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.10/dist-packages/ultralytics/data/base.py", line 242, in __getitem__ return self.transforms(self.get_image_and_label(index)) File "/usr/local/lib/python3.10/dist-packages/ultralytics/data/augment.py", line 70, in __call__ data = t(data) File "/usr/local/lib/python3.10/dist-packages/ultralytics/data/augment.py", line 824, 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'

Environment

Minimal Reproducible Example

%cd {HOME}

!yolo task=detect mode=train model=yolov8s.pt data={dataset.location}/data.yaml epochs=300 imgsz=640 plots=True

Additional

Ran the notebook tutorial, importing my own dataset from roboflow (tried several datasets), under "Custom Training" this error occurs each time.

Last successful training used torch 2.4.0, currently torch 2.4.1 is being loaded.

Are you willing to submit a PR?

LinasKo commented 2 months ago

This is an issue with ultralytics or albumentations.

Could you please try the following? pip install albumentations==1.4

(based on a similar issue)

Amir-Voloshin commented 2 months ago

Hi @LinasKo , pip install albumentations==1.4 did not work. Any other suggestions?

LinasKo commented 2 months ago

I wasn't sure it would, but I tried it and it did help get the training going: Colab. Note that I added the !pip install albumentations==1.4 right before the training starts, ensuring it is the final dependency to be installed.

Amir-Voloshin commented 2 months ago

@LinasKo adding it right before training works! Thank you.

LinasKo commented 2 months ago

Glad to help! 😉