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.43k stars 855 forks source link

train-yolos error #22

Closed robmarkcole closed 1 year ago

robmarkcole commented 1 year ago

Search before asking

Notebook name

train-yolos-huggingface-object-detection-on-custom-data.ipynb

Bug

I am using my own dataset from roboflow, exported in coco format.

At:

#Setup dataloader for training loop

from torch.utils.data import DataLoader

def collate_fn(batch):
  pixel_values = [item[0] for item in batch]
  encoding = feature_extractor.pad(pixel_values, return_tensors="pt")
  labels = [item[1] for item in batch]
  batch = {}
  batch['pixel_values'] = encoding['pixel_values']
  batch['labels'] = labels
  return batch

train_dataloader = DataLoader(train_dataset, collate_fn=collate_fn, batch_size=1, shuffle=True)
val_dataloader = DataLoader(val_dataset, collate_fn=collate_fn, batch_size=1)
batch = next(iter(train_dataloader))

I get error:

The `max_size` parameter is deprecated and will be removed in v4.26. Please specify in `size['longest_edge'] instead`.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-7-bd1a63ffeba0>](https://localhost:8080/#) in <module>
     14 train_dataloader = DataLoader(train_dataset, collate_fn=collate_fn, batch_size=1, shuffle=True)
     15 val_dataloader = DataLoader(val_dataset, collate_fn=collate_fn, batch_size=1)
---> 16 batch = next(iter(train_dataloader))

7 frames
[/usr/local/lib/python3.8/dist-packages/transformers/models/yolos/image_processing_yolos.py](https://localhost:8080/#) in resize(self, image, size, resample, data_format, **kwargs)
    805             size = (size["height"], size["width"])
    806         else:
--> 807             raise ValueError(
    808                 "Size must contain 'height' and 'width' keys or 'shortest_edge' and 'longest_edge' keys. Got"
    809                 f" {size.keys()}."

ValueError: Size must contain 'height' and 'width' keys or 'shortest_edge' and 'longest_edge' keys. Got dict_keys(['shortest_edge']).

Environment

Colab

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

SkalskiP commented 1 year ago

Hi, @robmarkcole 👋🏻! Thank you very much for your interest in Roboflow Notebooks! Please have a little patience. I'm taking a look at your problem, but it may take some time to figure out what's happening. I'll keep you posted.

SkalskiP commented 1 year ago

Hello again @robmarkcole 👋🏻! I confirm that the train-yolos-huggingface-object-detection-on-custom-data.ipynb notebook does not work even with our own dataset right now. Judging by logs coming from transformers and pytorch-lightning most likely because of some pip package update. We will work on fixing that issue with the rest of the team.

SkalskiP commented 1 year ago

I just released a fix for train-yolos-huggingface-object-detection-on-custom-data.ipynb. I tried it on Google Colab and it works for me. Please take a look, and let me know if you stil experience issues you described.

robmarkcole commented 1 year ago

OK run the new notebook and seems OK. Just noted the change to accelerator='gpu', devices=1

robmarkcole commented 1 year ago

@SkalskiP I just noticed batch_size=1 which is an odd choice

SkalskiP commented 1 year ago

I'm not sure why @Jacobsolawetz decided to use batch_size=1. Maybe problems with GPU memory overflow. Glad to hear that everything works.

i-m-karanagarwal commented 1 year ago

@SkalskiP I tried to run the notebook with my own dataset but it showed the same error. Could you please check what's causing it?

SkalskiP commented 1 year ago

@i-m-karanagarwal just to be sure, could you send me a link to Google Colab that you are using?

i-m-karanagarwal commented 1 year ago

@SkalskiP Yes here it is https://colab.research.google.com/drive/1Xf6NmlHIs4YiemhDqEBA81eBossgNvWl#scrollTo=0_YBNFmWivR0

SkalskiP commented 1 year ago

@i-m-karanagarwal, could you grant me access? I just requested :)

SkalskiP commented 1 year ago

Okay, I know what's going on! :) This is an old version of the notebook, before the fix. Please use this version: https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolos-huggingface-object-detection-on-custom-data.ipynb

@i-m-karanagarwal, could you please let me know where did you found the link to that version? We need to update that link so that others wouldn't struggle with the same errors :)

i-m-karanagarwal commented 1 year ago

Okay okay @SkalskiP I found the old version on the documentation site of Roboflow Under YoloS model.

SkalskiP commented 1 year ago

Thank you very much 🙏🏻 @i-m-karanagarwal! I'll make sure that this time the link gets updated :)