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

Are there anybody use resnet v2 as the base network? #377

Closed Dontfall closed 6 years ago

Dontfall commented 6 years ago

when I use the resnet v2 as the base network in faster rcnn, it has the errors: Fixing 3 blocks. Traceback (most recent call last): File "./tools/train_net.py", line 221, in main() File "./tools/train_net.py", line 217, in main max_iters=args.max_iters) File "/home/xiewei/densecap-tensorflow/tools/../lib/dense_cap/train.py", line 485, in train_net sw.train_model(sess, max_iters) File "/home/xiewei/densecap-tensorflow/tools/../lib/dense_cap/train.py", line 318, in train_model lr, train_op = self.construct_graph(sess) File "/home/xiewei/densecap-tensorflow/tools/../lib/dense_cap/train.py", line 148, in construct_graph layers = self.net.create_architecture('TRAIN', num_classes=1, tag='default') File "/home/xiewei/densecap-tensorflow/tools/../lib/nets/network.py", line 812, in create_architecture rois, cls_prob = self._build_network(training) File "/home/xiewei/densecap-tensorflow/tools/../lib/nets/network.py", line 601, in _build_network fc7 = self._head_to_tail(pool5, is_training) File "/home/xiewei/densecap-tensorflow/tools/../lib/nets/resnet_v2.py", line 131, in _head_to_tail scope=self._resnet_scope) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim/python/slim/nets/resnet_v2.py", line 221, in resnet_v2 net, activation_fn=nn_ops.relu, scope='postnorm') File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 181, in func_with_args return func(*args, current_args) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/layers.py", line 643, in batch_norm outputs = layer.apply(inputs, training=is_training) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/layers/base.py", line 671, in apply return self.call(inputs, args, kwargs) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/layers/base.py", line 559, in call self.build(input_shapes[0]) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/layers/normalization.py", line 189, in build trainable=True) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/layers/base.py", line 458, in add_variable trainable=trainable and self.trainable) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 1203, in get_variable constraint=constraint) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 1092, in get_variable constraint=constraint) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 417, in get_variable return custom_getter(custom_getter_kwargs) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1539, in layer_variable_getter return _model_variable_getter(getter, args, kwargs) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1531, in _model_variable_getter custom_getter=getter, use_resource=use_resource) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 181, in func_with_args return func(*args, *current_args) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/variables.py", line 262, in model_variable use_resource=use_resource) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 181, in func_with_args return func(args, **current_args) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/variables.py", line 217, in variable use_resource=use_resource) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 394, in _true_getter use_resource=use_resource, constraint=constraint) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 742, in _get_single_variable name, "".join(traceback.format_list(tb)))) ValueError: Variable resnet_v2_50/postnorm/gamma already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/variables.py", line 217, in variable use_resource=use_resource) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 181, in func_with_args return func(*args, **current_args) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/variables.py", line 262, in model_variable use_resource=use_resource)

daicoolb commented 6 years ago

I have the same problem , can anybody show your solution ?

Dontfall commented 6 years ago

@daicoolb I have not solved this problem.

daicoolb commented 6 years ago

I have tried to read the step code on by one , but I didn't find the wrong variable scope.

Dontfall commented 6 years ago

@daicoolb me too!

daicoolb commented 6 years ago

Now , I have solved the problem , THANKS

Dontfall commented 6 years ago

@daicoolb 哇,请问,你是怎么解决的

Dontfall commented 6 years ago

@daicoolb Excuse me, how did you solve it?

daicoolb commented 6 years ago

just coding the BN

Dontfall commented 6 years ago

