rbgirshick / py-faster-rcnn

Faster R-CNN (Python implementation) -- see https://github.com/ShaoqingRen/faster_rcnn for the official MATLAB version
Other
8.13k stars 4.11k forks source link

Training a modified ZF-net on py-faster-rcnn #483

Open sungchank opened 7 years ago

sungchank commented 7 years ago

I'm trying to train a modified ZF-net of py-faster-rcnn. I have conducted a simple experiment. I first have trained the unmodified ZF-net model with pascal voc data. I have initialized weights using the pretrained model with imagenet. The train was set to run for 1000 iterations only but it has ended up with worse accuracy as expected. Then, I have modified the channel size of the first convolution layer of the original ZF-net from 96 to 64. I have also renamed the first and second convolution layers while keeping the channel size of the second layer. Those two new layers were randomly initialized using weight_filler and bias_filler since they cannot be initialized from the pretrained model. After the modifications, I have trained the modified rcnn model with the same configurations to the unmodified training. The last part of logs are as follows.

... im_detect: 4952/4952 0.030s 0.001s Evaluating detections Writing aeroplane VOC results file Writing bicycle VOC results file Writing bird VOC results file Writing boat VOC results file Writing bottle VOC results file Writing bus VOC results file Writing car VOC results file Writing cat VOC results file Writing chair VOC results file Writing cow VOC results file Writing diningtable VOC results file Writing dog VOC results file Writing horse VOC results file Writing motorbike VOC results file Writing person VOC results file Writing pottedplant VOC results file Writing sheep VOC results file Writing sofa VOC results file Writing train VOC results file Writing tvmonitor VOC results file VOC07 metric? Yes AP for aeroplane = 0.0909 Traceback (most recent call last): File "./tools/test_net.py", line 90, in test_net(net, imdb, max_per_image=args.max_per_image, vis=args.vis) File "/home/skim/py-faster-rcnn/tools/../lib/fast_rcnn/test.py", line 295, in test_net imdb.evaluate_detections(all_boxes, output_dir) File "/home/skim/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 322, in evaluate_detections self._do_python_eval(output_dir) File "/home/skim/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 285, in _do_python_eval use_07_metric=use_07_metric) File "/home/skim/py-faster-rcnn/tools/../lib/datasets/voc_eval.py", line 148, in voc_eval BB = BB[sorted_ind, :] IndexError: too many indices for array

I found that the error I got indicates that the modified model learned nothing. Is this error due to too short iterations or insufficient training data with pascal voc? I guess that training only with pascal voc data is not a solution. If so, how can I use imagenet data to pretrain the modified ZF-net? My understanding is that training using imagenet entirely from scratch would take 2-3 weeks normally, which is not acceptable for me. Because I will try to modify ZF-net in many ways, I need an efficient way to pretrain models using imagenet data and to finetune it using pascal voc whenever I create a new one. Can any one give me some advise for this issue?

MSutt commented 7 years ago

I think this error append when you have no prediction for a class you can prevent it by modifiying the voc_eval.py file, after reading the detfile you can add:

if len(lines) == 0:
     return 0,0,0

it may resolve your evaluation issue, but you will have to find by yourself the best way to fine tune from pretrain model.

njblur commented 7 years ago

that's because there is nothing detected, I met this issue also when not use the pre-trained image-net model, I guess some parameters like conv2d filters are not initialized into the right range.