From e13677cbd1e5c2c0075173d447817ef918a8c641 Mon Sep 17 00:00:00 2001 From: Liyulingyue <852433440@qq.com> Date: Sun, 10 Dec 2023 14:35:57 +0800 Subject: [PATCH 1/6] add discribe --- ppsci/data/process/transform/preprocess.py | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/ppsci/data/process/transform/preprocess.py b/ppsci/data/process/transform/preprocess.py index 737d53ad86..a8da6f1ea5 100644 --- a/ppsci/data/process/transform/preprocess.py +++ b/ppsci/data/process/transform/preprocess.py @@ -235,22 +235,27 @@ class FunctionalTransform: transform_func (Callable): Function of data transform. Examples: - >>> import ppsci - >>> import numpy as np + >>> # This is the transform_func function. It takes three dictionaries as input: data_dict, label_dict, and weight_dict. + >>> # The function will perform some transformations on the data in data_dict, convert all labels in label_dict to uppercase, + >>> # and modify the weights in weight_dict by dividing each weight by 10. + >>> # Finally, it returns the transformed data, labels, and weights as a tuple. >>> 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 + ... data_dict[key] = data_dict[key] * 2 + ... for key in label_dict: + ... label_dict[key] = label_dict[key].upper() + ... for key in weight_dict: + ... weight_dict[key] = weight_dict[key] / 10 ... return data_dict, label_dict, weight_dict - >>> transform_cfg = { - ... "transforms": ( - ... { - ... "FunctionalTransform": { - ... "transform_func": transform_func, - ... }, - ... }, - ... ), - ... } + >>> transform = ppsci.data.transform.FunctionalTransform(transform_func) + >>> # Define some sample data, labels, and weights + >>> data = {'feature1': np.array([1, 2, 3]), 'feature2': np.array([4, 5, 6])} + >>> label = {'class': 'class1', 'instance': 'instance1'} + >>> weight = {'weight1': 0.5, 'weight2': 0.5} + >>> # Apply the transform function to the data, labels, and weights using the FunctionalTransform instance + >>> transformed_data = transform(data, label, weight) + >>> print(transformed_data) + ({'feature1': [2, 4, 6], 'feature2': [8, 10, 12]}, {'class': 'CLASS1', 'instance': 'INSTANCE1'}, {'weight1': 0.5, 'weight2': 0.5}) """ def __init__( From 787d4832ef08ea66bede1a61bfabbb7482bfe71f Mon Sep 17 00:00:00 2001 From: Liyulingyue <852433440@qq.com> Date: Sun, 10 Dec 2023 14:45:02 +0800 Subject: [PATCH 2/6] add discribe --- ppsci/data/process/transform/preprocess.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ppsci/data/process/transform/preprocess.py b/ppsci/data/process/transform/preprocess.py index a8da6f1ea5..a152dea444 100644 --- a/ppsci/data/process/transform/preprocess.py +++ b/ppsci/data/process/transform/preprocess.py @@ -117,6 +117,10 @@ class Log1p: Examples: >>> import ppsci >>> log1p = ppsci.data.transform.Log1p(1e-5) + >>> input_item = {"data": np.array([1.0, 2.0, 3.0])} + >>> label_item = {"data": np.array([4.0, 5.0, 6.0])} + >>> weight_item = np.array([0.1, 0.2, 0.3]) + >>> input_item_transformed, label_item_transformed, weight_item_transformed = log1p(input_item, label_item, weight_item) """ def __init__( From 6a0556110c718fcc94257ab88d8c5dcc1a01c5f3 Mon Sep 17 00:00:00 2001 From: Liyulingyue <852433440@qq.com> Date: Sun, 10 Dec 2023 14:48:26 +0800 Subject: [PATCH 3/6] add discribe --- ppsci/data/process/transform/preprocess.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ppsci/data/process/transform/preprocess.py b/ppsci/data/process/transform/preprocess.py index a152dea444..d272fa8587 100644 --- a/ppsci/data/process/transform/preprocess.py +++ b/ppsci/data/process/transform/preprocess.py @@ -79,6 +79,12 @@ class Normalize: Examples: >>> import ppsci >>> normalize = ppsci.data.transform.Normalize((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)) + >>> input_item = {"data": np.array([1.0, 2.0, 3.0])} + >>> label_item = {"data": np.array([4.0, 5.0, 6.0])} + >>> weight_item = np.array([0.1, 0.2, 0.3]) + >>> normalized_item = normalize(input_item, label_item, weight_item) + >>> print(normalized_item) + ({'data': array([1., 2., 3.])}, {'data': array([4., 5., 6.])}, array([0.1, 0.2, 0.3])) """ def __init__( From 3a537293b0f4a69b3c761462562617fe65b10191 Mon Sep 17 00:00:00 2001 From: Liyulingyue <852433440@qq.com> Date: Sun, 10 Dec 2023 15:06:30 +0800 Subject: [PATCH 4/6] add discribe --- ppsci/data/process/transform/preprocess.py | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ppsci/data/process/transform/preprocess.py b/ppsci/data/process/transform/preprocess.py index d272fa8587..555b8a57d8 100644 --- a/ppsci/data/process/transform/preprocess.py +++ b/ppsci/data/process/transform/preprocess.py @@ -31,7 +31,19 @@ class Translate: Examples: >>> import ppsci + >>> import numpy as np >>> translate = ppsci.data.transform.Translate({"x": 1.0, "y": -1.0}) + >>> input_data = np.array([[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]]) + >>> input_dict = {"x": input_data[:,:,0], "y": input_data[:,:,1]} + >>> label_dict = {"x": np.array([1.0, 2.0]), "y": np.array([3.0, 4.0])} + >>> weight_dict = {"x": np.array([10.0, 20.0]), "y": np.array([30.0, 40.0])} + >>> translated_input_dict, translated_label_dict, translated_weight_dict = translate(input_dict, label_dict, weight_dict) + >>> print(translated_input_dict) + {"x": array([[2., 3.], [4., 5.]]), "y": array([[0., 1.], [2., 3.]])} + >>> print(translated_label_dict) + {"x": array([2., 3.]), "y": array([3., 4.])} + >>> print(translated_weight_dict) + {"x": array([10., 20.]), "y": array([30., 40.])} """ def __init__(self, offset: Dict[str, float]): @@ -46,7 +58,7 @@ def __call__(self, input_dict, label_dict, weight_dict): class Scale: - """Scale class. + """Scale class for data transformation. Args: scale (Dict[str, float]): Scale the input data according to the variable name @@ -55,6 +67,10 @@ class Scale: Examples: >>> import ppsci >>> translate = ppsci.data.transform.Scale({"x": 1.5, "y": 2.0}) + >>> input_dict = {"x": 10, "y": 20} + >>> label_dict = {"x": 100, "y": 200} + >>> weight_dict = {"x": 1000, "y": 2000} + >>> input_dict_scaled, label_dict_scaled, weight_dict_scaled = translate(input_dict, label_dict, weight_dict) """ def __init__(self, scale: Dict[str, float]): @@ -204,7 +220,12 @@ class SqueezeData: Examples: >>> import ppsci + >>> import numpy as np >>> squeeze_data = ppsci.data.transform.SqueezeData() + >>> input_data = {"input": np.random.rand(10, 224, 224)} + >>> label_data = {"label": np.random.rand(10, 224, 224)} + >>> weight_data = {"weight": np.random.rand(10, 224, 224)} + >>> input_data_squeezed, label_data_squeezed, weight_data_squeezed = squeeze_data(input_data, label_data, weight_data) """ def __init__(self, apply_keys: Tuple[str, ...] = ("input", "label")): From 208842bf1eeaa6eda5ca05bf7fb88fbd241b13b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Thu, 21 Dec 2023 22:32:58 +0800 Subject: [PATCH 5/6] Update preprocess.py --- ppsci/data/process/transform/preprocess.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ppsci/data/process/transform/preprocess.py b/ppsci/data/process/transform/preprocess.py index 555b8a57d8..4b9b1dfad5 100644 --- a/ppsci/data/process/transform/preprocess.py +++ b/ppsci/data/process/transform/preprocess.py @@ -71,6 +71,12 @@ class Scale: >>> label_dict = {"x": 100, "y": 200} >>> weight_dict = {"x": 1000, "y": 2000} >>> input_dict_scaled, label_dict_scaled, weight_dict_scaled = translate(input_dict, label_dict, weight_dict) + >>> print(input_dict_scaled) + {'x': 15.0, 'y': 40.0} + >>> print(label_dict_scaled) + {'x': 100, 'y': 200} + >>> print(weight_dict_scaled) + {'x': 1000, 'y': 2000} """ def __init__(self, scale: Dict[str, float]): From fc5b05bdb354156e60ca88a4153d6b6ca14627cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Thu, 21 Dec 2023 22:35:37 +0800 Subject: [PATCH 6/6] Update preprocess.py --- ppsci/data/process/transform/preprocess.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ppsci/data/process/transform/preprocess.py b/ppsci/data/process/transform/preprocess.py index 4b9b1dfad5..970148bca7 100644 --- a/ppsci/data/process/transform/preprocess.py +++ b/ppsci/data/process/transform/preprocess.py @@ -149,6 +149,12 @@ class Log1p: >>> label_item = {"data": np.array([4.0, 5.0, 6.0])} >>> weight_item = np.array([0.1, 0.2, 0.3]) >>> input_item_transformed, label_item_transformed, weight_item_transformed = log1p(input_item, label_item, weight_item) + >>> print(input_item_transformed) + {'data': array([11.51293546, 12.20607765, 12.61154109])} + >>> print(label_item_transformed) + {'data': array([12.89922233, 13.12236538, 13.3046866 ])} + >>> print(weight_item_transformed) + [0.1 0.2 0.3] """ def __init__(