deep-diver / Soccer-Ball-Detection-YOLOv2

YOLOv2 trained against custom dataset
116 stars 43 forks source link

Error in training with filters in yolov2.cfg #26

Open angelisgiorgos opened 4 years ago

angelisgiorgos commented 4 years ago

https://stackoverflow.com/questions/60622851/impl-invalidargumenterror-input-to-reshape-is-a-tensor-with-1227400-values-but

I'm having the same error as described above. In my code i'm having 43 classes and when i'm changing the filter value in yolov2.cfg, i'm getting the following error:

`Parsing C:/Users/giwrg/tensorflow/models/yolo_v2/yolov2.cfg
Loading C:/yolov2.weights ...
Traceback (most recent call last):
  File "rn.py", line 91, in <module>
    tfnet = TFNet(options)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\net\build.py", line 58, in __init__
    darknet = Darknet(FLAGS)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\dark\darknet.py", line 27, in __init__
    self.load_weights()
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\dark\darknet.py", line 82, in load_weights
    wgts_loader = loader.create_loader(*args)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\utils\loader.py", line 105, in create_loader
    return load_type(path, cfg)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\utils\loader.py", line 19, in __init__
    self.load(*args)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\utils\loader.py", line 77, in load
    walker.offset, walker.size)
AssertionError: expect 203175760 bytes, found 203934260`

Then i tried setting back my yolov2.cfg filters values back to 425 and got this:

``Traceback (most recent call last):
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\client\session.py", line 1365, in _do_call
    return fn(*args)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\client\session.py", line 1350, in _run_fn
    target_list, run_metadata)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\client\session.py", line 1443, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 1227400 values, but the requested shape requires a multiple of 86640
         [[{{node Reshape}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "rn.py", line 92, in <module>
    tfnet.train()
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\net\flow.py", line 56, in train
    fetched = self.sess.run(fetches, feed_dict)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\client\session.py", line 956, in run
    run_metadata_ptr)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\client\session.py", line 1180, in _run
    feed_dict_tensor, options, run_metadata)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\client\session.py", line 1359, in _do_run
    run_metadata)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\client\session.py", line 1384, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 1227400 values, but the requested shape requires a multiple of 86640
         [[node Reshape (defined at D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\framework\ops.py:1748) ]]

Original stack trace for 'Reshape':
  File "rn.py", line 91, in <module>
    tfnet = TFNet(options)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\net\build.py", line 76, in __init__
    self.setup_meta_ops()
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\net\build.py", line 139, in setup_meta_ops
    if self.FLAGS.train: self.build_train_op()
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\net\help.py", line 15, in build_train_op
    self.framework.loss(self.out)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\darkflow\net\yolov2\train.py", line 56, in loss
    net_out_reshape = tf.reshape(net_out, [-1, H, W, B, (4 + 1 + C)])
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\ops\array_ops.py", line 131, in reshape
    result = gen_array_ops.reshape(tensor, shape, name)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\ops\gen_array_ops.py", line 8115, in reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\framework\op_def_library.py", line 794, in _apply_op_helper
    op_def=op_def)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\util\deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3357, in create_op
    attrs, op_def, compute_device)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3426, in _create_op_internal
    op_def=op_def)
  File "D:\Users\giwrg\anaconda3\lib\site-packages\tensorflow_core\python\framework\ops.py", line 1748, in __init__
    self._traceback = tf_stack.extract_stack()

my yolov2.cfg parameters:

`[convolutional]
size=1
stride=1
pad=1
filters=425
activation=linear

[region]
anchors =  0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828
bias_match=1
classes=43
coords=4
num=5
softmax=1
jitter=.3
rescore=1

object_scale=5
noobject_scale=1
class_scale=1
coord_scale=1

absolute=1
thresh = .1
random=1`