이미지를 텐서로 변환하기 위한 클래스
args:
keys (list[str]): 입력 데이터(dict)에서 이미지에 해당하는 키
Definition at line 52 of file formatting.py.
◆ __init__()
| formatting.ImageToTensor.__init__ |
( |
| self, |
|
|
| keys ) |
Definition at line 58 of file formatting.py.
58 def __init__(self, keys):
59 self.keys = keys
60
◆ transform()
| dict formatting.ImageToTensor.transform |
( |
| self, |
|
|
| sample ) |
입력 데이터의 이미지를 텐서로 변환하는 기능
args:
sample (dict): 데이터
return: 텐서로 변환된 이미지가 포함된 데이터
Definition at line 61 of file formatting.py.
61 def transform(self, sample) -> dict:
62 """
63 입력 데이터의 이미지를 텐서로 변환하는 기능
64 args:
65 sample (dict): 데이터
66 return: 텐서로 변환된 이미지가 포함된 데이터
67 """
68
69 for key in keys:
70 assert key in sample, \
71 f'ImageToTensor : not found key in sample : {key}'
72
73
74 for key in self.keys:
75 img = sample[key]
76 if len(img.shape) < 3:
77 img = np.expand_dims(img, -1)
78
79
80 sample[key] = (ToTensor.to_tensor(img.transpose(2, 0, 1))).contiguous()
81
82 return sample
83
◆ keys
| formatting.ImageToTensor.keys |
The documentation for this class was generated from the following file: