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

How to visualize input Dataloader after Augmentation? #779

Closed
chokyungjin opened this issue Aug 18, 2020 · 14 comments · Fixed by #3882
Closed

How to visualize input Dataloader after Augmentation? #779

chokyungjin opened this issue Aug 18, 2020 · 14 comments · Fixed by #3882
Labels
question Further information is requested Stale Stale and schedule for closing soon

Comments

@chokyungjin
Copy link

Hi! I have a question your Dataloader.
Your yolov5 is soo difficult to me to analyze..
How to visualize input Dataloader after Augmentation?
Before I training, I wonder how images come out in the dataloader.

Thanks!

@chokyungjin chokyungjin added the question Further information is requested label Aug 18, 2020
@Ownmarc
Copy link
Contributor

Ownmarc commented Aug 18, 2020

Trust me, Glenn’s code is really easy to read and understand compared to many repo in ML.

You can check the images created in the folder ‘’runs/exp0/‘’ they will show you 3 first batches when starting a training. Else you could simply create a dataloader object in a notebook or something using the repo’s code and load image one after an other and view them however you want by writing to disk or showing them with pyplot

@DacDinh147
Copy link

DacDinh147 commented Aug 19, 2020

You have to look in the LoadImagesAndLabels(Dataset) class. This class return a tuple (torch.from_numpy(img), labels_out, self.img_files[index], shapes).

Here torch.from_numpy(img) is a tensor with shape [batch size, channels, w, h] and labels_out is a list of item. Each item of labels_out represents a bounding box annotation for each image and is a list of bounding box (x_center, y_center, w, h) corresponding to the object in the specific image. Because the bounding box coordinates (x_center, y_center, w, h) was normalized, so you have to multiply it with the width and height of the image to visualize it xc, yc, w, h = xc*w_img, yc*h_img, w*w_img, h*h_img

Visualization with batch size=6

image

@glenn-jocher
Copy link
Member

We display this clearly in the notebook, suggest you start from there:
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb#scrollTo=DLI1JmHU7B0l

image

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Sep 19, 2020
@buimanhlinh96
Copy link

Hi @glenn-jocher, how can i add albumentations in torch library for augmentations in DataLoader?

@glenn-jocher
Copy link
Member

@buimanhlinh96 you can customize the trainloader here:

class LoadImagesAndLabels(Dataset): # for training/testing

@Auth0rM0rgan
Copy link

@glenn-jocher, Could you please provide more details that how to use albumentations in the DataLoader??

@glenn-jocher
Copy link
Member

glenn-jocher commented Nov 11, 2020

@Auth0rM0rgan we don't have an integration with albumentations. YOLOv5 augmentation hyperparameters are set here:

hsv_h: 0.015 # image HSV-Hue augmentation (fraction)
hsv_s: 0.7 # image HSV-Saturation augmentation (fraction)
hsv_v: 0.4 # image HSV-Value augmentation (fraction)
degrees: 0.0 # image rotation (+/- deg)
translate: 0.1 # image translation (+/- fraction)
scale: 0.5 # image scale (+/- gain)
shear: 0.0 # image shear (+/- deg)
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
flipud: 0.0 # image flip up-down (probability)
fliplr: 0.5 # image flip left-right (probability)
mosaic: 1.0 # image mosaic (probability)
mixup: 0.0 # image mixup (probability)

You are free to modify the dataloader also as you see fit here:

class LoadImagesAndLabels(Dataset): # for training/testing

@Auth0rM0rgan
Copy link

Auth0rM0rgan commented Nov 11, 2020

Hey @glenn-jocher, Thanks for the quick reply!

I know about the YOLOv5 augmentation but I'm trying to add some blur augmentations that are not in the yolov5 augmentation such as MotionBlur, Gaussian Blur, and ... but I have difficulty to add these augmentations inside YOLOv5. I will appreciate if you can help me even a little...

Gracias!

@glenn-jocher
Copy link
Member

@Auth0rM0rgan ah I see. Well you can access the raw image as a numpy array img here after it's already passed through the YOLOv5 augmentations, so I would just insert any augmentations here. Be careful to correctly modify labels correspondingly as well if your augmentations require it though.

yolov5/utils/datasets.py

Lines 526 to 528 in f6b3c96

if mosaic:
# Load mosaic
img, labels = load_mosaic(self, index)

@Auth0rM0rgan
Copy link

@glenn-jocher Thanks! made it work. Now I can apply a set of different kinds of augmentations at pixel-level and spatial-level!

@glenn-jocher
Copy link
Member

@Auth0rM0rgan hey cool! Maybe you could consider submitting a PR for general Albumentations integration? I know its a popular tool so others might find that useful.

@Auth0rM0rgan
Copy link

@glenn-jocher, Sure! will do it during the weekend!

@glenn-jocher
Copy link
Member

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

@glenn-jocher glenn-jocher linked a pull request Jul 4, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale Stale and schedule for closing soon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants