def adjust_scale_prediction(y_pred, cell_grid, ANCHORS): """ Adjust prediction == input == y_pred : takes any real values tensor of shape = (N batch, NGrid h, NGrid w, NAnchor, 4 + 1 + N class) ANCHORS : list containing width and height specializaiton of anchor box == output == pred_box_xy : shape = (N batch, N grid x, N grid y, N anchor, 2), contianing [center_y, center_x] rangining [0,0]x[grid_H-1,grid_W-1] pred_box_xy[irow,igrid_h,igrid_w,ianchor,0] = center_x pred_box_xy[irow,igrid_h,igrid_w,ianchor,1] = center_1 calculation process: tf.sigmoid(y_pred[...,:2]) : takes values between 0 and 1 tf.sigmoid(y_pred[...,:2]) + cell_grid : takes values between 0 and grid_W - 1 for x coordinate takes values between 0 and grid_H - 1 for y coordinate pred_Box_wh : shape = (N batch, N grid h, N grid w, N anchor, 2), containing width and height, rangining [0,0]x[grid_H-1,grid_W-1] pred_box_conf : shape = (N batch, N grid h, N grid w, N anchor, 1), containing confidence to range between 0 and 1 pred_box_class : shape = (N batch, N grid h, N grid w, N anchor, N class), containing """ BOX = int(len(ANCHORS)/2) ## cell_grid is of the shape of ### adjust x and y # the bounding box bx and by are rescaled to range between 0 and 1 for given gird. # Since there are BOX x BOX grids, we rescale each bx and by to range between 0 to BOX + 1 pred_box_xy = tf.sigmoid(y_pred[..., :2]) + cell_grid # bx, by ### adjust w and h # exp to make width and height positive # rescale each grid to make some anchor "good" at representing certain shape of bounding box pred_box_wh = tf.exp(y_pred[..., 2:4]) * np.reshape(ANCHORS,[1,1,1,BOX,2]) # bw, bh ### adjust confidence pred_box_conf = tf.sigmoid(y_pred[..., 4])# prob bb ### adjust class probabilities pred_box_class = y_pred[..., 5:] # prC1, prC2, ..., prC20 return(pred_box_xy,pred_box_wh,pred_box_conf,pred_box_class)