def normalize(self, statistics=None):
     # normalize the input-output pairs with optional given statistics
     if statistics is None:
         mean_in, std_in = nop.get_statistics_1d(self.input)
         mean_out, std_out = nop.get_statistics_1d(self.output)
         self.statistics = {
             'mean_in': mean_in,
             'mean_out': mean_out,
             'std_in': std_in,
             'std_out': std_out
         }
     else:
         mean_in, std_in = statistics['mean_in'], statistics['std_in']
         mean_out, std_out = statistics['mean_out'], statistics['std_out']
         self.statistics = statistics
     self.input = nop.normalize_1d(self.input, mean_in, std_in)
     self.output = nop.normalize_1d(self.output, mean_out, std_out)
     return
def lift_2d_to_3d(records, model, stats, template, cuda=True):
    """
    Foward-pass of the lifter model.
    """
    for path in records.keys():
        data = np.concatenate(records[path]['kpts_2d_pred'], axis=0)
        data = nop.normalize_1d(data, stats['mean_in'], stats['std_in'])
        data = data.astype(np.float32)
        data = torch.from_numpy(data)
        if cuda:
            data = data.cuda()
        prediction = model(data)
        prediction = nop.unnormalize_1d(prediction.data.cpu().numpy(),
                                        stats['mean_out'], stats['std_out'])
        records[path]['kpts_3d_pred'] = prediction.reshape(
            len(prediction), -1, 3)
    return records