How to train a custom YOLOv5 model using CodeProject.AI Training for YoloV5 6.2 module

VideoDad

Pulling my weight
Joined
Apr 13, 2022
Messages
163
Reaction score
219
Location
USA
If you had thousands of pictures of Spot, you could definitely train a model on those pictures and it would be able to find Spot in other pictures you gave it.

But the big problem is it may not necessarily know enough to distinguish Spot from a similarly shaped animal. If you want to get a model that can definitely recognize only Spot, you'll need lots of images that are not Spot, so it can learn the difference.
 

gmprpl

n3wb
Joined
Mar 11, 2024
Messages
4
Reaction score
1
Location
Poland
If you had thousands of pictures of Spot, you could definitely train a model on those pictures and it would be able to find Spot in other pictures you gave it.

But the big problem is it may not necessarily know enough to distinguish Spot from a similarly shaped animal. If you want to get a model that can definitely recognize only Spot, you'll need lots of images that are not Spot, so it can learn the difference.
So how important is it to include negative examples?
Creating a dataset from Open Images V7 will not have any, right?
If I have my collection of images for just a single class, do I need to throw in random images without any labels?
 

VideoDad

Pulling my weight
Joined
Apr 13, 2022
Messages
163
Reaction score
219
Location
USA
So how important is it to include negative examples?
Creating a dataset from Open Images V7 will not have any, right?
If I have my collection of images for just a single class, do I need to throw in random images without any labels?
If your chosen object looks similar to another, then consider including images that could generate false positives. For example, if you are training a model to recognize horses, you might want include pictures of zebras without labels.

That's probably not the best example, but you get the idea. They should be images chosen for their potential to be false positives, not just random images.
 

gmprpl

n3wb
Joined
Mar 11, 2024
Messages
4
Reaction score
1
Location
Poland
If your chosen object looks similar to another, then consider including images that could generate false positives. For example, if you are training a model to recognize horses, you might want include pictures of zebras without labels.

That's probably not the best example, but you get the idea. They should be images chosen for their potential to be false positives, not just random images.
Thanks a lot for your help so far! I was able to initialize my first training.

I've got a few other questions now.
Should I expect a significant difference in perfromance between a model with 2000 images of just one class vs the same set of images with 5 different classes (additional objects, more bounding boxes)?
Are there any easy to follow guidelines regarding training parameters - number of epochs, number of workers, tuning, model size? Or.. should I treat settings from your example as the best default settings for most applications?
 
Last edited:

AlwaysSomething

Getting the hang of it
Joined
Apr 24, 2023
Messages
65
Reaction score
27
Location
US
2 questions:

1. What are the minimum hardware requirements for training custom models?

I know that's a loaded question but to elaborate, I have no need for a GPU (e.g. gaming, video editing, etc.) so all my computers are using integrated graphics. If I needed to get a graphics card for the sole purpose of creating a model or two what could I get by with? Is it possible to get something for $100 ($200-250 max) without the the training running almost an entire month or even an entire week?

Can a high end CPU work just as well? If so, would it need a lot of memory as well or would 16 or 32 GB be enough? At least with the CPU I can repurpose it (e.g.: new Proxmox server).

2. What is the difference between training a model for a GPU versus training the model for a Coral TPU? Or is there a difference?

I'm still learning about Models and YOLO. I thought I had it but with the new versions of everything I don't think I was right, or maybe I was partially correct. I thought YOLO was the algorithm (engine) and Models were what the algorithm used for processing. I guess where I am confused is in the Install Modules list there are many options for ObjectDetection with different YOLO versions. But then when I look in the model options (for Object Detection Coral) I see YOLOv5, YOLOv8, MobileNet SSD, etc. Sorry for my lack of knowledge.
 

mailseth

Getting the hang of it
Joined
Dec 22, 2023
Messages
126
Reaction score
88
Location
California
Most models can be used on a Coral TPU but require some extra steps to get them exported as the appropriate .tflite file and then more steps to get them segmented across multiple TPUs. YOLOv8 is relatively easy to export since they have the settings built into their export feature, but it’s not a simple model and is not completely compatible with the TPU.
 

Pentagano

Getting comfortable
Joined
Dec 11, 2020
Messages
612
Reaction score
282
Location
Uruguay
Most models can be used on a Coral TPU but require some extra steps to get them exported as the appropriate .tflite file and then more steps to get them segmented across multiple TPUs. YOLOv8 is relatively easy to export since they have the settings built into their export feature, but it’s not a simple model and is not completely compatible with the TPU.
If I find another model .tflite file on git how do I program cpai to use that specific custom model? I'm at the bottom of the learning curve..
 

mailseth

Getting the hang of it
Joined
Dec 22, 2023
Messages
126
Reaction score
88
Location
California
If you’re starting from ‘scratch’ with an existing .tflite file, the first step would be to instal the TPU compiler and converting to that format:

I think the YOLOv8 export takes care of that for you, but it may still be needed if you find your own .tflite file. Segmenting so it runs well across more than one TPU would require installing the profiling compiler, which requires Ubuntu 20.04 and a particular package installed with Bezel. I don’t know if how to get it installed in CPAI, but I’m sure it can be supported if someone wants the functionality.
 

AlwaysSomething

Getting the hang of it
Joined
Apr 24, 2023
Messages
65
Reaction score
27
Location
US
So the models that come with CPAI (e.g.: "EfficientDet-Lite" and "MobileNet SSD") are there multiple "versions"? One for a single TPU versus one for Dual TPU?

I'm a complete newb as well and was reading the Coral documentation but that is obviously different than using the module that comes with CPAI. The module that comes with CPAI seems WAY easier but wasn't sure if we can use it directly with a TPU. Sounds like it needs extra steps?
 

mailseth

Getting the hang of it
Joined
Dec 22, 2023
Messages
126
Reaction score
88
Location
California
For the original models:

There are really two models (MobileNet & EfficentDet) in your comment in different sizes and variations. Mainly think of the different sizes. Then, for models that don't fit well on one TPU, I've been playing with segmenting them with different strategies. For example, see my file here here:

Different layers of the model run on different TPUs and some layers run on the CPU. So different files for each model / size / TPU count combination. This isn't really something to worry about when building the model, however. It seems to be pretty random exactly what the best strategy is and when the YOLO models work well on a single TPU and when they don't. Smaller models and smaller tensor sizes tend to work better, but it's not always very predictable.

For training I'd personally just use the CLI here:

But I’ve never trained a deep learning model myself, and would trust Mike to know better than I. And I know that it exports models to a single TPU (generally) well and easily with a single command. Getting them to run on multiple TPUs is more tricky to do well, but if there's interest I can discuss my learnings.
 
Last edited:
Top