incremental_detectors icon indicating copy to clipboard operation
incremental_detectors copied to clipboard

[Tutorial] How to run the code...

Open jinyu121 opened this issue 5 years ago • 12 comments

I copy this post from my blog.


What is the most distressing thing in life?

Not money, not paper, but the author released their fantastic code while you do not know how to run it.

So, this tutorial records how I run the code using VOC 2007 dataset.

Prepare

  1. Install Tensorflow 1.5 (conda install tensorflow-gpu==1.5)
  2. Install Matlab
  3. Clone the code
  4. Make folders: datasets,resnet
  5. Download the pre-trained weights of backbone

Download dataset

Well, nothing to say.

Then, make a soft link ln -s XXXX/VOCdevkit ./datasets/voc/VOCdevkit/

Finally, create a folder mkdir -p ./datasets/voc/VOCdevkit/VOC2007/EvalCache/, or you will get an error when evaluating.

Generate proposals

I HATE MATLAB.

  1. cd into the code folder
  2. git clone https://github.com/pdollar/edges
  3. Download https://pdollar.github.io/toolbox/archive/piotr_toolbox.zip and unzip it
  4. Open compute_edgeboxes.m. Comment the COCO part, uncomment VOC part. Change paths. Notice that the result folder should be EdgeBoxesProposals
  5. cd edges and compile it follow the instructions:
  mex private/edgesDetectMex.cpp -outdir private '-DUSEOMP' CXXFLAGS="\$CXXFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp"
  mex private/edgesNmsMex.cpp    -outdir private '-DUSEOMP' CXXFLAGS="\$CXXFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp"
  mex private/spDetectMex.cpp    -outdir private '-DUSEOMP' CXXFLAGS="\$CXXFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp"
  mex private/edgeBoxesMex.cpp   -outdir private '-DUSEOMP' CXXFLAGS="\$CXXFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp"
  1. Run compute_edgeboxes.m . It will take a looooooooooooooong time

PS: the toolbox says that it can process images at the speed of 60fps, but in my machine, 0.6 FPS. :sob: 6 hours for VOC, and 37+ hours for COCO.

Make tfrecord

Well, next, generate tfrecord files.

Open datasets.py, in the end, you can see the __main__. Modify it, or just stay them unchanged.

If your split is not called train, val, trainval or test, delete the assert in VOCLoader.

Then, run this file.

The result file will show in the datasets folder.

Run the code! hahaha

For example, I want to train (5+5+5+5).

To start the first session, run

python3 frcnn.py \
    --run_name=voc_5 \
    --num_classes=5 \
    --dataset=voc07 \
    --max_iterations=40000 \
    --action=train,eval \
    --eval_ckpts=40k \
    --learning_rate=0.001 \
    --lr_decay 30000 \
    --sigmoid

And for the following sessions:

python3 frcnn.py sigmoid \
    --run_name=voc_10 \
    --num_classes=5 \
    --extend=5 \
    --dataset=voc07 \
    --max_iterations=40000 \
    --action=train,eval \
    --eval_ckpts=40k \
    --learning_rate=0.0001 \
    --sigmoid \
    --pretrained_net=voc_5 \
    --distillation \
    --bias_distillation

python3 frcnn.py sigmoid \
    --run_name=voc_15 \
    --num_classes=10 \
    --extend=5 \
    --dataset=voc07 \
    --max_iterations=40000 \
    --action=train,eval \
    --eval_ckpts=40k \
    --learning_rate=0.0001 \
    --sigmoid \
    --pretrained_net=voc_10 \
    --distillation \
    --bias_distillation

python3 frcnn.py sigmoid \
    --run_name=voc_20 \
    --num_classes=15 \
    --extend=5 \
    --dataset=voc07 \
    --max_iterations=40000 \
    --action=train,eval \
    --eval_ckpts=40k \
    --learning_rate=0.0001 \
    --sigmoid \
    --pretrained_net=voc_15 \
    --distillation \
    --bias_distillation

And you can notice that this code only use the first GPU.

BTW: you should change the parameter, like 40K, to your own!!!

Use on my own dataset

Personally, it is easy to convert other dataset formats to VOC format. Isn't it?

So, the first step, convert your dataset! (For me, I convert COCO to VOC)

