nn/nn_utils.py
def pad_prediction(image, prediction):
    """
    Pad prediction map if necessary, this is useful when network has smaller outputs than input images
    :param image: input rgb image
    :param prediction: network prediction map
    :return:
    """
    _, img_w, img_h, _ = image.shape
    n, pred_img_w, pred_img_h, c = prediction.shape

    if img_w > pred_img_w and img_h > pred_img_h:
        pad_w = int((img_w - pred_img_w) / 2)
        pad_h = int((img_h - pred_img_h) / 2)
        prediction_padded = np.zeros((n, img_w, img_h, c))
        pad_dim = ((pad_w, pad_w),
                   (pad_h, pad_h))

        for batch_id in range(n):
            for channel_id in range(c):
                prediction_padded[batch_id, :, :, channel_id] = \
                    np.pad(prediction[batch_id, :, :, channel_id], pad_dim, 'constant')
        prediction = prediction_padded
        return prediction
    else:
        return prediction

    Pad prediction map if necessary, this is useful when network has smaller outputs than input images
    :param image: input rgb image
    :param prediction: network prediction map
    :return:
    
Pad prediction map if necessary, this is useful when network has smaller outputs than input images
Pad prediction map if necessary this is useful when network has smaller outputs than input images
def pad_prediction(image, prediction):
    _, img_w, img_h, _ = image.shape
    n, pred_img_w, pred_img_h, c = prediction.shape
    if img_w > pred_img_w and img_h > pred_img_h:
        pad_w = int((img_w - pred_img_w) / 2)
        pad_h = int((img_h - pred_img_h) / 2)
        prediction_padded = np.zeros((n, img_w, img_h, c))
        pad_dim = ((pad_w, pad_w),
                   (pad_h, pad_h))
        for batch_id in range(n):
            for channel_id in range(c):
                prediction_padded[batch_id, :, :, channel_id] = \
                    np.pad(prediction[batch_id, :, :, channel_id], pad_dim, 'constant')
        prediction = prediction_padded
        return prediction
    else:
        return prediction
def pad_prediction ( image , prediction ) : _ , img_w , img_h , _ = image . shape n , pred_img_w , pred_img_h , c = prediction . shape if img_w > pred_img_w and img_h > pred_img_h : pad_w = int ( ( img_w - pred_img_w ) / 2 ) pad_h = int ( ( img_h - pred_img_h ) / 2 ) prediction_padded = np . zeros ( ( n , img_w , img_h , c ) ) pad_dim = ( ( pad_w , pad_w ) , ( pad_h , pad_h ) ) for batch_id in range ( n ) : for channel_id in range ( c ) : prediction_padded [ batch_id , : , : , channel_id ] = np . pad ( prediction [ batch_id , : , : , channel_id ] , pad_dim , 'constant' ) prediction = prediction_padded return prediction else : return prediction
Pad prediction map if necessary, this is useful when network has smaller outputs than input images
Pad prediction map if necessary this is useful when network has smaller outputs than input images
"""
    Pad prediction map if necessary, this is useful when network has smaller outputs than input images
    :param image: input rgb image
    :param prediction: network prediction map
    :return:
    """
None
image
input rgb image
input rgb image
prediction
network prediction map
network prediction map