Data.transform(预处理) 模块¶
ppsci.data.process.transform
¶
CropData
¶
Crop data class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xmin |
Tuple[int, ...]
|
Bottom left corner point, [x0, y0]. |
required |
xmax |
Tuple[int, ...]
|
Top right corner point, [x1, y1]. |
required |
apply_keys |
Tuple[str, ...]
|
Which data is the crop method applied to. Defaults to ("input", "label"). |
('input', 'label')
|
Examples:
Source code in ppsci/data/process/transform/preprocess.py
FunctionalTransform
¶
Functional data transform class, which allows to use custom data transform function from given transform_func for special cases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transform_func |
Callable
|
Function of data transform. |
required |
Examples:
>>> import ppsci
>>> import numpy as np
>>> def transform_func(data_dict, label_dict, weight_dict):
... rand_ratio = np.random.rand()
... for key in data_dict:
... data_dict[key] = data_dict[key] * rand_ratio
... return data_dict, label_dict, weight_dict
>>> transform_cfg = {
... "transforms": (
... {
... "FunctionalTransform": {
... "transform_func": transform_func,
... },
... },
... ),
... }
Source code in ppsci/data/process/transform/preprocess.py
Log1p
¶
Calculates the natural logarithm of one plus the data, element-wise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale |
float
|
Scale data. Defaults to 1.0. |
1.0
|
apply_keys |
Tuple[str, ...]
|
Which data is the log1p method applied to. Defaults to ("input", "label"). |
('input', 'label')
|
Examples:
Source code in ppsci/data/process/transform/preprocess.py
Normalize
¶
Normalize data class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mean |
Union[ndarray, Tuple[float, ...]]
|
Mean of training dataset. |
required |
std |
Union[ndarray, Tuple[float, ...]]
|
Standard Deviation of training dataset. |
required |
apply_keys |
Tuple[str, ...]
|
Which data is the normalization method applied to. Defaults to ("input", "label"). |
('input', 'label')
|
Examples:
Source code in ppsci/data/process/transform/preprocess.py
Scale
¶
Scale class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale |
Dict[str, float]
|
Scale the input data according to the variable name and coefficient specified in scale. |
required |
Examples:
Source code in ppsci/data/process/transform/preprocess.py
SqueezeData
¶
Squeeze data class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
apply_keys |
Tuple[str, ...]
|
Which data is the squeeze method applied to. Defaults to ("input", "label"). |
('input', 'label')
|
Examples:
Source code in ppsci/data/process/transform/preprocess.py
Translate
¶
Translate class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
Dict[str, float]
|
Shift the input data according to the variable name and coefficient specified in offset. |
required |
Examples:
Source code in ppsci/data/process/transform/preprocess.py
build_transforms(cfg)
¶
Source code in ppsci/data/process/transform/__init__.py
创建日期: November 6, 2023