Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tiny yolo model body, but cannot retrain #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

glc12125
Copy link

Hey,

I am trying to retrain tiny YOLO to predict traffic signs using gtsdb. I have finished the tiny YOLO body, but when I followed the instructions to retrain the model, I got "Incompatible shapes" in yolo_loss. Here is the command to replicate the issue. And the npz data file is shared here, and the class file is shared here. Note, there is loads of code duplication right now, but after debugging I will clean up.

retrain_tiny_yolo.py --data_path "my_dataset.npz" --classes_path "gtsdb_classes.txt"

Train on 666 samples, validate on 75 samples
Epoch 1/5
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1323, in _do_call
return fn(*args)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1302, in _run_fn
status, run_metadata)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 473, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [32,13,13,5,1] vs. [32,6,6,5,1]
[[Node: yolo_loss/mul_8 = Mul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](yolo_loss/mul_7, yolo_loss/Square_2)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "retrain_tiny_yolo.py", line 356, in
_main(args)
File "retrain_tiny_yolo.py", line 77, in _main
matching_true_boxes
File "retrain_tiny_yolo.py", line 259, in train
callbacks=[logging])
File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 1650, in fit
validation_steps=validation_steps)
File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 1213, in _fit_loop
outs = f(ins_batch)
File "/usr/local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2352, in call
**self.session_kwargs)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 889, in run
run_metadata_ptr)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1120, in _run
feed_dict_tensor, options, run_metadata)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1317, in _do_run
options, run_metadata)
File "/usr/local/lib/python3.6/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: Incompatible shapes: [32,13,13,5,1] vs. [32,6,6,5,1]
[[Node: yolo_loss/mul_8 = Mul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](yolo_loss/mul_7, yolo_loss/Square_2)]]

Caused by op 'yolo_loss/mul_8', defined at:
File "retrain_tiny_yolo.py", line 356, in
_main(args)
File "retrain_tiny_yolo.py", line 68, in _main
model_body, model = create_model(anchors, class_names)
File "retrain_tiny_yolo.py", line 224, in create_model
detectors_mask_input, matching_boxes_input
File "/usr/local/lib/python3.6/site-packages/keras/engine/topology.py", line 603, in call
output = self.call(inputs, **kwargs)
File "/usr/local/lib/python3.6/site-packages/keras/layers/core.py", line 651, in call
return self.function(inputs, **arguments)
File "/Users/liangchuangu/Development/machine_learning/YAD2K/yad2k/models/keras_yolo.py", line 281, in yolo_loss
K.square(1 - pred_confidence))
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 900, in binary_op_wrapper
return func(x, y, name=name)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 1123, in _mul_dispatch
return gen_math_ops._mul(x, y, name=name)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 2821, in _mul
"Mul", x=x, y=y, name=name)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3042, in create_op
op_def=op_def)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1521, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Incompatible shapes: [32,13,13,5,1] vs. [32,6,6,5,1]
[[Node: yolo_loss/mul_8 = Mul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](yolo_loss/mul_7, yolo_loss/Square_2)]]

@alecGraves
Copy link
Contributor

I know it's been a while, but the Theano support branch supports loading the tiny yolo darknet model and retraining.

@Lescurel
Copy link

Lescurel commented Sep 7, 2018

I know it's been a while, but your problem is related to your re-implementation of TinyYolo.

Your darknet should be :

def darknetref_body():
    """Generate first 8 conv layers of Darknet-Ref."""
    return compose(
        DarknetConv2D_BN_Leaky(16, (3, 3)),
        MaxPooling2D(),
        DarknetConv2D_BN_Leaky(32, (3, 3)),
        MaxPooling2D(),
        DarknetConv2D_BN_Leaky(64, (3, 3)),
        MaxPooling2D(),
        DarknetConv2D_BN_Leaky(128, (3, 3)),
        MaxPooling2D(),
        DarknetConv2D_BN_Leaky(256, (3, 3)),
        MaxPooling2D(),
        DarknetConv2D_BN_Leaky(512, (3, 3)),
        MaxPooling2D(strides=1, padding='same'),
        DarknetConv2D_BN_Leaky(1024, (3, 3)),
        DarknetConv2D_BN_Leaky(512, (3, 3))
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants