Object Detection Using YOLO v4 on Custom Dataset | Practical Implementation
ฝัง
- เผยแพร่เมื่อ 7 ก.พ. 2025
- Step by step Implementation of YOLO v4.
Dataset Preparation for yolo v4.
Train your custom Yolo v4 Model
Test your Yolo v4 Model
Github Link: github.com/Aar...
What is YOLO?
YOLO stands for You Only Look Once
YOLO is an algorithm that uses neural networks to provide real-time object detection. This algorithm is popular because of its speed and accuracy. It has been used in various applications to detect traffic signals, people, parking meters, and animals.
With the timeline, it has become faster and better, with its versions named as:
YOLO V1
YOLO V2
YOLO V3
YOLO V4
YOLO V5
YOLO V2 is better than V1 in terms of accuracy and speed.
YOLO V3 is not faster than V2 but is more accurate than V2 and so on.
How the YOLO algorithm works?
YOLO algorithm works using the following three techniques:
1- Residual blocks: image is divided into various grids. Each grid has a dimension of n X n
2- Bounding box regression
3- Intersection Over Union (IOU) : YOLO uses IOU to provide an output box that surrounds the objects perfectly.
Contact: aarohisingla1987@gmail.com
#yolov4 #yolo #objectdetection #computervision #deeplearning #ai #artificialintelligence #ml #machinelearning #neuralnetworks #darknet
Most awaited video ...thanks so much mam for the video ...
welcome
Thank you so much!
Your setup video with 1 line command and this tutorial on training yolo worked perfectly 1st try for me 🎉
I used LabelImg for annotations instead tho.
Best teacher out there for YOLO :)
Glad it helped!
Hey Aroshi, I want to thank you.
you saved me in the final year project❤
My pleasure 😊
You can use LabelIMG tool for Annotation. It is easier to annotate images in yolo format with it.
How to use?
Mam you said that After running the precess.py file we wil get train.py and text.py file.But I am not getting those file after run process.py.....
I follow all the procedure that you given ... But HereI am getting error ..please help
Mam you said that After running the precess.py file we wil get train.py and text.py file.But I am not getting those file after run process.py.....
I follow all the procedure that you given ... But HereI am getting error ..please help
@@hasibulislamsquads513 aarohisingla1987@gmail.com
How many classes do we need to give while using LabellImg
best explanation on internet on yolo model thank u so much.
Glad my video is helpful!
mam, your way of teaching is Exellent, Ossm
Glad to hear that
Superb video maam
Thanks!
Kudos for this content
Thank you!
Thank you very much Aarohi for making up this video. Very useful.
Glad my video helped you
Thank you for the amazing tutorial, you left nothing uncovered! I wish I could have subscribed and liked more than once!
Glad it was helpful 😊
Thanks for your efforts and for sharing your knowledge
Welcome
Hi Aarohi, It's an excellent effort to share your knowledge. Nice Video. I was working on the same. I could not able to train my model. I am using windows 10 Operating system. i got this error.: ./darknet: error while loading shared libraries: libcuda.so.1: cannot open shared object file: No such file or directory. Can you please help me to sort out this problem
Please check this video for darknet installation: th-cam.com/video/MEB0SEgmtKg/w-d-xo.html
I am getting the same error. Could you please tell me what you did to rectify it ?
it's urgent for me. could you please tell me?
Thank you Ms aarohi for your efforts
Welcome!!
Thank you so much.. Explain clearly..
glad my video is helpful
Thank you great explanation 🤡
You're welcome!
Excellent tutorial. Can you share the presentation also for reference ?
God bless you
Thankyou
mam after creating dataset while mounting to drive at timeline 32:54 i am getting the following error for the command ln-s/content/gdrive/my/Drive/mydrive
/bin/bash: ln-s/content/gdrive/my/Drive/mydrive: No such file or directory or ln: invalid option -- 'c'
Try 'ln --help' for more information. please help me proceed further thanks in advance
only one line is coming in test.txt while in train.txt i could get for
all d images..why mam?
Thank you ma'am.. useful video it help me alot, I appreciate your efforts
There are two types of images:
1- One image with one object
2- One image with multiple objects.
In this video you deal with the first type. Is it same for the second type? Or how to train images using yolov4 that contained multiple objects? Please, I need your help
Process is same for the second type also
How to evaluate the multiple classes per image..please I need your reply
thanks it's great tutorial
but i wanted to ask if there's a way to work with yolov4 locally in vscode or in jupyter?
Not that I know of
Hii mam .We tried as same as your way but at last while prediction imshow it just giving same image as output without any bounding box and prediction class..Can you pls help on this
If you are not getting any bounding boxes that means you model is not yet trained for recognizing the objects. You need to run more more epochs for training. You can also try to increase the number of images if your dataset is small.
Hello sir
Good work , i have a question the labels of yolov5 is it the same in yolo v4 and yolov3 italk about annotation ( the file.txt)
i hope to answer me
Thanks.
Yes, its same
@@CodeWithAarohi Thanks madam
Hi Aarohi, thank you for the video.
Wondering I used Git clone to download bbox-label-tool package, but inside it I could not see the three files you said "bbox tool""convert""and proces", wondering if they have been removed? thank you.
Maybe. I haven't used this tool after this video. So no idea.
Thak you very much! Is this implementation similar to yolov4 in darknet please? Or your implementation is different?
This implementation is yolov4 in darknet framework only
@@CodeWithAarohi Thank you. Can you please implementation from scratch of YOLOv4 using PyTorch if possible?
I guess what you did is data augmentation for the dataset and then you used a YOLOv4 implementation from darknet?
When selecting folder for annotation, it was not displaying picture for bounding boxes.Then how should i get the coordinates of my picture mam
Can you share the presentation will us ? It will help to follow the steps your explaination is wonderful
Thank you for the wonderful video.I have a a question... How to get the bounding box coordinate in predicted image ?
Thanx, for this wonderful video, Do we have option to get coordinates of the detected objects in yolov4 or yolov5.
Never tried that so don't know right now
@@CodeWithAarohi Thanks for your prompt reply.
Thank you madam for this tutorial, its very useful
I have question about prediction using video as input
When i put the path of the video, it display this message ( cannot load image)
How can i resolve this problem please
try to give absolute path of video
In label tool i am not getting images..please tell me mam
so how does it works with the live detection when Using the CCTV with this ? do we need to create the files for that too
Provide the path(url) of your cctv in source
Mam I am doing fake or real logo detection project with the help of yolo4 algorithm. Can u please suggest me which yolo version is better? for my project
Try to work with yolov8 or yolov9 or YOLO-NAS. YOLOv9 is good for small object detection and for the objects which are farther from camera.
When selecting a picture containing folder for annotation ,it will showing no items match your search though it is in the same folder in files. what should I do? Mam
You just press ok and images will open
i do not know why i can not save the weights in the backup folder....whole code is running fine bt the issue is that i do not get the weights
Weights are not setting up in backup folder. Not getting weights anywhere. ,How to resolve
Thanks for the video..Can you pls make a video about model evaluation part(IoU & mAP) for this project or for previous YoloV3 project.
Sure will do soon
@@CodeWithAarohi hi aarohi can I get the files for all the versions of yolo that you have implemented please
Thanks Mam for this detailed video.
I am working on an object detection problem where it is required to detect objects at two levels. At the first level, it has classes and at the second level, it has subclasses. For example, classes are birds or animals or flowers. And subclasses for animals are e.g., dog, cat or lion. For subclass level detection, it is required to add extra CNN and Dense layers to the subclass level detection. In the present YOLOv4, I am not able to update the neural network layer architecture.
Kindly guide in implementation. Thanks in advance.
why the label folder in data folder is not being deleted.
while training it generates a warning that label cannot load it may be for ms coco
Ma'am, How to evalute YOLOV4 after training with multilables?
Hi mam I tried to train my model but its showing the error as darknet error location. Is there any way to resolve it mam
how will the process file run
and create weight file
Nice tutorial..
I want to run object detection in raspberry pi .what will be changes
Glad my video is helpful and I never executed this on raspberry so no idea.
Thanks for the video. Great content!.. I have a question... what if I’m interested on performing object detection on both object classes in the same picture, that is, phone and laptop? What would’ve changed from data prep to model setup? Thanks!
Process will be same.
@@CodeWithAarohi Thanks for your reply! I still have trouble on trying to set up the files directories for such task.. Let's say I have a tree structure like this:
train:
-class 1
--study A
--- picture_1.png
--- picture_2.png
...
--study B
--- picture_1.png
---picture_2.png
-class 2
-- study C
--- picture_n.png
- class 3
-- study
--- pictures.png
the task would be to classify a study in one of the classes based on multiple images input. Each study in this case is a sample. The output should be class 1, 2 or class 3, based on the n images I used as input for a specific Study. Do you know what I mean?
@@evandrocardozo62 Did you got your problem solved if yes I have same project and I am confused like hell can you drop your github reposetry for same
Hi ma'am while training the model I am getting the wrong annotation error. Plz, help me out here. thanks!
hi mam,
how can i increase the font size of the label? because they are not readable, so want to increase
mam i am training my model on 150 images (80% train) for one class only, i ran for 4 hours with these configuration values, now i am not getting any output, no predictions are made. if i do thresh -0, many 0% are detected filling up all the predicted image with pink boxes, during training i keep on getting 100% in map value, i am running on google colab
width=320
height=320
channels=3
momentum=0.949
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 6000
policy=steps
steps=4800,5400
mam thank you so much its very clear and easy to understand. but i have one doubt . if I want to train thousands of images then do we have to use the annotation tool manually for every image ? its time consuming know mam any solution for that?
You have to annotate all the images manually.
Just work on public datasets provided by Kaggle and etc.
Instead of this three files can we use labelimg software for annotation i think it's easy and time saving process.
Yes you can use labelimg tool.
how i could use yolo4, yolo5 in two stages detection and classification person accesserois?
Hi Aarohi, is it okay that have an image for laptop called 1.jpg and an image for phone called 1.jpg or is this an issue because both classes images will be combined in the multiple images folder. Should the names of the images not overlap? For example is 1_phone.jpg and 1_laptop.jpg a better way to go? Thank you and great video!
1_phone.jpg and 1_laptop.jpg is a better way
Hi Aarohi, I am new in Data Science. I am working on a object detection project where I need to detect the container numbers. Could you please tell me which steps I need to follow to do this. Thanks
Train your algorithm for different numbers. First collect the data for different numbers. Then annotate the dataset. After that train your model.
@@CodeWithAarohi Thank you so much for your response.
predicted image shows same as the input test image..i think number of epochs should be increased....how can we do that??please help
Hey
Thanks for the vídeo, But What should i do if my dataset isnt in coco classes? I need to train a yolo model to detect helipads
When you want to use yolo algorithm, your algorithm should be in the format which yolo accepts. You need 1 txt file for 1 image. This txt file will have the annotation detail of that particular image. you can use labelImg tool for annotations
Hello mam, after 55.54 I didn't get train and test files, can we connect through something because this project is really important to me.
Copy the code of process.py in your colab notebook and then execute it
as per following the steps there are two darknet folder, one inside the other. the second darknet folder is where process.py should be pasted. But after doing that, running it on collab shows, cant open , no such directory exists,
i.e , its not detecting process.py
Also current_dir and other dir are to be changed , what location address should be put in there?
also please share the roadmap pdf of this whole process, as it becomes lot easier to process what all is going on
you can put the process.py file anywhere but check if the paths are correct of you your dataset folder and also set the path where you want to have your train.txt and test.txt file.
@@CodeWithAarohi where to set the path in the process file ? thoda specefic plz i am beginner
@@CodeWithAarohi Can you please say where to change the path?
Thanks for this best guide ma'am. Do you know where I may find coco dataset with txt-files like in piford in the video? (mean files with info like )?
You can check the official site of coco dataset. There you will get it but not sure
mam image is not displayed I used absolute path but image is not display
Heyyy Mam. Thankyou soo much for this amzing tutorial. I m not able 2 recieve train.txt nd test.txt files by running !python process.py
Thanks Ma'am, unable to execute after process.py, will you plz guide me on that.
Error: There is no data/test.txt file for mAP calculation!
Don't use -map flag.
Or set valid=data/train.txt in your data/Multiple_images.data file.
When you will execute process.py. After that you will get train.txt and test.txt. Check the path which you have defined in process.py file. You will get tyou rtrain.txt file and test.txt file there
@@CodeWithAarohi thank you so much for this tutorial , i am also suffring from the same problem when i execute this commande
please how to solve this problem
i am soo need the answer plz
@@CodeWithAarohi while executing in cmd prompt only we are getting train.txt and test.txt not in google colab..is that right?
Mam why low resolution images are not working on this method??
does all annotation values need to be within (0 and 1)
Great Video, but why don't you share the documentations. It will be helpful for us.
Please check description, github link is mentioned.
when i run this code in colab it gives me empty file as train.txt having no paths to the images
images_list = glob.glob("data/obj/*[jpg|png|jpeg]")
print(images_list)
# Create train.txt file
file = open("data/train.txt", "w")
file.write("
".join(images_list))
file.close()
Upload 'process.py' in data folder and make sure 'process.py' has correct path setup
thank you so much, but i have one question .. where should i upload process.py ? in piford folder or in darknet? i tried uploading it in both but it doesn't work
In darknet folder. Also change the path of current_dir, file_train , file_test variable in process.py file
@@CodeWithAarohi Hello Ma'am, can I keep anywhere inside the darknet folder? And where and how to change the current_dir and all?
@@CodeWithAarohi please let me know how to give current_dir,file _train,file_test and whether we have to make directory for piford by deleting obj directory?
Why didn't we use Labelimg tool, I feel it's way easier than bbox since it comes with an option to save annotations in yolo format.
No Specific reasons :) And yes labelIMG is easier to use.
While training and testing data I'm having the error couldn't open file: data/names.list even the path is correct.. please help
Hi Ms #Aarohi thankyou for you're tutorials, it worked for me. but how can we use the yolov4 weights obtained in python tensorflow and keras.
You need to load the weights. Call the model and then upload the weights
Mam I'm this getting error "" [Errno 2] No such file or directory: '/mydrive/yolov4"" when I execute this command ➡%cd /mydrive/yolov4.
I have created folder with name "yolov4". but the command is not executing. what should I do now?
we need to annonate every single image through labellmg, it there any way we could directly get .txt for all images ?
You need to annotate all the images
@@CodeWithAarohi okay thank you I did it for all the images. Having an error from !./darknet detector train data/piford.data cfg/yolov4-custom.cfg yolov4.conv.137 -dont_show -map...as
loading weights failed because it can't open file yolov4.conv.137
can u share this ?
It started trainning, I have 1100 images and converted all them into .txt file. It is showing 395 hours in trainning and executing... how much time will it take ?
Mam the error coming for me is " 122 Darknet error location: ./src/parser.c, parse_convolutional, line #208
Layer before convolutional layer must output image.: Success"
The error message "Layer before convolutional layer must output image" typically means that the layer before the convolutional layer is not producing an image or feature map that can be used as input to the convolutional layer.
One possible reason for this error is that there may be a mismatch between the size of the output of the previous layer and the size of the input expected by the convolutional layer. You should check the configuration of your layers and ensure that the output of the previous layer matches the input shape of the convolutional layer.
Another possible reason could be that the input image size is not compatible with the network architecture. You may need to adjust the size of the input image or the network architecture to ensure compatibility.
It is also possible that the error is due to a bug or a typo in your code. You should carefully review your code and ensure that all the layer configurations are correct and that there are no syntax errors or typos.
hi! thanks for the video! i have a question btw, how do i prepare a image dataset that have lots of different resolutions?
You can resize them to one size using opencv.
@@CodeWithAarohi i have to do that before labeling?
how can i get label name and confidence over bounding box?
NO need to write any separate code for that. You get a label name with confidence score on bounding box using yolo
@@CodeWithAarohi yup, got it mam, thank you
Hi mam, thank you for details explanation of the whole process. Do you have any specific script for converting XML format to YOLO format for the annotation file? It would be really helpful. Thank you
HI Aarohi, I was wondering if its possible to store the already trained model, like the one in your video, into a python object model so that it can be pickled?
I tried to find multiple ways to save the architecture, state and weights of the model but had no success.
you can save them into tensorflow model, or mini tensorflow
you can save them into tensorflow model, or mini tensorflow
mam i use jupyter notebook pls guide me to how to train my algorithm
Hi maam Im so fan of you. Can u help with my project I am student computer engr. I want to detect trash detection such as bottle,can, wrapper, can give me tips and videos step by step on how to do this? pls maam the deadline is end febuary i hope you notice me.
Hi, Start with collecting a dataset. Then annotate your dataset. Then choose the algorithm which you want to use for training and then start the training. I have videos on yolov5, yolov6, yolov7 and yolov8 for Object detection. You can follow those videos to train your custom model.
@@CodeWithAarohi my project is real-time maam do you have videos of realtime object detection. then i am done labelling image.
Thankyou soo much for this video ma'am and While executing training code I am getting this error "Couldn't open file: data/names.list" can you please help me with this.
You are using wrong file names. There are 2 files, 1 with the extension .data and other file with the extension .names . There is no file with the extension .list
@@CodeWithAarohi Thankyou soo much for your reply Ma'am and I checked everything again but I am still getting this error
"names: Using default 'data/names.list'
Couldn't open file: data/names.list"
Which default value this error is talking about.
Please is YOLOV4 not working in PNG ? until i change every pictures to JPG before i can get my convert.jp
Cctv camera ko yolov7 se kese connect kre
Nice explanation 👌 maam can you please tell me how to run yolov4 for 300 epochs actually i am comparing yolov5 with yolov4 and i ran yolov5 for 300 epochs so how can i compare map of both
Hello Aarohi,
I am working on customizing YOLOv4, but I have encountered an issue. Some of my images are not independent and must be grouped together in either the training or testing set. In order to address this, I would like to modify the 'split_data' function in data.c. However, I am unable to determine which images should be grouped together without accessing their file paths, but I am unsure where to locate this information in the code. Additionally, I am curious as to how the images are associated with their respective filenames.
Thank you for your assistance.
In YOLOv4, the image file paths are typically stored in a text file that is used as input to the training process. The split_data function in data.c is responsible for splitting the image file paths into training and testing sets, so modifying this function is a good approach to address your requirement to group certain images together.
To access the file paths of the images, you can modify the get_paths function in data.c. This function reads the image file paths from a text file and returns them as an array of strings. You can modify this function to also read in additional information, such as a grouping identifier, from the text file and store it in a separate array. For example, you can modify the text file to include a second column with a grouping identifier for each image, and then modify the get_paths function to read in this column and store it in a separate array.
Once you have the grouping information for each image, you can modify the split_data function to ensure that images with the same grouping identifier are grouped together in either the training or testing set. One approach is to modify the function to split the images into groups based on their grouping identifier before performing the random split into training and testing sets. You can then merge the groups together to form the final training and testing sets.
As for how the images are associated with their respective filenames, this is typically done by including the file path of each image in the text file used as input to the training process. The load_data function in data.c reads in this text file and uses the file paths to load the images into memory for training. The data struct in data.c contains an array of image structs, each of which contains a char *filename member that stores the file path of the image. This allows the training process to associate each image with its respective filename.
@@CodeWithAarohi Thank you very much for your answer , it's working !
In Which Folder Do I Have to upload Process.py File or folder Please let me know
Put it in darknet folder
Hi mam, Training in google colab takes too much time. Is there any easy method by the system gpu
Yes you can setup the darknet framework on your PC and can run the algorithm on System GPU
I ran the code with your pictures of laptops and phones. As a result, there is no frame on the test picture. Your video at the end in predictions.jpg also lacks a frame. Is it because there are very few images for training? Or the coordinates are written randomly?
Coordinates are written randomly. Sorry for that. I just created this small dataset for teaching Mask RCNN. Main intent here in this video is to make my Subscribers understand how Mask RCNN works.
@@CodeWithAarohi i didn't understand "Coordinates are written randomly."
can you explain
can we use only one class ,suppose face class,,,,for face detection
Yes you can use 1 class
Hello, can you tell me where to paste process.py in drive ? and what changes to do in it's code. do we need to paste any other file along with it ? what do you mean by all those things @ 39:10
In darknet folder.
@@CodeWithAarohi It did not work for me, Could you help me with that
Hi Aarohi, need to detect logo from different different invoices and want train model for that. plz help me out ow I can achieve that.
Create a dataset (Images of Invoices with Logo) in the format which yolov4 accepts. And then train the algorithm as I have shown in this video.
Mam, how I can find accuracy of the model?
Hi professor, I need your help in my project,
the work consists in the manual annotation of all the nuclei positions and extensions (via a classical bounding box) in a series of images scanned with 40x magnitude. This work will help us in the development of a novel algorithm for nuclei detection via YOLO neural network model, I’m waiting for your answer
Hi, Please mail me your exact requirement at aarohisingla1987@gmail.com
my annotated data is in .xml file type instead of being .text file.. what should I do maam?
Look up convert PascalVOC to Yolo
madam ek hi folder me kaam kar lena chahiye usse aapko bhi confusion na ho, half video me to aap apna hi confusion solve kar rahe ho or complete model can train using that one folder.
How I know the accuracy model after testing?
in my case there is no weight value file in my backupfolder, it is tottaly empty
Check if the path is correct or you have another backup folder in some other directory.
Mam is it mandatory to install jupitar notebook to do this task? Can i just use colab for this?
Yes you can use colab
mam your english are clearly understand, than understanding the topic resolve the prob
Glad to hear that
How can record as a video only when object is detected
Hi , thank you for the tutorial, I followed all the steps and when I execute the process.py nothing happened, the train and the test file doesn't created, could you please help me ? if anyone face this issue could please provide me the solution and thank you.
Check the paths in process.py file. The path of your dataset and also the path of train.txt and test.txt .
Wrong annotation: x = 0, y = 0, < 0 or > 1, file: data/piford/14.txt
Wrong annotation: x = 0, y = 0, < 0 or > 1, file: data/piford/8.txt
Wrong annotation: x = 0, y = 0, < 0 or > 1, file: data/piford/267.txt
Wrong annotation: x = 0, y = 0, < 0 or > 1, file: data/piford/48.txt
Wrong annotation: x = 0, y = 0, < 0 or > 1, file: data/piford/243.txt
can I use this on the ExDark dataset because it has the same format of annotations used for yolo
Yes, If the format is similar then you can use
@@CodeWithAarohi Thanks for the code ma'am I was able to train the model on the ExDark dataset with only 2 classes but the results were incredible. The only thing was that my default annotations had some problem in it so I created the annotations again on roboflow but other than that the model was able to predict very well
@@adityachache great 👍