Sunday, July 12, 2020

Yolo model trained using Deepfashion2 Dataset

Hello Friends in this blog i will be implement Yolo model training process using DeepFashion2 Dataset.



If want to study about DeepFashion2 so you can Click here.

I want to show only practical not theory.

First we need to Download Deepfashion2 Dataset and after this we need to convert coco format. 

I have been  implemented  step by step conversion and training process on mask rcnn model Click here

After you convert coco format. now we need to convert coco to Yolo model format.

And after this process we ready to train our Yolo model using Deepfashion2 Dataset.

But one more point guys. I have a some Hardware resources problem. so i will using only 200 images For demo purpose. If you have high specification hardware so you can use all Deepfashion2 Dataset ( train - 1,91,961, validation - 32,153 ) and also you can use Google Colab for This. i Have use my local system for show entire process.

Note :- If you want to decrease the size of your Deepfashion2 Dataset. in this Python script you need to Change line number 114 before convert  coco format conversion.

Now start the conversion coco to yolo.

First we need to clone Click here

or

cmd :- git clone  https://github.com/Manishsinghrajput98/deepfashion2coco_to_yolo_.git

cmd :- cd deepfashion2coco_to_yolo_

you can create virtual environment 

cmd :-  virtualenv local

cmd:-  source local/bin/activate

Or also you can ues both foder of deepfashion2 dataset train and validation. If you use both folder so you need to execute python script for two times and after this process you have to combine both Folder.

cmd :- pip install -r requirements.txt

the run python script 

cmd :-  python3 example.py --datasets COCO --img_path /home/rajput/Desktop/deepfashion2coco_to_yolo_/Dataset_Deepfashion2/train/Images/ --label /home/rajput/Desktop/deepfashion2coco_to_yolo_/Dataset_Deepfashion2/train/train.json --convert_output_path YOLO/ --img_type ".jpg" --manipast_path ./ --cls_list_file coco.names

set path according to your system. then run


And after this you create data folder and paste our YOLO (which is generated .txt files) folder content And Images folder content.


And now we setup will set Yolo3 project. first we need to install Darknet Click here

or 

cmd :- git clone https://github.com/pjreddie/darknet.git

cmd :- cd darknet

cmd :- make

cmd :- cd..

After this you clone my project on github 

cmd :- https://github.com/Manishsinghrajput98/yolo_training.git
 
cmd :- cd yolo_training

And after this we need to install pre-trained yolo v3 model Click here

or 

open your terminal 

cmd :- wget https://pjreddie.com/media/files/darknet53.conv.74
 
Then copy all the content of your clone yolo_training folder also downloaded pre-trained model files And, data folder (which is content images and txt files) to darknet folder 

After that you run one python script to generate train.txt and test.txt files.

cmd :- python process.py data  

Data folder which is indicate as a arguments (content images and txt files)

after that the folder looks like 



Finally we are ready for yolo model training. one more point you have to change the path of the train.txt and test.txt , backup folder, and .cfg files which is mention on tast.data files

After that we 

cmd :- ./darknet detector train /home/rajput/Desktop/darknet/Task/task.data /home/rajput/Desktop/darknet/Task/task.cfg /home/rajput/Desktop/darknet/Task/darknet53.conv.74

if you get this type of error 

/bin/bash: ./darknet: Is a directory.

so you add darknet keyword (There is a darknet file inside the darknet directory which you need to use and you need to give that darknet file's path (not the directory's path))

cmd:- ./darknet/darknet detector train /home/rajput/Desktop/darknet/Task/task.data /home/rajput/Desktop/darknet/Task/task.cfg /home/rajput/Desktop/darknet/Task/darknet53.conv.74



if you want to use GPU so mention this keywords (-gpus 0) multiple GPU use (-gpus 0,1)

cmd:- ./darknet/darknet detector train /home/rajput/Desktop/darknet/Task/task.data /home/rajput/Desktop/darknet/Task/task.cfg /home/rajput/Desktop/darknet/Task/darknet53.conv.74 -gpus 0             ## change path according your system  
  
and resume training so use backup folder last weights

cmd :-  ./darknet/darknet detector train /home/rajput/Desktop/darknet/Task/task.data /home/rajput/Desktop/darknet/Task/task.cfg /home/rajput/Desktop/darknet/Task/backup/task.backup

## change path according your system  

you can edit .cfg files according your dataset, accuracy, system performance (like batch size, subdivisions etc ) 

and now test the model using this command 

cmd :- ./darknet detector test /home/rajput/Desktop/darknet/Task/task.cfg /home/rajput/Desktop/darknet/Task/task_30000.weights /home/rajput/Desktop/darknet/Task/0a0c3c07-3d52-418b-b589-9b670caae173.jpg -thresh 0.1        ## change path according your system  

Also you can Create Flask API for real time projects. and if you comment on this comment section so i will be providing full detection api for this so you can use real time projects.

Thanks.

2 comments:

  1. Do you have an implementation which predicts the landmarks? Thanks

    ReplyDelete
  2. names: Using default 'data/names.list'
    Couldn't open file: data/names.list
    Why am getting this error?

    ReplyDelete

If you have any doubts. Please let me know