leeyoshinari / YOLO_tiny

The implementation of YOLO_v1 with TensorFlow
MIT License
13 stars 4 forks source link

How to change the numbers of CLASSES? #1

Open tgbamg opened 6 years ago

tgbamg commented 6 years ago

When I try to change the numbers of CLASSES, the program produces an error:

"tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [14351,128] rhs shape= [70450,128] "

How could I solve this?

leeyoshinari commented 6 years ago

It's not necessary to change the number of CLASSES. Change the CLASSES, the number of CLASSES change automatically.

tgbamg commented 6 years ago

@leeyoshinari Your default CLASSES has 20 items, I just change the CLASSES with 40 items, without changing any other things. But the Error occured as I mentioned above. Should I change the size of the net?

tgbamg commented 6 years ago

@leeyoshinari Here is the full log:

C:\pycharm_projects\yolo_tiny>python train.py WARNING:tensorflow:From C:\pycharm_projects\yolo_tiny\yolo\yolo_net.py:139: calling reduce_max (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version. Instructions for updating: keep_dims is deprecated, use keepdims instead 2018-07-19 14:34:41.731424: I c:\users\user\source\repos\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2 2018-07-19 14:34:42.326276: I c:\users\user\source\repos\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1356] Found device 0 with properties: name: GeForce GTX 1060 major: 6 minor: 1 memoryClockRate(GHz): 1.733 pciBusID: 0000:01:00.0 totalMemory: 6.00GiB freeMemory: 4.97GiB 2018-07-19 14:34:42.326364: I c:\users\user\source\repos\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1435] Adding visible gpu devices: 0 2018-07-19 14:34:42.814056: I c:\users\user\source\repos\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-07-19 14:34:42.814125: I c:\users\user\source\repos\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:929] 0 2018-07-19 14:34:42.814903: I c:\users\user\source\repos\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:942] 0: N 2018-07-19 14:34:42.815038: I c:\users\user\source\repos\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4743 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1) Restore weights from: C:\pycharm_projects\yolo_tiny\data\output\YOLO_tiny.ckpt Traceback (most recent call last): File "train.py", line 167, in main() File "train.py", line 160, in main solver = Solver(yolo, pascal) File "train.py", line 67, in init self.saver.restore(self.sess, self.weights_file) File "D:\Python27\lib\site-packages\tensorflow\python\training\saver.py", line 1802, in restore {self.saver_def.filename_tensor_name: save_path}) File "D:\Python27\lib\site-packages\tensorflow\python\client\session.py", line 900, in run run_metadata_ptr) File "D:\Python27\lib\site-packages\tensorflow\python\client\session.py", line 1135, in _run feed_dict_tensor, options, run_metadata) File "D:\Python27\lib\site-packages\tensorflow\python\client\session.py", line 1316, in _do_run run_metadata) File "D:\Python27\lib\site-packages\tensorflow\python\client\session.py", line 1335, 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= [4096,2450] rhs shape= [4096,1470] [[Node: save/Assign_23 = Assign[T=DT_FLOAT, _class=["loc:@local3/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](local3/weights, save/RestoreV2:23)]] [[Node: save/RestoreV2/_249 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_22_save/RestoreV2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

Caused by op u'save/Assign_23', defined at: File "train.py", line 167, in main() File "train.py", line 160, in main solver = Solver(yolo, pascal) File "train.py", line 42, in init self.saver = tf.train.Saver(variable_to_restore) File "D:\Python27\lib\site-packages\tensorflow\python\training\saver.py", line 1338, in init self.build() File "D:\Python27\lib\site-packages\tensorflow\python\training\saver.py", line 1347, in build self._build(self._filename, build_save=True, build_restore=True) File "D:\Python27\lib\site-packages\tensorflow\python\training\saver.py", line 1384, in _build build_save=build_save, build_restore=build_restore) File "D:\Python27\lib\site-packages\tensorflow\python\training\saver.py", line 835, in _build_internal restore_sequentially, reshape) File "D:\Python27\lib\site-packages\tensorflow\python\training\saver.py", line 494, in _AddRestoreOps assign_ops.append(saveable.restore(saveable_tensors, shapes)) File "D:\Python27\lib\site-packages\tensorflow\python\training\saver.py", line 185, in restore self.op.get_shape().is_fully_defined()) File "D:\Python27\lib\site-packages\tensorflow\python\ops\state_ops.py", line 283, in assign validate_shape=validate_shape) File "D:\Python27\lib\site-packages\tensorflow\python\ops\gen_state_ops.py", line 63, in assign use_locking=use_locking, name=name) File "D:\Python27\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "D:\Python27\lib\site-packages\tensorflow\python\framework\ops.py", line 3392, in create_op op_def=op_def) File "D:\Python27\lib\site-packages\tensorflow\python\framework\ops.py", line 1718, 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= [4096,2450] rhs shape= [4096,1470] [[Node: save/Assign_23 = Assign[T=DT_FLOAT, _class=["loc:@local3/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](local3/weights, save/RestoreV2:23)]] [[Node: save/RestoreV2/_249 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_22_save/RestoreV2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

leeyoshinari commented 6 years ago

Don't restore the weight of the last layer when you begin to train the net.

tgbamg commented 6 years ago

I could not find the weight of the last layer. Should I change the .ckpt file? Where and what should I change? Can you tell me more details? Thanks a lot.

leeyoshinari commented 6 years ago

Modify train.py. Comment out line 35, and use line 36 and line 66. In line 36, the '-3' means the last three variables don't restore. You can try to change it to '-1', '-2', '-5' or others.

tgbamg commented 6 years ago

@leeyoshinari I change it to '-2', it works fine now. Thanks a lot! I want to draw the box with red and bolder lines in the test.py file, which line should I change and how to change it?

leeyoshinari commented 6 years ago

In test.py, you should modify the function of 'draw_result', you need to know opencv.

tgbamg commented 6 years ago

@leeyoshinari Thanks! My CLASSES have 20 items. If I want to train on my own dataset, how many pictures should I have in the dataset at least?

leeyoshinari commented 6 years ago

The more, the better. But need to note the distribution of data.

tgbamg commented 6 years ago

The distribution of my data is Uniform distribution. Is that ok?

leeyoshinari commented 6 years ago

OK

tgbamg commented 6 years ago

@leeyoshinari Thanks a lot!

ghffarpk commented 6 years ago

@tgbamg have you trained any model by using this code?