endernewton / tf-faster-rcnn

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

Assign requires shapes of both tensors to match. lhs shape= [1,1,4096,4096] rhs shape= [4096,4096] #371

Open zxqcreations opened 6 years ago

zxqcreations commented 6 years ago

Hi, I've tried to build my own vgg16 with my code gennet which is used to generate CNNs. By following vgg's paper, I generated a vgg16 model by myself (use testgen.py to generate a vgg16.ckpt). But when I tried to apply it to train_faster_rcnn.sh, I met this issue:

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [1,1,4096,4096] rhs shape= [4096,4096] [[Node: Fix_VGG16/save/Assign_2 = Assign[T=DT_FLOAT, _class=["loc:@Fix_VGG16/fc7_conv"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Fix_VGG16/fc7_conv, Fix_VGG16/save/RestoreV2:2)]]

I didn't edit any code gitted from this repository, and executed ./experiments/scripts/train_faster_rcnn.sh 0 pascal_voc vgg16.

When I execute inspect_checkpoint.py provided by tensorflow to inspect differences between your model and mine, I got:

  1. fc6: yours: vgg_16/fc6/weights (DT_FLOAT) [7,7,512,4096] mine: vgg_16/fc6/weights (DT_FLOAT) [25088,4096]
  2. fc7: yours: vgg_16/fc7/weights (DT_FLOAT) [1,1,4096,4096] mine: vgg_16/fc7/weights (DT_FLOAT) [4096,4096]
  3. fc8: yours: vgg_16/fc8/weights (DT_FLOAT) [1,1,4096,1000] mine: vgg_16/fc8/weights (DT_FLOAT) [4096,1000]|

Here 'your model' is vgg16.ckpt from google drive while mine is generated by gennet.

there are several difference from fc6 to fc8, but I don't know how to fix it. I'd like to ask you why the shape of fc layers are different or am I wrong? emm. If you are too busy to review this difference, please ignore it.

But I know my vgg16 is not working, waiting for your kindly review.

Jo-Pan commented 6 years ago

same error happens to me. do you know how to fix it?

starthlw commented 5 years ago

I fixed the error in this way: change lines 87,88 in ./lib/nets/vgg16.py fc6_conv = tf.get_variable("fc6_conv", [7, 7, 512, 4096], trainable=False) fc7_conv = tf.get_variable("fc7_conv", [1, 1, 4096, 4096], trainable=False) to fc6_conv = tf.get_variable("fc6_conv", [7 7 512, 4096], trainable=False) fc7_conv = tf.get_variable("fc7_conv", [ 4096, 4096], trainable=False)