Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change bounding box label index to text #3578

Closed
hjsg1010 opened this issue Jun 10, 2021 · 7 comments · Fixed by #3882
Closed

change bounding box label index to text #3578

hjsg1010 opened this issue Jun 10, 2021 · 7 comments · Fixed by #3882
Labels
question Further information is requested

Comments

@hjsg1010
Copy link

❔Question

Hi, thanks for your great research and sharing codes.

I am applying YOLOv5 to my custom dataset.

And during learning, the mosaic section on wandb.ai shows the figure below.

image

However, I want to change the bbox label index to text label, such as '118' changes to 'cheesecake'.

What should I fix in code? or do I have to change my annotation?

Currently the data folder are consists of
data_folder/
┣ images/
┃ ┣ train/
┃ ┣ valid/
┣ labels/
┃ ┣ train/
┃ ┣ valid/
┣ data_config.yaml

Additional context

@hjsg1010 hjsg1010 added the question Further information is requested label Jun 10, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jun 10, 2021

👋 Hello @hjsg1010, thank you for your interest in 🚀 YOLOv5! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

glenn-jocher commented Jun 10, 2021

@hjsg1010 @kalenmike yes, your results are correct. The train mosaics only display the class index rather than the class name. You can see this in the Train Custom Data tutorial. We did this because the mosaics can get quite busy for high density datasets. The test dataset labels show the full name though, i.e. test_batch0_labels.jpg, so you may want to look at those instead.
https://docs.ultralytics.com/yolov5/tutorials/train_custom_data#local-logging

We're also developing dataset introspection tools as part of the new Ultralytics HUB. This should be ready sometime later on in summer 2021 at https://ultralytics.com

duo3-1

@hjsg1010
Copy link
Author

hjsg1010 commented Jun 10, 2021

@hjsg1010 @kalenmike yes, your results are correct. The train mosaics only display the class index rather than the class name. You can see this in the Train Custom Data tutorial. We did this because the mosaics can get quite busy for high density datasets. The test dataset labels show the full name though, i.e. test_batch0_labels.jpg, so you may want to look at those instead.
https://docs.ultralytics.com/yolov5/tutorials/train_custom_data#local-logging

We're also developing dataset introspection tools as part of the new Ultralytics HUB. This should be ready sometime later on in summer 2021 at https://ultralytics.com

duo3-1

oh, Thx for quick and kind reply.
Again, thx for sharing your codes!!

@hjsg1010
Copy link
Author

@glenn-jocher
Hi, can I ask one more question?
I know that YOLO already does data augmentation.
However, I want to do custom data augmentation using Albumentations.
Then, where should I put augmentation pipeline code?
.utils/dataset.py ? or train.py?

sorry for my poor English skills, and low knowledge on object detection code..

@glenn-jocher
Copy link
Member

glenn-jocher commented Jun 10, 2021

@hjsg1010 you can inline any Albumentations augmentations you want in the dataloader here:

yolov5/utils/datasets.py

Lines 499 to 545 in 095197b

def __getitem__(self, index):
index = self.indices[index] # linear, shuffled, or image_weights
hyp = self.hyp
mosaic = self.mosaic and random.random() < hyp['mosaic']
if mosaic:
# Load mosaic
img, labels = load_mosaic(self, index)
shapes = None
# MixUp https://arxiv.org/pdf/1710.09412.pdf
if random.random() < hyp['mixup']:
img2, labels2 = load_mosaic(self, random.randint(0, self.n - 1))
r = np.random.beta(32.0, 32.0) # mixup ratio, alpha=beta=32.0
img = (img * r + img2 * (1 - r)).astype(np.uint8)
labels = np.concatenate((labels, labels2), 0)
else:
# Load image
img, (h0, w0), (h, w) = load_image(self, index)
# Letterbox
shape = self.batch_shapes[self.batch[index]] if self.rect else self.img_size # final letterboxed shape
img, ratio, pad = letterbox(img, shape, auto=False, scaleup=self.augment)
shapes = (h0, w0), ((h / h0, w / w0), pad) # for COCO mAP rescaling
labels = self.labels[index].copy()
if labels.size: # normalized xywh to pixel xyxy format
labels[:, 1:] = xywhn2xyxy(labels[:, 1:], ratio[0] * w, ratio[1] * h, padw=pad[0], padh=pad[1])
if self.augment:
# Augment imagespace
if not mosaic:
img, labels = random_perspective(img, labels,
degrees=hyp['degrees'],
translate=hyp['translate'],
scale=hyp['scale'],
shear=hyp['shear'],
perspective=hyp['perspective'])
# Augment colorspace
augment_hsv(img, hgain=hyp['hsv_h'], sgain=hyp['hsv_s'], vgain=hyp['hsv_v'])
# Apply cutouts
# if random.random() < 0.9:
# labels = cutout(img, labels)

@hjsg1010
Copy link
Author

@hjsg1010 you can inline any Albumentations augmentations you want in the dataloader here:

yolov5/utils/datasets.py

Lines 499 to 545 in 095197b

def __getitem__(self, index):
index = self.indices[index] # linear, shuffled, or image_weights
hyp = self.hyp
mosaic = self.mosaic and random.random() < hyp['mosaic']
if mosaic:
# Load mosaic
img, labels = load_mosaic(self, index)
shapes = None
# MixUp https://arxiv.org/pdf/1710.09412.pdf
if random.random() < hyp['mixup']:
img2, labels2 = load_mosaic(self, random.randint(0, self.n - 1))
r = np.random.beta(32.0, 32.0) # mixup ratio, alpha=beta=32.0
img = (img * r + img2 * (1 - r)).astype(np.uint8)
labels = np.concatenate((labels, labels2), 0)
else:
# Load image
img, (h0, w0), (h, w) = load_image(self, index)
# Letterbox
shape = self.batch_shapes[self.batch[index]] if self.rect else self.img_size # final letterboxed shape
img, ratio, pad = letterbox(img, shape, auto=False, scaleup=self.augment)
shapes = (h0, w0), ((h / h0, w / w0), pad) # for COCO mAP rescaling
labels = self.labels[index].copy()
if labels.size: # normalized xywh to pixel xyxy format
labels[:, 1:] = xywhn2xyxy(labels[:, 1:], ratio[0] * w, ratio[1] * h, padw=pad[0], padh=pad[1])
if self.augment:
# Augment imagespace
if not mosaic:
img, labels = random_perspective(img, labels,
degrees=hyp['degrees'],
translate=hyp['translate'],
scale=hyp['scale'],
shear=hyp['shear'],
perspective=hyp['perspective'])
# Augment colorspace
augment_hsv(img, hgain=hyp['hsv_h'], sgain=hyp['hsv_s'], vgain=hyp['hsv_v'])
# Apply cutouts
# if random.random() < 0.9:
# labels = cutout(img, labels)

Thx for reply. Thankyou.

@glenn-jocher glenn-jocher linked a pull request Jul 4, 2021 that will close this issue
@glenn-jocher
Copy link
Member

@hjsg1010 see PR #3882 for a proposed automatic Albumentations integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants