File size: 641 Bytes
52a9452
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
import torch

from concern.config import Configurable


class TransformData(Configurable):
    '''
    this transformation is inplcae, which means that the input
        will be modified.
    '''
    mean = np.array([0.485, 0.456, 0.406])
    std = np.array([0.229, 0.224, 0.225])

    def __init__(self, **kwargs):
        self.load_all(**kwargs)

    def __call__(self, data_dict, *args, **kwargs):
        image = data_dict['image'].transpose(2, 0, 1)
        image = image / 255.0
        image = (image - self.mean[:, None, None]) / self.std[:, None, None]
        data_dict['image'] = image
        return data_dict