Thursday, July 9, 2020

Deepfashion2 Dataset implementation step by step with python code also providing my trained model

In this blog we will implement DeepFashion2 Dataset. we will use Mask Rcnn for train our own Fashion Model. I will providing all source code on in this blog.

It contains 13 popular clothing categories from both commercial shopping stores and consumers. 
'short_sleeved_shirt', 'long_sleeved_shirt', 'short_sleeved_outwear', 'long_sleeved_outwear', 'vest', 'sling', 'shorts', 'trousers', 'skirt', 'short_sleeved_dress', 'long_sleeved_dress', 'vest_dress', 'sling_dress'
this Dataset use for detection, segmentation etc. you can read more


Training images: train/image Training annotations: train/annos

Validation images: validation/image Validation annotations: validation/annos

Test images: test/image

Implementation

This is the information of Deepfashion2 Dataset. now i will show step by step  implementation with source code you can copy this code and paste on your Pycharm Python, or any ids.

First we need to download the Dataset of Deepfashion2.

Download 

you can click on this side Click here.. it takes time because the file size is large. you need to download 

1. train.zip (10 GB)

2. validation.zip (2 GB)

After download these files. you need to unzip this files but you need password for this.
You need fill in the form to get password for unzipping files Click here. after you fill this form.

You will  received Email from yyge13@gmail.com which is email content password for unzip the zip files. you can unzip the zip files one by one.

Note : - ( if you not receive password email you can mail me.)

After unzips the zip files you get images and corresponding Json files. 

In this blog we will use Mask_Rcnn to train custom model using Deepfashion2 Dataset 





and further any other Blogs we will use YOLO and Deeplabs model.

we need to convert this Dataset to coco format. we need Python script to convert coco format. 

In python script you must be insert the path of train unzip Dataset images folder (which is content images) and json folder (which is content json files corresponding image). also insert the path of empty train.json file.

This empty train.json file you can create manually or your choice you want to create. but we need to insert this 3 paths to convert coco format for training.

Unzip train folder :-

1). Image folder (which is given on unzip train folder).

2). Json folder ( which is given on train folder).

3). Empty json files ( create manually name likes train.json ).

and also we need same process for unzip validation folder. 

we need to execute python script one more time for convert validation folder to coco format.

Unzip validation folder :- 

1). Image folder (which is given on unzip validation folder).

2). Json folder ( which is given on validation folder).

3). Empty json files ( create manually name likes val.json ).

Remember :- 

(1). Please change Line Number 114 for ( you want to select number of images for training or you can set default values validation 32,153 and train 1,91,961 ).
(2). Line Number 118 and 119 Path for ( your unzip train and validation folder path according your system).
(3). Line Number 224 Path for ( your manually created train.json files and val.json files).

Source Code : -  In my Github Page Click here.

This python script must be done 2 times one for train unzip folder and second is unzip validation folder According your both folder path in your system with line number.

Finally you get 2 files after run deepfashion2coco.py files for 2 times one for train and second is validation 

You Get

1). train.json
2). val.json
 
After you get this files you successful done coco format conversion. 

You create dataset folder manually then create 2 more folder in dataset folder one is train and second is validation. then paste the train.json or train images  on train folder similar for validation folder.

we ready for train the model on GPU.   

your Dataset folder file structure look likes :
dataset
    1 ) train
          I) images
          II) train.json
    2) validation 
         I) images
         2)val.json         

First we need clone the projects on your system or any AWS machine. 

Clone Projects on my Github Repository Click here.

or cmd :- https://github.com/Manishsinghrajput98/Deepfashion2_Training.git

we are using python 3 for training. you create virtual environment using python 3

cmd :-  virtualenv -p python3 localenv

cmd :-  source localenv/bin/activate

now you install requirement.txt which mentioned on projects.

cmd :- cd Deepfashion2_Training

cmd :- pip install -r requirement.txt

Note :- If you get any types of error during installation. you can run this script and install package on Run time if you get error for no module found just install these package using pip.

I have train my model according this requirement.txt package. i know there are many update on Packages you need to follow updated packages. don't worry the updation is not reflect your training.
a
And also we need to Download pre-trained mask rcnn model train on  the COCO dataset. to download these model and past on clone project and also create logs folder. 

After download you get this files mask_rcnn_coco.h5 this files paste on your clone project and we need to create logs folder manually and also need to paste our dataset folder on clone projects 

if you have any problem to install pycocotools package on your virtual environment to solved issue or  Click here.

before doing above steps install cython  

cmd :-  pip install cython
cmd :- git clone https://github.com/pdollar/coco.git
cmd :- cd coco/PythonAPI
cmd :- make 
cmd :- sudo make install
cmd :- sudo python setup.py install

we ready to train model using Deepfashion2 Dataset.

After finish all work your clone projects files structure look likes 