@daicoolb thanks,yesterday, I haver solved the problem,but, arise a new problem. Traceback (most recent call last): File "./tools/train_net.py", line 221, in main() File "./tools/train_net.py", line 217, in main max_iters=args.max_iters) File "/home/xiewei/densecap-tensorflow/tools/../lib/dense_cap/train.py", line 485, in train_net sw.train_model(sess, max_iters) File "/home/xiewei/densecap-tensorflow/tools/../lib/dense_cap/train.py", line 325, in train_model rate, last_snapshot_iter, stepsizes, np_paths, ss_paths = self.initialize(sess) File "/home/xiewei/densecap-tensorflow/tools/../lib/dense_cap/train.py", line 237, in initialize restorer.restore(sess, self.pretrained_model) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1666, in restore {self.saver_def.filename_tensor_name: save_path}) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 889, in run run_metadata_ptr) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1120, in _run feed_dict_tensor, options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1317, in _do_run options, run_metadata) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1336, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [1024] rhs shape= [2048] [[Node: save_1/Assign_217 = Assign[T=DT_FLOAT, _class=["loc:@resnet_v2_50/postnorm/moving_variance"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](resnet_v2_50/postnorm/moving_variance, save_1/RestoreV2_217/_9)]]

Caused by op u'save_1/Assign_217', defined at: File "./tools/train_net.py", line 221, in main() File "./tools/train_net.py", line 217, in main max_iters=args.max_iters) File "/home/xiewei/densecap-tensorflow/tools/../lib/dense_cap/train.py", line 485, in train_net sw.train_model(sess, max_iters) File "/home/xiewei/densecap-tensorflow/tools/../lib/dense_cap/train.py", line 325, in train_model rate, last_snapshot_iter, stepsizes, np_paths, ss_paths = self.initialize(sess) File "/home/xiewei/densecap-tensorflow/tools/../lib/dense_cap/train.py", line 236, in initialize restorer = tf.train.Saver(variables_to_restore) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1218, in init self.build() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1227, in build self._build(self._filename, build_save=True, build_restore=True) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1263, in _build build_save=build_save, build_restore=build_restore) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 751, in _build_internal restore_sequentially, reshape) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 439, in _AddRestoreOps assign_ops.append(saveable.restore(tensors, shapes)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 160, in restore self.op.get_shape().is_fully_defined()) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/state_ops.py", line 276, in assign validate_shape=validate_shape) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 57, in assign use_locking=use_locking, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2956, in create_op op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1470, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [1024] rhs shape= [2048] [[Node: save_1/Assign_217 = Assign[T=DT_FLOAT, _class=["loc:@resnet_v2_50/postnorm/moving_variance"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](resnet_v2_50/postnorm/moving_variance, save_1/RestoreV2_217/_9)]]

daicoolb commented 6 years ago

I did NOT have the problem, maybe you use the wrong BN

Dontfall commented 6 years ago

@daicoolb Hey, can you show your solution? Let me see how to change. thanks!!

Dontfall commented 6 years ago

@daicoolb Thank you, Miss Sister

daicoolb commented 6 years ago

jsut modify the BN is ok.

Dontfall commented 6 years ago

@daicoolb sorry,I don‘t understand. Is it here? def resnet_arg_scope(is_training=True, batch_norm_decay=0.997, batch_norm_epsilon=1e-5, batch_norm_scale=True): batch_norm_params = { 'is_training': False, 'decay': batch_norm_decay, 'epsilon': batch_norm_epsilon, 'scale': batch_norm_scale, 'trainable': False, 'updates_collections': tf.GraphKeys.UPDATE_OPS }

with arg_scope(
        [slim.conv2d],
        weights_regularizer=slim.l2_regularizer(cfg.TRAIN.WEIGHT_DECAY),
        weights_initializer=slim.variance_scaling_initializer(),
        trainable=is_training,
        activation_fn=tf.nn.relu,
        normalizer_fn=slim.batch_norm,
        normalizer_params=batch_norm_params):
    with arg_scope([slim.batch_norm], **batch_norm_params) as arg_sc:
        return arg_sc
Dontfall commented 6 years ago

@daicoolb 小姐姐,请问,你能将具体的修改步骤教我吗?谢谢!

daicoolb commented 6 years ago

just move the BN after pool5 is OK

Dontfall commented 6 years ago

@daicoolb thanks

rnsandeep commented 5 years ago

@Dontfall Can you please explain what changes need to be done i got the same error of Variable resnet_v2_152/postnorm/gamma already exists, disallowed.