ultralytics / yolov3

YOLOv3 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
10.22k stars 3.45k forks source link

train on own dataset with other class #433

Closed andrew-begain closed 5 years ago

andrew-begain commented 5 years ago

hi glenn-jocher thanks for your great job i want to fine-tune with my own dataset,But this data set does not belong to the coco data set category, it is a separate category,what should i do? thanks

glenn-jocher commented 5 years ago

Hello, thank you for your interest in our work! This issue seems to apply to the following question:

Ownmarc commented 5 years ago

@andrew-begain Look at the tutorial glenn wrote in this repo, it is a good start!

I made my own script to set-up this repo from images and xml annotation produced from the labelimg tool that creates all the files needed to do custom training in this repo. Here are the big steps:

  1. Create your labels for your images (I use labelimg repo which provides a UI for that and creates XML files, I think it can also produce yolo files, but I dont like the way its done)
  2. Convert your annotations to the yolo format. You can check the official Darknet repo if you need more info
  3. Create the .names file for you classes (see the one for coco, its 1 class per line)
  4. Make the training and validation list of all your images (make sure the path to your image is good, use full path or use path relative to train.py)
  5. Create the .data file (see the one for coco, need to specify few paths in your project, make sure to do a split for training data and validation data and name your folders "images" and "labels" and make sure there is 1 label file for each image file)
  6. Create the yolo .cfg file. Needs to be edited depending on the number of classes you have. I also suggest to take a look at the kmeans algo in the utils of this repo to get better anchor boxes for your data set. Can help alot if you have only big objects in your images or only small objects.
  7. My script produces a start command that I can then use to start the training, it will look like python3 train.py --cfg cfg/yolov3-7c.cfg --data cfg/data.data --batch-size 8 --img-size 608 --epoch 300. For batch size, you'll need to do some trial and error, see what fits on your GPU VRAM
andrew-begain commented 5 years ago

@glenn-jocher @glenn-jocher thank you very much for your reply,i will read your repo carefully,and i hope i do not have annother qustion,

andrew-begain commented 5 years ago

hi glenn,Ownmarc I am sorry to ask annother qustion, I want to retrain the model, how to initialize the parameters except the yolo layer,thanks

glenn-jocher commented 5 years ago

@andrew-begain all parameters are initialized to random values to start, which may be replaced with a full pretrained model or a pretrained backbone. Read the wikis: https://github.com/ultralytics/yolov3/wiki/Example:-Transfer-Learning https://docs.ultralytics.com/yolov5/tutorials/train_custom_data