Then, replace the class names in voc_loader.py.

Then, search 20 through all codes, and replace into your class numbers. (For me, 20 to 80)

Finally, run python3 dataset.py to generate tfrecord files, and train the net.


WARNING: Maybe you should write a script to re-start training after it crashes due to the annoying NaN loss......


Thank you again for the amazing code, and have fun.

jinyu121 avatar Aug 05 '18 07:08 jinyu121

Hi jinyu121. Thank you for this fantasic tutorial and i felt happy when you do this, but i am stuck at step 5 of the Generate Proposals. I tried to install Edges following pdollar's instructions. It was not working. How to install Structured Edge Detection Toolbox on Ubuntu.

masaruhoang avatar Aug 07 '18 09:08 masaruhoang

@jinyu121 Great work! It saves us lots of time : )

Joker316701882 avatar Aug 13 '18 08:08 Joker316701882

Hi jinyu121. Thank you for this fantasic tutorial and i felt happy when you do this, but i am stuck at step 5 of the Generate Proposals. I tried to install Edges following pdollar's instructions. It was not working. How to install Structured Edge Detection Toolbox on Ubuntu.

Hello, have you solved this problem? I have the same problem. If you have solved it, could you tell me how to solve it

DaQiZi avatar Mar 27 '19 14:03 DaQiZi

@masaruhoang Hello, have you solved this problem? I have the same problem. If you have solved it, could you tell me how to solve it

DaQiZi avatar Mar 27 '19 14:03 DaQiZi

I gave up as this code uses Matlab :(

giangnguyen2412 avatar Dec 06 '19 09:12 giangnguyen2412

@jinyu121 Thank you so much!!

I've modified a line in the code "dataset.py" for can run on Python 2.7 and TensorFlow 1.4.0 or less. I hope that help to future people. I changed the line 73 for something like that:

example = tf.train.Example(features=tf.train.Features(feature={"img_features", "proposals", "objects"}))

For the users that don't can run the pdollar or installed it, Matlab is easier than pdollar. The code delay around 1 hour. The instructions are:

1.- Open Matlab 2.- Open the file compute_edgeboxes.m 3.- Modified the paths such as: addpath(genpath('/home/user/incremental_detectors/edges/')); addpath(genpath('/home/user/incremental_detectors/piotr_toolbox/toolbox/')); voc_dir = '/home/user/incremental_detectors/datasets/voc/VOCdevkit/VOC2007/'; model = load('/home/user/incremental_detectors/edges/models/forest/modelBsds'); 4.- This generate the data into dataset folder

You should follow the instructions that Jinyu told us. I only mentioned some things to help.

AldrichCabrera avatar Jun 29 '20 07:06 AldrichCabrera

I gave up as this code uses Matlab :( @giangnguyen2412 Same here!! Did you find anything else over the internet for Incremental learning in Object detection? (Code not paper)

vishwa30 avatar Nov 30 '20 04:11 vishwa30

@vishwa30 why you ask me that? There are a lot of papers about Incremental learning in Object detection. Just googling and you can find them.

giangnguyen2412 avatar Nov 30 '20 05:11 giangnguyen2412

https://www.google.com/search?q=continual+learning+object+detection&oq=continual+learning+objec&aqs=chrome.0.0i457j69i57.3294j0j7&sourceid=chrome&ie=UTF-8

giangnguyen2412 avatar Nov 30 '20 05:11 giangnguyen2412

@jinyu121 @Joker316701882 @AldrichCabrera @masaruhoang @giangnguyen2412 guys, when I running the script for training first (let's say 3 classes), I am getting this error:

tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value resnet_v1_50/block3/unit_4/bottleneck_v1/conv2/BatchNorm/beta [[{{node resnet_v1_50/block3/unit_4/bottleneck_v1/conv2/BatchNorm/beta/read}}]]

My iterations have been completed but I think this is while "eval" process. Thanks in advance for your help.

niranjansuthar70 avatar Dec 10 '20 12:12 niranjansuthar70

Thank you for this amazing tutorial

ataftaf avatar Jun 21 '22 15:06 ataftaf

Please, did you run compute_edgeboxes.m after using your own data ? (because for me, it changes even the number of classes) Thanks

ataftaf avatar Jun 24 '22 13:06 ataftaf