Skip to content

Commit 03783f2

Browse files
committed
add test_data_pipeline dynmic test. test=develop
1 parent a01f870 commit 03783f2

File tree

4 files changed

+99
-5
lines changed

4 files changed

+99
-5
lines changed

python/paddle/fluid/dataloader/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def flip_normalize(image):
116116
117117
"""
118118
if _non_static_mode():
119-
return map_func(inputs)
119+
return map_func(*args, **kwargs)
120120

121121
helper = LayerHelper("map", **locals())
122122

python/paddle/tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ foreach(TEST_OP ${DIST_TEST_OPS})
99
endforeach()
1010

1111
if (WIN32)
12-
LIST(REMOVE_ITEM TEST_OPS test_data_pipeline)
12+
LIST(REMOVE_ITEM TEST_OPS test_data_pipeline_static)
13+
LIST(REMOVE_ITEM TEST_OPS test_data_pipeline_dynamic)
1314
LIST(REMOVE_ITEM TEST_OPS test_ops_file_label_loader)
1415
LIST(REMOVE_ITEM TEST_OPS test_ops_decode)
1516
LIST(REMOVE_ITEM TEST_OPS test_ops_crop_resize)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import cv2
17+
import unittest
18+
import numpy as np
19+
20+
import paddle
21+
import paddle.fluid as fluid
22+
import paddle.fluid.core as core
23+
from paddle.utils.download import get_path_from_url
24+
from paddle.vision.datasets import DatasetFolder
25+
from paddle.vision.ops import image_decode_random_crop, image_resize, \
26+
random_flip, mirror_normalize
27+
from paddle.vision.reader import file_label_reader
28+
29+
import test_data_pipeline_static
30+
from test_data_pipeline_static import DATASET_HOME, DATASET_URL, \
31+
DATASET_MD5, IMAGE_NUM
32+
33+
DATASET_HOME = os.path.expanduser("~/.cache/paddle/datasets")
34+
DATASET_URL = "https://paddlemodels.cdn.bcebos.com/ImageNet_stub.tar"
35+
DATASET_MD5 = "c7110519124a433901cf005a4a91b607"
36+
IMAGE_NUM = 100
37+
38+
39+
class TestDataPipelineDynamicCase1(
40+
test_data_pipeline_static.TestDataPipelineStaticCase1):
41+
def test_output(self):
42+
# NOTE: only supoort CUDA kernel currently
43+
if not core.is_compiled_with_cuda():
44+
return
45+
46+
data = self.reader()
47+
48+
image = data['image'].numpy()
49+
assert image.shape[0] == self.batch_size
50+
assert image.shape[1] == 3
51+
assert image.shape[2] == self.target_size
52+
assert image.shape[3] == self.target_size
53+
assert image.dtype == np.float32
54+
55+
restore_image = image * self.std_np + self.mean_np
56+
assert np.all(restore_image > -1.)
57+
assert np.all(restore_image < 256.)
58+
59+
label = data['label'].numpy()
60+
assert label.shape[0] == self.batch_size
61+
assert label.dtype == np.int64
62+
assert np.all(label >= 0)
63+
assert np.all(label <= 1)
64+
65+
66+
class TestDataPipelineDynamicCase2(TestDataPipelineDynamicCase1):
67+
def setUp(self):
68+
self.data_root = get_path_from_url(DATASET_URL, DATASET_HOME,
69+
DATASET_MD5)
70+
71+
self.num_epoches = 1
72+
self.batch_size = 16
73+
self.num_threads = 4
74+
self.host_memory_padding = 0
75+
self.device_memory_padding = 0
76+
77+
self.shuffle = True
78+
self.drop_last = True
79+
self.calc_iter_info()
80+
81+
self.target_size = 128
82+
self.flip_prob = 0.5
83+
self.mean = [123.675, 116.28, 103.53]
84+
self.std = [58.395, 57.120, 57.375]
85+
86+
self.mean_np = np.array(self.mean).reshape([1, 3, 1, 1])
87+
self.std_np = np.array(self.std).reshape([1, 3, 1, 1])
88+
89+
self.build_reader()
90+
91+
92+
if __name__ == '__main__':
93+
unittest.main()

python/paddle/tests/test_data_pipeline.py renamed to python/paddle/tests/test_data_pipeline_static.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
IMAGE_NUM = 100
3333

3434

35-
class TestDataPipelineCase1(unittest.TestCase):
35+
class TestDataPipelineStaticCase1(unittest.TestCase):
3636
def setUp(self):
3737
self.data_root = get_path_from_url(DATASET_URL, DATASET_HOME,
3838
DATASET_MD5)
@@ -102,7 +102,7 @@ def flip_normalize(image):
102102

103103
self.reader = imagenet_reader
104104

105-
def test_static_output(self):
105+
def test_output(self):
106106
# NOTE: only supoort CUDA kernel currently
107107
if not core.is_compiled_with_cuda():
108108
return
@@ -136,7 +136,7 @@ def test_static_output(self):
136136
loader.reset()
137137

138138

139-
class TestDataPipelineCase2(TestDataPipelineCase1):
139+
class TestDataPipelineStaticCase2(TestDataPipelineStaticCase1):
140140
def setUp(self):
141141
self.data_root = get_path_from_url(DATASET_URL, DATASET_HOME,
142142
DATASET_MD5)

0 commit comments

Comments
 (0)