keras-yolo2
keras-yolo2 copied to clipboard
questions on custom_loss
In frontend.py, could anyone explain a bit for this two line in function custom_loss()?
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])
why to transpose and why to concat this two?
I think this is a mistake, since when the input image isn't square (W != H) then this code crashes. I changed these lines to:
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_W), [GRID_H]), (1, GRID_H, GRID_W, 1, 1)))
cell_grid = tf.tile(tf.concat([cell_x,cell_y], -1), [BATCH_SIZE, 1, 1, 5, 1])
and it worked.
Moreover, make sure to fix the cv2.resize inputs in "aug_image" method in "BatchGenerator" class.
should be
image = cv2.resize(image, (self.config['IMAGE_W'], self.config['IMAGE_H']))
instead of
image = cv2.resize(image, (self.config['IMAGE_H'], self.config['IMAGE_W']))
I've opened a PR for that
Dear @Golbstein , As I understood, according to original code cell_x and cell_y are the different (cell_y is transposed of cell_x)
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))
But according to your code, cell_x and cell_y are the same
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_W), [GRID_H]), (1, GRID_H, GRID_W, 1, 1)))
cell_grid = tf.tile(tf.concat([cell_x,cell_y], -1), [BATCH_SIZE, 1, 1, 5, 1])
Is that right? And does it have any side effect? Thank you so much!
Same issue, looking forward to further solution.