Deepfashion2_Training
(1) dataset
    (I) train
        i.images
        ii.train.json
    (II) validation
        i.images
        ii.train.json
(2) source 
(3) tools
(4) lib
(5) main.py
(6) model_test.py
(7) requirement.txt


Befor training you need to change on main.py python file. Line Number 33, 40, 41, 42, 43, 212.

Line 33 :- GPU_COUNT = 2  (according to your system capability)

Line 40 :-  train_img_dir = "/home/asa/projects/datasets/train/image" (according to your system path which is our unzip train folder)

Line 41 :- train_json_path = "/home/asa/projects/match_rcnn/tools/train.json" (according to your system path which is our train.json which is generated to coco conversion)

Line 42 :- valid_img_dir = "/home/asa/projects/datasets/validation/image" (according to your system path which is our unzip validation folder)

Line 43 :- valid_json_path = "/home/asa/projects/match_rcnn/tools/valid.json" (according to your system path which is our val.json which is generated to coco conversion)

Line 212 :- Number of Epochs default 30 (you can change according your result or system capability) 

New model starting from pre-trained COCO weights
cmd :- python main.py train --weights=coco

Resume training on last trained model
cmd :- python main.py train --weight=last

Run this command on terminal with activate your virtual environment in Deepfashion2_Training folder 


show this type of images on your terminal you successful training start and after complete 1 Epochs your model save on logs folder (which you create manually)  

After train the model you get the model in your logs folder just paste the path of your last weights file and also images path which is you test and run on your terminal

Source code on my github page 

cmd :- python model_test.py 

your result show on images 



This is the simple script you need to used these script for images and save images on your system  and Also i am providing scripts to Test your model on random videos.

This script i have used on google colab. you can try on your system or colab.

Before this you need to mount to drive. it's not difficult. you just click mount drive button in google Colab. also select the GPU options in google colab.

For Images In Google Colab :- Replaced the path of your local system ,colab, drive. 

Also you need to upload your train model on drive and replace the path of your trained model in python scripts.

cmd :- !python deepfashion_images.py --i /content/00ac770f-055c-4f3f-9681-669926a263ef_91.jpg --o /content/output_test

--i : - Path of input images
 
--o :- Path of output images

After run this script on google colab. the input images after detected save on google colab in output folder. you can Also store Detected images on google drive just insert the path of output images in command line.

For Videos In Google Colab :-  Replaced the path of your local system ,colab, drive.

cmd :- !python deepfashion_videos.py --i /content/video_test.mp4

--i :- path of input videos

After run this script you will received the output video output.avi.

Note :- If you don't want to use google colab. you can try on your machine.

Official GitHub Repository of Deepafashion2 Dataset  Click here. or Click here

Also you can create Flask API for Mask-RCNN DeepFashion2 Machine Learning Model.
if you want to Flask API using python Click here
 
Short videos (Youtube


Note :- I have trained model with 100 Epochs. If you need my trained model. Click here

Results of My models with 100 Epochs.




Thanks if you have any doubt please comment.

22 comments:

  1. It's new idea for you.. keep it up bro.. 👍
    I totally committed to help you anytime

    ReplyDelete
  2. Thank you very much for this guide and for your help. I succeeded in everything.

    ReplyDelete
  3. Great work! Thanks Manish for shearing.

    ReplyDelete
  4. Very nice work ! thank you for this great tuto... I have a question if you don't mind: what is the accuracy of your trained model ?

    ReplyDelete
    Replies
    1. Your welcome sir.

      I have used this model on my clients project. It's provide good accuracy. You can use 👍

      Delete
    2. Thanks for replying, yeah it's really so good, i've tested it on many pictures it provides good results. thank you for sharing !

      Delete
  5. Hi, you didn't mention the configuration you used to get this good resaults

    ReplyDelete
    Replies
    1. I have already mentioned ! Please check. And also send email.

      Delete
  6. The work is great and it is working nice. But can you please help me out for landmark detection in this? Thanks

    ReplyDelete
  7. Getting Below error while executing main.py

    Traceback (most recent call last):
    File "main.py", line 10, in
    from lib.model import MaskRCNN
    File "/home/prasad/project/Deepfashion2_Training/Deepfashion2_Training/lib/model.py", line 25, in
    from lib import utils
    File "/home/prasad/project/Deepfashion2_Training/Deepfashion2_Training/lib/utils.py", line 21, in
    import urllib.request
    ImportError: No module named request

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. 2019Deepfashion2** password of unzip zip file

    ReplyDelete
  10. In the requirement.txt file it cannot find the package
    ERROR: No matching distribution found for absl-py==0.9.0

    ReplyDelete
  11. DO ANYONE HAVE THE UPDATED CODE FOR THIS

    ReplyDelete

If you have any doubts. Please let me know