guigzzz / Keras-Yolo-v2

Keras re-implementation of Yolo v2 Object Detection
29 stars 8 forks source link

Changing the batch size and number of labels. #2

Closed jrrios closed 5 years ago

jrrios commented 5 years ago

I am attempting to train a custom model with TinyYOLOv2, however when I replace the batch size and label count on the trainnet = TinyYOLOv2(13 * 32, batch_size, num_classes, is_learning_phase=True) call I get the following error when the model is being created:

  File "/test/yolo2/tiny_yolo_v2.py", line 24, in __init__
    self.m = self.buildModel()
  File "/test/yolo2/tiny_yolo_v2.py", line 50, in buildModel
    )(model)
  File "/test/venv/lib/python3.7/site-packages/keras/engine/base_layer.py", line 474, in __call__
    output_shape = self.compute_output_shape(input_shape)
  File "/test/venv/lib/python3.7/site-packages/keras/layers/core.py", line 398, in compute_output_shape
    input_shape[1:], self.target_shape)
  File "/test/venv/lib/python3.7/site-packages/keras/layers/core.py", line 386, in _fix_unknown_dimension
    raise ValueError(msg)
ValueError: total size of new array must be unchanged

My guess is i would need to change how the Reshape layer is added, what could I change to make it work?

jrrios commented 5 years ago

In order to get past this, I made the following change to https://github.com/guigzzz/Keras-Yolo-v2/blob/master/tiny_yolo_v2.py#L46

model = Conv2D(len(TINY_YOLOV2_ANCHOR_PRIORS)*(5+self.n_classes), (1, 1), padding='same', activation='linear')(model)

guigzzz commented 5 years ago

Good catch! that's what I get for not testing the code with different dimensions :) I'll change the code to add your fix

guigzzz commented 5 years ago

Fixed https://github.com/guigzzz/Keras-Yolo-v2/commit/f61286371cdc2d470e0811234f552c70bbd5caba