import math
import megengine as mge
import megengine.functional as F
import numpy as np
from megengine import Tensor
import pdb

def restore_bbox(rois, deltas, unnormalize=True, config = None):

    assert deltas.ndim == 3
    if unnormalize:
        std_opr = mge.tensor(config.bbox_normalize_stds.reshape(1, 1, -1))
        mean_opr = mge.tensor(config.bbox_normalize_means.reshape(1, 1, -1))
        deltas = deltas * std_opr
        deltas = deltas + mean_opr

    # n = deltas.shape[1]
    n, c = deltas.shape[0], deltas.shape[1]
    all_rois = F.broadcast_to(
F.expand_dims(rois, 1)