Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
formatting.ImageToTensor Class Reference
Inheritance diagram for formatting.ImageToTensor:

Public Member Functions

 __init__ (self, keys)
 
dict transform (self, sample)
 

Public Attributes

 keys
 

Detailed Description

이미지를 텐서로 변환하기 위한 클래스
args:
    keys (list[str]): 입력 데이터(dict)에서 이미지에 해당하는 키

Definition at line 52 of file formatting.py.

Constructor & Destructor Documentation

◆ __init__()

formatting.ImageToTensor.__init__ ( self,
keys )

Definition at line 58 of file formatting.py.

58 def __init__(self, keys):
59 self.keys = keys
60

Member Function Documentation

◆ 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: #이미지가 2차원일 경우(흑백)
77 img = np.expand_dims(img, -1) #끝에 한차원 늘려줘서 차원을 맞춰줌, (H, W, C(1))
78
79 #텐서 변환 및 인덱스 구조 변경, H, W, C -> C, H, W
80 sample[key] = (ToTensor.to_tensor(img.transpose(2, 0, 1))).contiguous()
81
82 return sample
83

Member Data Documentation

◆ keys

formatting.ImageToTensor.keys

Definition at line 59 of file formatting.py.


The documentation for this class was generated from the following file: