ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.09k stars 16.18k forks source link

object localization ot correct #8229

Closed AliNaqvi110 closed 2 years ago

AliNaqvi110 commented 2 years ago

Search before asking

Question

Hi hope you are well. I have trained Yolov5 on custom data. Although model is trained without any issue. The detection box i get for training and val data is incorrect. I could not find whats wrong with the data.

train_batch1

how can i correct these wrong detection box any help will be appreciated. Many thanks

Additional

No response

glenn-jocher commented 2 years ago

@AliNaqvi110 👋 Hello! Thanks for asking about YOLOv5 🚀 dataset formatting. To train correctly your data must be in YOLOv5 format. Your labels are incorrect. Please see our Train Custom Data tutorial for full documentation on dataset setup and all steps required to start training your first model. A few excerpts from the tutorial:

1.1 Create dataset.yaml

COCO128 is an example small tutorial dataset composed of the first 128 images in COCO train2017. These same 128 images are used for both training and validation to verify our training pipeline is capable of overfitting. data/coco128.yaml, shown below, is the dataset config file that defines 1) the dataset root directory path and relative paths to train / val / test image directories (or *.txt files with image paths), 2) the number of classes nc and 3) a list of class names:

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco128  # dataset root dir
train: images/train2017  # train images (relative to 'path') 128 images
val: images/train2017  # val images (relative to 'path') 128 images
test:  # test images (optional)

# Classes
nc: 80  # number of classes
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
         'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
         'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
         'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
         'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
         'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
         'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
         'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
         'hair drier', 'toothbrush' ]  # class names

1.2 Create Labels

After using a tool like Roboflow Annotate to label your images, export your labels to YOLO format, with one *.txt file per image (if no objects in image, no *.txt file is required). The *.txt file specifications are:

Image Labels

The label file corresponding to the above image contains 2 persons (class 0) and a tie (class 27):

1.3 Organize Directories

Organize your train and val images and labels according to the example below. YOLOv5 assumes /coco128 is inside a /datasets directory next to the /yolov5 directory. YOLOv5 locates labels automatically for each image by replacing the last instance of /images/ in each image path with /labels/. For example:

../datasets/coco128/images/im0.jpg  # image
../datasets/coco128/labels/im0.txt  # label

Good luck 🍀 and let us know if you have any other questions!

bryanbocao commented 2 years ago

@AliNaqvi110 As you mentioned

The detection box i get for training and val data is incorrect

You can do some sanity check on the labels like drawing bbox on images and visualize them before training. Something worth checking in the dataset: (1) Does (x, y) mean (rows, cols) or (cols, rows)? (2) Does (x, y) refer to the top-left corner of a bounding box or the center? (3) Does (w, h) refer to the width, height of the bounding box or half? (4) Is (w, h) in absolute location or relative to the image?

jsmlau commented 2 years ago

I have the same issue. I used Roboflow annotator to draw bounding boxes. I double checked all the bboxs that I drew are correct, but the issue exists after "Generate New Version". Some bbox position seemed flipped or rotated. I would like to know hoe I can fix this issue.

bryanbocao commented 2 years ago

@AliNaqvi110 As you mentioned

The detection box i get for training and val data is incorrect

You can do some sanity check on the labels like drawing bbox on images and visualize them before training. Something worth checking in the dataset: (1) Does (x, y) mean (rows, cols) or (cols, rows)? (2) Does (x, y) refer to the top-left corner of a bounding box or the center? (3) Does (w, h) refer to the width, height of the bounding box or half? (4) Is (w, h) in absolute location or relative to the image?

After experiments these day I think I have answers to these questions: (1) Does (x, y) mean (rows, cols) or (cols, rows)? Ans: (x, y) -> (cols, rows) normalized by (image_width, image_height). (2) Does (x, y) refer to the top-left corner of a bounding box or the center? Ans: Center. (3) Does (w, h) refer to the width, height of the bounding box or half? Ans: Width and height normalized by image_width and image_height. (4) Is (w, h) in absolute location or relative to the image? Ans: normalized by image_width and image_height.

@jsmlau by "flipped or rotated" probably (x, y) or (w, h) are flipped and you may manually visualize the bounding boxes for sanity check.

github-actions[bot] commented 2 years ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!