leeyoshinari / YOLO_v2

The implementation of YOLO v2 with TensorFlow
GNU General Public License v3.0
80 stars 38 forks source link

Something wrong when I run train_val.py #1

Closed Jasonsun1993 closed 6 years ago

Jasonsun1993 commented 6 years ago

Hi Leeyoshinari ! When I tried to run the code you provided, there were always some fault tips occurring. Like:

Traceback (most recent call last): File "train_val.py", line 135, in main() File "train_val.py", line 127, in main train = Train(yolo, pre_data) File "train_val.py", line 53, in init self.saver.restore(self.sess, weight_file) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1666, in restore {self.saver_def.filename_tensor_name: save_path}) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 889, in run run_metadata_ptr) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1120, in _run feed_dict_tensor, options, run_metadata) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1317, in _do_run options, run_metadata) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-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= [125] rhs shape= [425] [[Node: save/Assign_15 = Assign[T=DT_FLOAT, _class=["loc:@biases_22"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](biases_22, save/RestoreV2_15/_1)]]

Caused by op 'save/Assign_15', defined at: File "train_val.py", line 135, in main() File "train_val.py", line 127, in main train = Train(yolo, pre_data) File "train_val.py", line 33, in init self.saver = tf.train.Saver(self.variable_to_restore) # restore variable File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1218, in init self.build() File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1227, in build self._build(self._filename, build_save=True, build_restore=True) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1263, in _build build_save=build_save, build_restore=build_restore) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 751, in _build_internal restore_sequentially, reshape) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 439, in _AddRestoreOps assign_ops.append(saveable.restore(tensors, shapes)) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 160, in restore self.op.get_shape().is_fully_defined()) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/ops/state_ops.py", line 276, in assign validate_shape=validate_shape) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/ops/gen_state_ops.py", line 57, in assign use_locking=use_locking, name=name) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2956, in create_op op_def=op_def) File "/home/jason/.conda/envs/py3_5/lib/python3.5/site-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= [125] rhs shape= [425] [[Node: save/Assign_15 = Assign[T=DT_FLOAT, _class=["loc:@biases_22"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](biases_22, save/RestoreV2_15/_1)]]

leeyoshinari commented 6 years ago

I'm sorry to reply you so late. It is caused by the length of cfg.CLASSES is not same as the size of the output layer of the weightsfile. You use weightsfile for coco to tarin voc dataset. If this, the weights of output layer don't restore.