endernewton / tf-faster-rcnn

Tensorflow Faster RCNN for Object Detection
https://arxiv.org/pdf/1702.02138.pdf
MIT License
3.65k stars 1.57k forks source link

How to add a deconv layer after 'conv5'? #165

Open hgfm opened 7 years ago

hgfm commented 7 years ago

I changed /tf-faster-rcnn/lib/nets/vgg16.py .

after net = slim.repeat(net, 3, slim.conv2d, 512, [3, 3], trainable=is_training, scope='conv5') add net = slim.conv2d_transpose(net, 512, [4, 4], stride=4, scope='deconv')

I used ./experiments/scripts/train_faster_rcnn.sh 0 pascal_voc vgg16 to train, but it error. What else file should I change? I'm not sure what result in ValueError: cannot reshape array of size 17100 into shape (1,152,200,9) Thank you for your help!

Here is the error log:

2017-07-21 16:48:45.753730: W tensorflow/core/framework/op_kernel.cc:1158] Invalid argument: ValueError: cannot reshape array of size 17100 into shape (1,152,200,9)
2017-07-21 16:48:45.802082: W tensorflow/core/framework/op_kernel.cc:1158] Invalid argument: ValueError: operands could not be broadcast together with shapes (273600,1) (17100,1) 
Traceback (most recent call last):
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1139, in _do_call
    return fn(*args)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1121, in _run_fn
    status, run_metadata)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/contextlib.py", line 89, in __exit__
    next(self.gen)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: ValueError: cannot reshape array of size 17100 into shape (1,152,200,9)
     [[Node: vgg_16/anchor/PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_INT32, DT_FLOAT, DT_INT32], Tout=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], token="pyfunc_2", _device="/job:localhost/replica:0/task:0/cpu:0"](vgg_16/rpn_cls_score/BiasAdd, _arg_Placeholder_2_0_2, _arg_Placeholder_1_0_1, vgg_16/anchor/PyFunc/input_3, vgg_16/ANCHOR_default/generate_anchors, vgg_16/anchor/PyFunc/input_5)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./tools/trainval_net.py", line 141, in <module>
    max_iters=args.max_iters)
  File "/home/fm-wingspan/tf-faster-rcnn/tools/../lib/model/train_val.py", line 338, in train_net
    sw.train_model(sess, max_iters)
  File "/home/fm-wingspan/tf-faster-rcnn/tools/../lib/model/train_val.py", line 236, in train_model
    self.net.train_step(sess, blobs, train_op)
  File "/home/fm-wingspan/tf-faster-rcnn/tools/../lib/nets/network.py", line 386, in train_step
    feed_dict=feed_dict)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 789, in run
    run_metadata_ptr)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 997, in _run
    feed_dict_string, options, run_metadata)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1132, in _do_run
    target_list, options, run_metadata)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1152, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: ValueError: cannot reshape array of size 17100 into shape (1,152,200,9)
     [[Node: vgg_16/anchor/PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_INT32, DT_FLOAT, DT_INT32], Tout=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], token="pyfunc_2", _device="/job:localhost/replica:0/task:0/cpu:0"](vgg_16/rpn_cls_score/BiasAdd, _arg_Placeholder_2_0_2, _arg_Placeholder_1_0_1, vgg_16/anchor/PyFunc/input_3, vgg_16/ANCHOR_default/generate_anchors, vgg_16/anchor/PyFunc/input_5)]]

Caused by op 'vgg_16/anchor/PyFunc', defined at:
  File "./tools/trainval_net.py", line 141, in <module>
    max_iters=args.max_iters)
  File "/home/fm-wingspan/tf-faster-rcnn/tools/../lib/model/train_val.py", line 338, in train_net
    sw.train_model(sess, max_iters)
  File "/home/fm-wingspan/tf-faster-rcnn/tools/../lib/model/train_val.py", line 106, in train_model
    anchor_ratios=cfg.ANCHOR_RATIOS)
  File "/home/fm-wingspan/tf-faster-rcnn/tools/../lib/nets/network.py", line 311, in create_architecture
    rois, cls_prob, bbox_pred = self.build_network(sess, training)
  File "/home/fm-wingspan/tf-faster-rcnn/tools/../lib/nets/vgg16.py", line 70, in build_network
    rpn_labels = self._anchor_target_layer(rpn_cls_score, "anchor")
  File "/home/fm-wingspan/tf-faster-rcnn/tools/../lib/nets/network.py", line 150, in _anchor_target_layer
    [tf.float32, tf.float32, tf.float32, tf.float32])
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/script_ops.py", line 198, in py_func
    input=inp, token=token, Tout=Tout, name=name)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_script_ops.py", line 38, in _py_func
    name=name)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
    op_def=op_def)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2506, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/fm-wingspan/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1269, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): ValueError: cannot reshape array of size 17100 into shape (1,152,200,9)
     [[Node: vgg_16/anchor/PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_INT32, DT_FLOAT, DT_INT32], Tout=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], token="pyfunc_2", _device="/job:localhost/replica:0/task:0/cpu:0"](vgg_16/rpn_cls_score/BiasAdd, _arg_Placeholder_2_0_2, _arg_Placeholder_1_0_1, vgg_16/anchor/PyFunc/input_3, vgg_16/ANCHOR_default/generate_anchors, vgg_16/anchor/PyFunc/input_5)]]
yaoqi-zd commented 7 years ago

have you solved the problem? I also want to use deconv layer

hgfm commented 7 years ago

@yaoqi-zd Sorry, I am not, maybe the problem caused when generate anchor. I'm still trying to solve it, if you have solved, please tell me how to do, thanks!

endernewton commented 7 years ago

yes the anchor size needs to be the same as your feature map after deconv.

zqdeepbluesky commented 6 years ago

@hgfm are you solve this problem ?can you tell me what to do ,thanks in advance.