@@ -71,6 +71,8 @@ def __call__(self, input_dict, label_dict, weight_dict):
71
71
class Normalize :
72
72
"""Normalize data class.
73
73
74
+ NOTE: This transform will modify the input data dict inplace.
75
+
74
76
Args:
75
77
mean (Union[np.ndarray, Tuple[float, ...]]): Mean of training dataset.
76
78
std (Union[np.ndarray, Tuple[float, ...]]): Standard Deviation of training dataset.
@@ -96,20 +98,20 @@ def __init__(
96
98
self .apply_keys = apply_keys
97
99
98
100
def __call__ (self , input_item , label_item , weight_item ):
99
- input_item_copy = {** input_item }
100
- label_item_copy = {** label_item }
101
101
if "input" in self .apply_keys :
102
- for key , value in input_item_copy .items ():
103
- input_item_copy [key ] = (value - self .mean ) / self .std
102
+ for key , value in input_item .items ():
103
+ input_item [key ] = (value - self .mean ) / self .std
104
104
if "label" in self .apply_keys :
105
- for key , value in label_item_copy .items ():
106
- label_item_copy [key ] = (value - self .mean ) / self .std
107
- return input_item_copy , label_item_copy , weight_item
105
+ for key , value in label_item .items ():
106
+ label_item [key ] = (value - self .mean ) / self .std
107
+ return input_item , label_item , weight_item
108
108
109
109
110
110
class Log1p :
111
111
"""Calculates the natural logarithm of one plus the data, element-wise.
112
112
113
+ NOTE: This transform will modify the input data dict inplace.
114
+
113
115
Args:
114
116
scale (float, optional): Scale data. Defaults to 1.0.
115
117
apply_keys (Tuple[str, ...], optional): Which data is the log1p method applied to. Defaults to ("input", "label").
@@ -132,22 +134,22 @@ def __init__(
132
134
self .apply_keys = apply_keys
133
135
134
136
def __call__ (self , input_item , label_item , weight_item ):
135
- input_item_copy = {** input_item }
136
- label_item_copy = {** label_item }
137
137
if "input" in self .apply_keys :
138
- for key , value in input_item_copy .items ():
139
- input_item_copy [key ] = np .log1p (value / self .scale )
138
+ for key , value in input_item .items ():
139
+ input_item [key ] = np .log1p (value / self .scale )
140
140
if "label" in self .apply_keys :
141
- for key , value in label_item_copy .items ():
142
- label_item_copy [key ] = np .log1p (value / self .scale )
143
- return input_item_copy , label_item_copy , weight_item
141
+ for key , value in label_item .items ():
142
+ label_item [key ] = np .log1p (value / self .scale )
143
+ return input_item , label_item , weight_item
144
144
145
145
146
146
class CropData :
147
147
"""Crop data class.
148
148
149
149
This class is used to crop data based on a specified bounding box.
150
150
151
+ NOTE: This transform will modify the input data dict inplace.
152
+
151
153
Args:
152
154
xmin (Tuple[int, ...]): Bottom left corner point, [x0, y0].
153
155
xmax (Tuple[int, ...]): Top right corner point, [x1, y1].
@@ -182,24 +184,24 @@ def __init__(
182
184
self .apply_keys = apply_keys
183
185
184
186
def __call__ (self , input_item , label_item , weight_item ):
185
- input_item_copy = {** input_item }
186
- label_item_copy = {** label_item }
187
187
if "input" in self .apply_keys :
188
- for key , value in input_item_copy .items ():
189
- input_item_copy [key ] = value [
188
+ for key , value in input_item .items ():
189
+ input_item [key ] = value [
190
190
:, self .xmin [0 ] : self .xmax [0 ], self .xmin [1 ] : self .xmax [1 ]
191
191
]
192
192
if "label" in self .apply_keys :
193
- for key , value in label_item_copy .items ():
194
- label_item_copy [key ] = value [
193
+ for key , value in label_item .items ():
194
+ label_item [key ] = value [
195
195
:, self .xmin [0 ] : self .xmax [0 ], self .xmin [1 ] : self .xmax [1 ]
196
196
]
197
- return input_item_copy , label_item_copy , weight_item
197
+ return input_item , label_item , weight_item
198
198
199
199
200
200
class SqueezeData :
201
201
"""Squeeze data class.
202
202
203
+ NOTE: This transform will modify the input data dict inplace.
204
+
203
205
Args:
204
206
apply_keys (Tuple[str, ...], optional): Which data is the squeeze method applied to. Defaults to ("input", "label").
205
207
@@ -216,27 +218,25 @@ def __init__(self, apply_keys: Tuple[str, ...] = ("input", "label")):
216
218
self .apply_keys = apply_keys
217
219
218
220
def __call__ (self , input_item , label_item , weight_item ):
219
- input_item_copy = {** input_item }
220
- label_item_copy = {** label_item }
221
221
if "input" in self .apply_keys :
222
- for key , value in input_item_copy .items ():
222
+ for key , value in input_item .items ():
223
223
if value .ndim == 4 :
224
224
B , C , H , W = value .shape
225
- input_item_copy [key ] = value .reshape ((B * C , H , W ))
225
+ input_item [key ] = value .reshape ((B * C , H , W ))
226
226
if value .ndim != 3 :
227
227
raise ValueError (
228
228
f"Only support squeeze data to ndim=3 now, but got ndim={ value .ndim } "
229
229
)
230
230
if "label" in self .apply_keys :
231
- for key , value in label_item_copy .items ():
231
+ for key , value in label_item .items ():
232
232
if value .ndim == 4 :
233
233
B , C , H , W = value .shape
234
- label_item_copy [key ] = value .reshape ((B * C , H , W ))
234
+ label_item [key ] = value .reshape ((B * C , H , W ))
235
235
if value .ndim != 3 :
236
236
raise ValueError (
237
237
f"Only support squeeze data to ndim=3 now, but got ndim={ value .ndim } "
238
238
)
239
- return input_item_copy , label_item_copy , weight_item
239
+ return input_item , label_item , weight_item
240
240
241
241
242
242
class FunctionalTransform :
0 commit comments