keras-yolo2 icon indicating copy to clipboard operation
keras-yolo2 copied to clipboard

Bugs if grid size differ, ex. if image is not square

Open exipilis opened this issue 6 years ago • 3 comments

This code fails if you try setting grid_w and grid_h with different values, for example, you decided to use Yolo for images which are not square:

cell_x = tf.to_float(tf.reshape(tf.tile(tf.range(self.grid_w), [self.grid_h]), (1, self.grid_h, self.grid_w, 1, 1)))
cell_y = tf.transpose(cell_x, (0,2,1,3,4))
cell_grid = tf.tile(tf.concat([cell_x,cell_y], -1), [self.batch_size, 1, 1, self.nb_box, 1])

https://github.com/experiencor/keras-yolo2/blob/master/frontend.py#L92

ValueError: Dimension 1 in both shapes must be equal, but are 13 and 23 for 'loss/reshape_1_loss/concat' (op: 'ConcatV2') with input shapes: [1,13,23,1,1], [1,23,13,1,1], [] and with computed input tensors: input[2] = <-1>.

exipilis avatar Apr 13 '18 16:04 exipilis

You should change that part of code in this way:

cell_x = tf.to_float(tf.reshape(tf.tile(tf.range(GRID_W), [GRID_H]), (1, GRID_H, GRID_W, 1, 1)))
cell_y = tf.to_float(tf.reshape(tf.tile(tf.range(GRID_H), [GRID_W]), (1, GRID_W, GRID_H, 1, 1)))
cell_y = tf.transpose(cell_y, (0,2,1,3,4))

cell_grid = tf.tile(tf.concat([cell_x,cell_y], -1), [BATCH_SIZE, 1, 1, BOX, 1])

So we get a grid where every cell keeps cell's coordinates. It will work with squaresd grid too

evgevd avatar Jul 26 '18 03:07 evgevd

it is working in my repo, you can check it here. I did something very similiar from what @evgevd said

rodrigo2019 avatar Jul 26 '18 04:07 rodrigo2019

Nope @rodrigo2019 still the same error with your fork

fenilsuchak avatar Feb 02 '19 14:02 fenilsuchak