2020-03-27 14:49:12 +08:00
|
|
|
# Copyright 2019 Huawei Technologies Co., Ltd
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
# ==============================================================================
|
2020-06-02 03:03:05 +08:00
|
|
|
"""
|
|
|
|
Testing Normalize op in DE
|
|
|
|
"""
|
2020-05-18 16:42:35 +08:00
|
|
|
import numpy as np
|
2020-03-27 14:49:12 +08:00
|
|
|
import mindspore.dataset as ds
|
2020-08-28 03:30:21 +08:00
|
|
|
import mindspore.dataset.transforms.py_transforms
|
|
|
|
import mindspore.dataset.vision.c_transforms as c_vision
|
|
|
|
import mindspore.dataset.vision.py_transforms as py_vision
|
2020-03-27 14:49:12 +08:00
|
|
|
from mindspore import log as logger
|
2020-06-10 03:12:07 +08:00
|
|
|
from util import diff_mse, save_and_check_md5, visualize_image
|
2020-03-27 14:49:12 +08:00
|
|
|
|
|
|
|
DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"]
|
|
|
|
SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json"
|
|
|
|
|
2020-06-02 03:03:05 +08:00
|
|
|
GENERATE_GOLDEN = False
|
|
|
|
|
|
|
|
|
|
|
|
def normalize_np(image, mean, std):
|
2020-03-27 14:49:12 +08:00
|
|
|
"""
|
2021-04-20 10:37:25 +08:00
|
|
|
Apply the Normalization
|
2020-03-27 14:49:12 +08:00
|
|
|
"""
|
2021-03-11 11:57:24 +08:00
|
|
|
# DE decodes the image in RGB by default, hence
|
2020-03-27 14:49:12 +08:00
|
|
|
# the values here are in RGB
|
|
|
|
image = np.array(image, np.float32)
|
2020-06-02 03:03:05 +08:00
|
|
|
image = image - np.array(mean)
|
|
|
|
image = image * (1.0 / np.array(std))
|
2020-03-27 14:49:12 +08:00
|
|
|
return image
|
|
|
|
|
|
|
|
|
2020-06-02 03:03:05 +08:00
|
|
|
def util_test_normalize(mean, std, op_type):
|
2020-03-27 14:49:12 +08:00
|
|
|
"""
|
2020-06-02 03:03:05 +08:00
|
|
|
Utility function for testing Normalize. Input arguments are given by other tests
|
2020-03-27 14:49:12 +08:00
|
|
|
"""
|
2020-06-02 03:03:05 +08:00
|
|
|
if op_type == "cpp":
|
|
|
|
# define map operations
|
|
|
|
decode_op = c_vision.Decode()
|
|
|
|
normalize_op = c_vision.Normalize(mean, std)
|
|
|
|
# Generate dataset
|
|
|
|
data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
|
2020-09-10 01:23:02 +08:00
|
|
|
data = data.map(operations=decode_op, input_columns=["image"])
|
|
|
|
data = data.map(operations=normalize_op, input_columns=["image"])
|
2020-06-02 03:03:05 +08:00
|
|
|
elif op_type == "python":
|
|
|
|
# define map operations
|
|
|
|
transforms = [
|
|
|
|
py_vision.Decode(),
|
|
|
|
py_vision.ToTensor(),
|
|
|
|
py_vision.Normalize(mean, std)
|
|
|
|
]
|
2020-08-28 03:30:21 +08:00
|
|
|
transform = mindspore.dataset.transforms.py_transforms.Compose(transforms)
|
2020-06-02 03:03:05 +08:00
|
|
|
# Generate dataset
|
|
|
|
data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
|
2020-09-10 01:23:02 +08:00
|
|
|
data = data.map(operations=transform, input_columns=["image"])
|
2020-06-02 03:03:05 +08:00
|
|
|
else:
|
|
|
|
raise ValueError("Wrong parameter value")
|
|
|
|
return data
|
2020-03-27 14:49:12 +08:00
|
|
|
|
2020-06-02 03:03:05 +08:00
|
|
|
|
|
|
|
def util_test_normalize_grayscale(num_output_channels, mean, std):
|
|
|
|
"""
|
|
|
|
Utility function for testing Normalize. Input arguments are given by other tests
|
|
|
|
"""
|
|
|
|
transforms = [
|
|
|
|
py_vision.Decode(),
|
|
|
|
py_vision.Grayscale(num_output_channels),
|
|
|
|
py_vision.ToTensor(),
|
|
|
|
py_vision.Normalize(mean, std)
|
|
|
|
]
|
2020-08-28 03:30:21 +08:00
|
|
|
transform = mindspore.dataset.transforms.py_transforms.Compose(transforms)
|
2020-06-02 03:03:05 +08:00
|
|
|
# Generate dataset
|
|
|
|
data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
|
2020-09-10 01:23:02 +08:00
|
|
|
data = data.map(operations=transform, input_columns=["image"])
|
2020-06-02 03:03:05 +08:00
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
def test_normalize_op_c(plot=False):
|
|
|
|
"""
|
|
|
|
Test Normalize in cpp transformations
|
|
|
|
"""
|
|
|
|
logger.info("Test Normalize in cpp")
|
|
|
|
mean = [121.0, 115.0, 100.0]
|
|
|
|
std = [70.0, 68.0, 71.0]
|
2020-03-27 14:49:12 +08:00
|
|
|
# define map operations
|
2020-06-02 03:03:05 +08:00
|
|
|
decode_op = c_vision.Decode()
|
|
|
|
normalize_op = c_vision.Normalize(mean, std)
|
2020-03-27 14:49:12 +08:00
|
|
|
|
|
|
|
# First dataset
|
|
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
|
2020-09-10 01:23:02 +08:00
|
|
|
data1 = data1.map(operations=decode_op, input_columns=["image"])
|
|
|
|
data1 = data1.map(operations=normalize_op, input_columns=["image"])
|
2020-03-27 14:49:12 +08:00
|
|
|
|
|
|
|
# Second dataset
|
|
|
|
data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
|
2020-09-10 01:23:02 +08:00
|
|
|
data2 = data2.map(operations=decode_op, input_columns=["image"])
|
2020-03-27 14:49:12 +08:00
|
|
|
|
|
|
|
num_iter = 0
|
2020-09-05 10:56:38 +08:00
|
|
|
for item1, item2 in zip(data1.create_dict_iterator(num_epochs=1, output_numpy=True),
|
|
|
|
data2.create_dict_iterator(num_epochs=1, output_numpy=True)):
|
2020-03-27 14:49:12 +08:00
|
|
|
image_de_normalized = item1["image"]
|
2020-06-02 03:03:05 +08:00
|
|
|
image_original = item2["image"]
|
|
|
|
image_np_normalized = normalize_np(image_original, mean, std)
|
|
|
|
mse = diff_mse(image_de_normalized, image_np_normalized)
|
2020-03-27 14:49:12 +08:00
|
|
|
logger.info("image_{}, mse: {}".format(num_iter + 1, mse))
|
|
|
|
assert mse < 0.01
|
2020-06-02 03:03:05 +08:00
|
|
|
if plot:
|
2020-06-10 03:12:07 +08:00
|
|
|
visualize_image(image_original, image_de_normalized, mse, image_np_normalized)
|
2020-06-02 03:03:05 +08:00
|
|
|
num_iter += 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_normalize_op_py(plot=False):
|
|
|
|
"""
|
|
|
|
Test Normalize in python transformations
|
|
|
|
"""
|
|
|
|
logger.info("Test Normalize in python")
|
|
|
|
mean = [0.475, 0.45, 0.392]
|
|
|
|
std = [0.275, 0.267, 0.278]
|
|
|
|
# define map operations
|
|
|
|
transforms = [
|
|
|
|
py_vision.Decode(),
|
|
|
|
py_vision.ToTensor()
|
|
|
|
]
|
2020-08-28 03:30:21 +08:00
|
|
|
transform = mindspore.dataset.transforms.py_transforms.Compose(transforms)
|
2020-06-02 03:03:05 +08:00
|
|
|
normalize_op = py_vision.Normalize(mean, std)
|
|
|
|
|
|
|
|
# First dataset
|
|
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
|
2020-09-10 01:23:02 +08:00
|
|
|
data1 = data1.map(operations=transform, input_columns=["image"])
|
|
|
|
data1 = data1.map(operations=normalize_op, input_columns=["image"])
|
2020-06-02 03:03:05 +08:00
|
|
|
|
|
|
|
# Second dataset
|
|
|
|
data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
|
2020-09-10 01:23:02 +08:00
|
|
|
data2 = data2.map(operations=transform, input_columns=["image"])
|
2020-06-02 03:03:05 +08:00
|
|
|
|
|
|
|
num_iter = 0
|
2020-09-05 10:56:38 +08:00
|
|
|
for item1, item2 in zip(data1.create_dict_iterator(num_epochs=1, output_numpy=True),
|
|
|
|
data2.create_dict_iterator(num_epochs=1, output_numpy=True)):
|
2020-06-02 03:03:05 +08:00
|
|
|
image_de_normalized = (item1["image"].transpose(1, 2, 0) * 255).astype(np.uint8)
|
|
|
|
image_np_normalized = (normalize_np(item2["image"].transpose(1, 2, 0), mean, std) * 255).astype(np.uint8)
|
|
|
|
image_original = (item2["image"].transpose(1, 2, 0) * 255).astype(np.uint8)
|
|
|
|
mse = diff_mse(image_de_normalized, image_np_normalized)
|
|
|
|
logger.info("image_{}, mse: {}".format(num_iter + 1, mse))
|
|
|
|
assert mse < 0.01
|
|
|
|
if plot:
|
2020-06-10 03:12:07 +08:00
|
|
|
visualize_image(image_original, image_de_normalized, mse, image_np_normalized)
|
2020-03-27 14:49:12 +08:00
|
|
|
num_iter += 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_decode_op():
|
2020-06-02 03:03:05 +08:00
|
|
|
"""
|
|
|
|
Test Decode op
|
|
|
|
"""
|
2020-03-27 14:49:12 +08:00
|
|
|
logger.info("Test Decode")
|
|
|
|
|
|
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image", "label"], num_parallel_workers=1,
|
|
|
|
shuffle=False)
|
|
|
|
|
|
|
|
# define map operations
|
2020-06-02 03:03:05 +08:00
|
|
|
decode_op = c_vision.Decode()
|
2020-03-27 14:49:12 +08:00
|
|
|
|
|
|
|
# apply map operations on images
|
2020-09-10 01:23:02 +08:00
|
|
|
data1 = data1.map(operations=decode_op, input_columns=["image"])
|
2020-03-27 14:49:12 +08:00
|
|
|
|
|
|
|
num_iter = 0
|
2020-08-26 07:52:53 +08:00
|
|
|
for item in data1.create_dict_iterator(num_epochs=1):
|
2020-03-27 14:49:12 +08:00
|
|
|
logger.info("Looping inside iterator {}".format(num_iter))
|
2020-05-26 16:17:53 +08:00
|
|
|
_ = item["image"]
|
2020-03-27 14:49:12 +08:00
|
|
|
num_iter += 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_decode_normalize_op():
|
2020-06-02 03:03:05 +08:00
|
|
|
"""
|
|
|
|
Test Decode op followed by Normalize op
|
|
|
|
"""
|
2020-03-27 14:49:12 +08:00
|
|
|
logger.info("Test [Decode, Normalize] in one Map")
|
|
|
|
|
|
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image", "label"], num_parallel_workers=1,
|
|
|
|
shuffle=False)
|
|
|
|
|
|
|
|
# define map operations
|
2020-06-02 03:03:05 +08:00
|
|
|
decode_op = c_vision.Decode()
|
|
|
|
normalize_op = c_vision.Normalize([121.0, 115.0, 100.0], [70.0, 68.0, 71.0])
|
2020-03-27 14:49:12 +08:00
|
|
|
|
|
|
|
# apply map operations on images
|
2020-09-10 01:23:02 +08:00
|
|
|
data1 = data1.map(operations=[decode_op, normalize_op], input_columns=["image"])
|
2020-03-27 14:49:12 +08:00
|
|
|
|
|
|
|
num_iter = 0
|
2020-08-26 07:52:53 +08:00
|
|
|
for item in data1.create_dict_iterator(num_epochs=1):
|
2020-03-27 14:49:12 +08:00
|
|
|
logger.info("Looping inside iterator {}".format(num_iter))
|
2020-05-26 16:17:53 +08:00
|
|
|
_ = item["image"]
|
2020-03-27 14:49:12 +08:00
|
|
|
num_iter += 1
|
|
|
|
|
|
|
|
|
2020-06-02 03:03:05 +08:00
|
|
|
def test_normalize_md5_01():
|
|
|
|
"""
|
|
|
|
Test Normalize with md5 check: valid mean and std
|
|
|
|
expected to pass
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_md5_01")
|
|
|
|
data_c = util_test_normalize([121.0, 115.0, 100.0], [70.0, 68.0, 71.0], "cpp")
|
|
|
|
data_py = util_test_normalize([0.475, 0.45, 0.392], [0.275, 0.267, 0.278], "python")
|
|
|
|
|
|
|
|
# check results with md5 comparison
|
|
|
|
filename1 = "normalize_01_c_result.npz"
|
|
|
|
filename2 = "normalize_01_py_result.npz"
|
|
|
|
save_and_check_md5(data_c, filename1, generate_golden=GENERATE_GOLDEN)
|
|
|
|
save_and_check_md5(data_py, filename2, generate_golden=GENERATE_GOLDEN)
|
|
|
|
|
|
|
|
|
|
|
|
def test_normalize_md5_02():
|
|
|
|
"""
|
|
|
|
Test Normalize with md5 check: len(mean)=len(std)=1 with RGB images
|
|
|
|
expected to pass
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_md5_02")
|
|
|
|
data_py = util_test_normalize([0.475], [0.275], "python")
|
|
|
|
|
|
|
|
# check results with md5 comparison
|
|
|
|
filename2 = "normalize_02_py_result.npz"
|
|
|
|
save_and_check_md5(data_py, filename2, generate_golden=GENERATE_GOLDEN)
|
|
|
|
|
|
|
|
|
|
|
|
def test_normalize_exception_unequal_size_c():
|
|
|
|
"""
|
|
|
|
Test Normalize in c transformation: len(mean) != len(std)
|
|
|
|
expected to raise ValueError
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_exception_unequal_size_c")
|
|
|
|
try:
|
|
|
|
_ = c_vision.Normalize([100, 250, 125], [50, 50, 75, 75])
|
|
|
|
except ValueError as e:
|
|
|
|
logger.info("Got an exception in DE: {}".format(str(e)))
|
2020-11-12 23:44:17 +08:00
|
|
|
assert str(e) == "Length of mean and std must be equal."
|
2020-06-02 03:03:05 +08:00
|
|
|
|
|
|
|
|
2020-12-11 11:51:29 +08:00
|
|
|
def test_normalize_exception_out_of_range_c():
|
|
|
|
"""
|
|
|
|
Test Normalize in c transformation: mean, std out of range
|
|
|
|
expected to raise ValueError
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_exception_out_of_range_c")
|
|
|
|
try:
|
|
|
|
_ = c_vision.Normalize([256, 250, 125], [50, 75, 75])
|
|
|
|
except ValueError as e:
|
|
|
|
logger.info("Got an exception in DE: {}".format(str(e)))
|
|
|
|
assert "not within the required interval" in str(e)
|
|
|
|
try:
|
|
|
|
_ = c_vision.Normalize([255, 250, 125], [0, 75, 75])
|
|
|
|
except ValueError as e:
|
|
|
|
logger.info("Got an exception in DE: {}".format(str(e)))
|
|
|
|
assert "not within the required interval" in str(e)
|
|
|
|
|
|
|
|
|
2020-06-02 03:03:05 +08:00
|
|
|
def test_normalize_exception_unequal_size_py():
|
|
|
|
"""
|
|
|
|
Test Normalize in python transformation: len(mean) != len(std)
|
|
|
|
expected to raise ValueError
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_exception_unequal_size_py")
|
|
|
|
try:
|
|
|
|
_ = py_vision.Normalize([0.50, 0.30, 0.75], [0.18, 0.32, 0.71, 0.72])
|
|
|
|
except ValueError as e:
|
|
|
|
logger.info("Got an exception in DE: {}".format(str(e)))
|
2020-11-12 23:44:17 +08:00
|
|
|
assert str(e) == "Length of mean and std must be equal."
|
2020-06-02 03:03:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_normalize_exception_invalid_size_py():
|
|
|
|
"""
|
|
|
|
Test Normalize in python transformation: len(mean)=len(std)=2
|
|
|
|
expected to raise RuntimeError
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_exception_invalid_size_py")
|
|
|
|
data = util_test_normalize([0.75, 0.25], [0.18, 0.32], "python")
|
|
|
|
try:
|
added python api based on cpp api
1st draft of python iterator
Added Cifar10 and Cifar100 pybind port
Change pybind to use IR for Skip and Manifest
Signed-off-by: alex-yuyue <yue.yu1@huawei.com>
DatasetNode as a base for all IR nodes
namespace change
Fix the namespace issue and make ut tests work
Signed-off-by: alex-yuyue <yue.yu1@huawei.com>
Add VOCDataset
!63 Added RandomDataset
* Added RandomDataset
add imagefolder ir
Pybind switch: CelebA and UT
!61 CLUE example with class definition
* Merge branch 'python-api' of gitee.com:ezphlow/mindspore into clue_class_pybind
* Passing testcases
* Added CLUE, not working
add ManifestDataset IR
Signed-off-by: alex-yuyue <yue.yu1@huawei.com>
Update Coco & VOC & TFReader, Update clang-format, Reorder
datasets_binding
!69 Add Generator and move c_dataset.Iterator to dataset.Iterator
* Add GeneratorDataset to c_dataset
* Add GeneratorDataset to c_dataset
!67 Moving c_datasets and adding sampler wrapper
* Need to add create() method in datasets.py
* migration from c_dataset to dataset part 1
!71 Fix indent error
* Fix indentation error
!72 Fix c_api tests cases
* Fix c_api tests cases
!73 Added CSV Dataset
* Added CSVDataset
pybind switch: Take and CelebA fixes
!75 move c_dataset functionality to datasets
* Fixed existing testcases
* Added working clue and imagefolder
* Added sampler conversion from pybind
* Added sampler creation
!77 Add Python API tree
* Python API tree
add minddataset
TextFileDataset pybind
Rename to skip test_concat.py and test_minddataset_exception.py
!80 Add batch IR to python-api branch, most test cases work
* staging III
* staging, add pybind
Enable more c_api take and CelebA tests; delete util_c_api
!84 Schema changes in datasets.py
* Schema changes
!85 Remove input_indexes from sub-classes
* remove input_index from each subclass
!83 Remove C datasets
* Removed c_dataset package
* Remove c_datasets
!82 pybind switch: shuffle
* pybind switch: shuffle
!86 Add build_vocab
* Add build_vocab
Rebase with upstream/master
_shuffle conflict
BatchNode error
!88 Fix rebase problem
* fix rebase problem
Enable more unit tests; code typo/nit fixes
!91 Fix python vocag hang
* Fix python vocab hang
!89 Added BucketBatchByLength Pybind switch
* Added BucketBatchByLength
Update and enable more tet_c_api_*.py tests
!95 Add BuildSentencePeiceVocab
* - Add BuildSentencePeiceVocab
!96 Fix more tests
* - Fix some tests
- Enable more test_c_api_*
- Add syncwait
!99 pybind switch for device op
* pybind switch for device op
!93 Add getters to python API
* Add getters to python API
!101 Validate tree, error if graph
* - Add sync wait
!103 TFrecord/Random Datasets schema problem
* - TfRecord/Random schem aproblem
!102 Added filter pybind switch
* Added Filter pybind switch
!104 Fix num_samples
* - TfRecord/Random schem aproblem
!105 Fix to_device hang
* Fix to_device hang
!94 Adds Cache support for CLUE dataset
* Added cache for all dataset ops
* format change
* Added CLUE cache support
* Added Cache conversion
Add save pybind
fix compile err
init modify concat_node
!107 Fix some tests cases
* Fix tests cases
Enable and fix more tests
!109 pybind switch for get dataset size
* pybind_get_dataset_size
some check-code fixes for pylint, cpplint and clang-format
!113 Add callback
* revert
* dataset_sz 1 line
* fix typo
* get callback to work
!114 Make Android compile clean
* Make Android Compile Clean
Fix build issues due to rebase
!115 Fix more tests
* Fix tests cases
* !93 Add getters to python API
fix test_profiling.py
!116 fix get dataset size
* fix get dataset size
!117 GetColumnNames pybind switch
* Added GetColumnNames pybind switch
code-check fixes: clangformat, cppcheck, cpplint, pylint
Delete duplicate test_c_api_*.py files; more lint fixes
!121 Fix cpp tests
* Remove extra call to getNext in cpp tests
!122 Fix Schema with Generator
* Fix Schema with Generator
fix some cases of csv & mindrecord
!124 fix tfrecord get_dataset_size and add some UTs
* fix tfrecord get dataset size and add some ut for get_dataset_size
!125 getter separation
* Getter separation
!126 Fix sampler.GetNumSamples
* Fix sampler.GetNumSampler
!127 Assign runtime getter to each get function
* Assign runtime getter to each get function
Fix compile issues
!128 Match master code
* Match master code
!129 Cleanup DeviceOp/save code
* Cleanup ToDevice/Save code
!130 Add cache fix
* Added cache fix for map and image folder
!132 Fix testing team issues
* Pass queue_name from python to C++
* Add Schema.from_json
!131 Fix Cache op issues and delete de_pipeline
* Roll back C++ change
* Removed de_pipeline and passing all cache tests.
* fixed cache tests
!134 Cleanup datasets.py part1
* Cleanup dataset.py part1
!133 Updated validation for SentencePieceVocab.from_dataset
* Added type_check for column names in SentencePieceVocab.from_dataset
Rebase on master 181120 10:20
fix profiling
temporary solution of catching stauts from Node.Build()
!141 ToDevice Termination
* ToDevice termination
pylint fixes
!137 Fix test team issues and add some corresponding tests
* Fix test team issues and add some corresponding tests
!138 TreeGetter changes to use OptPass
* Getter changes to use OptPass (Zirui)
Rebase fix
!143 Fix cpplint issue
* Fix cpplint issue
pylint fixes in updated testcases
!145 Reset exceptions testcase
* reset exception test to master
!146 Fix Check_Pylint Error
* Fix Check_Pylint Error
!147 fix android
* fix android
!148 ToDevice changes
* Add ToDevice to the iterator List for cleanup at exit
!149 Pylint issue
* Add ToDevice to the iterator List for cleanup at exit
!150 Pylint 2
* Add ToDevice to the iterator List for cleanup at exit
!152 ExecutionTree error
* ET destructor error
!153 in getter_pass, only remove callback, without deleting map op
* getter pass no longer removes map
!156 early __del__ of iterator/to_device
* early __del__ of iterator
!155 Address review comments Eric 1
* Added one liner fix to validators.py
* roll back signature fix
* lint fix
* Eric Address comments 2
* C++ lint fix
* Address comments Eric 1
!158 Review rework for dataset bindings - part 1
* Reorder nodes repeat and rename
* Review rework for dataset bindings - part 1
!154 Fixing minor problems in the comments (datasets.py, python_tree_consumer.cc, iterators_bindings.cc, and iterators.py)
* Fixing minor problems in the comments (datasets.py, python_tree_consum…
!157 add replace none
* Add replace_none to datasets.py, address comments in tests
Trying to resolve copy
Override the deepcopy method of deviceop
Create_ir_tree method
Create_ir_tree method 2
Create_ir_tree method 2
del to_device if already exists
del to_device if already exists
cache getters shapes and types
Added yolov3 relaxation, to be rolled back
Get shapes and types together
bypass yolo
NumWorkers for MapOp
revert Yolo
revert Thor
Print more info
Debug code: Update LOG INFO to LOG ERROR
do not remove epochctrl for getter pass
Remove repeat(1)
pritn batch size
add log to tree_consumer and device_queue op
Revert PR 8744
Signed-off-by: alex-yuyue <yue.yu1@huawei.com>
__del__ toDEvice
__del__ toDevice2
!165 add ifndef ENABLE_ANDROID to device queue print
* Add ifndef ENABLE_ANDROID to device queue print
revert some changes
!166 getter: get_data_info
* getter: get_data_info
!168 add back tree print
* revert info to warnning in one log
* add back the missed print tree log
Release GIL in GetDataInfo
2020-07-17 05:34:09 +08:00
|
|
|
_ = data.create_dict_iterator(num_epochs=1).__next__()
|
2020-06-02 03:03:05 +08:00
|
|
|
except RuntimeError as e:
|
|
|
|
logger.info("Got an exception in DE: {}".format(str(e)))
|
|
|
|
assert "Length of mean and std must both be 1 or" in str(e)
|
|
|
|
|
|
|
|
|
|
|
|
def test_normalize_exception_invalid_range_py():
|
|
|
|
"""
|
|
|
|
Test Normalize in python transformation: value is not in range [0,1]
|
|
|
|
expected to raise ValueError
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_exception_invalid_range_py")
|
|
|
|
try:
|
|
|
|
_ = py_vision.Normalize([0.75, 1.25, 0.5], [0.1, 0.18, 1.32])
|
|
|
|
except ValueError as e:
|
|
|
|
logger.info("Got an exception in DE: {}".format(str(e)))
|
2021-03-11 11:57:24 +08:00
|
|
|
assert "Input mean_value is not within the required interval of [0.0, 1.0]." in str(e)
|
2020-06-02 03:03:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_normalize_grayscale_md5_01():
|
|
|
|
"""
|
|
|
|
Test Normalize with md5 check: len(mean)=len(std)=1 with 1 channel grayscale images
|
|
|
|
expected to pass
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_grayscale_md5_01")
|
|
|
|
data = util_test_normalize_grayscale(1, [0.5], [0.175])
|
|
|
|
# check results with md5 comparison
|
|
|
|
filename = "normalize_03_py_result.npz"
|
|
|
|
save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN)
|
|
|
|
|
|
|
|
|
|
|
|
def test_normalize_grayscale_md5_02():
|
|
|
|
"""
|
|
|
|
Test Normalize with md5 check: len(mean)=len(std)=3 with 3 channel grayscale images
|
|
|
|
expected to pass
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_grayscale_md5_02")
|
|
|
|
data = util_test_normalize_grayscale(3, [0.5, 0.5, 0.5], [0.175, 0.235, 0.512])
|
|
|
|
# check results with md5 comparison
|
|
|
|
filename = "normalize_04_py_result.npz"
|
|
|
|
save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN)
|
|
|
|
|
|
|
|
|
|
|
|
def test_normalize_grayscale_exception():
|
|
|
|
"""
|
|
|
|
Test Normalize: len(mean)=len(std)=3 with 1 channel grayscale images
|
|
|
|
expected to raise RuntimeError
|
|
|
|
"""
|
|
|
|
logger.info("test_normalize_grayscale_exception")
|
|
|
|
try:
|
|
|
|
_ = util_test_normalize_grayscale(1, [0.5, 0.5, 0.5], [0.175, 0.235, 0.512])
|
|
|
|
except RuntimeError as e:
|
|
|
|
logger.info("Got an exception in DE: {}".format(str(e)))
|
|
|
|
assert "Input is not within the required range" in str(e)
|
|
|
|
|
|
|
|
|
2021-05-08 00:31:33 +08:00
|
|
|
def test_multiple_channels():
|
|
|
|
logger.info("test_multiple_channels")
|
|
|
|
|
|
|
|
def util_test(item, mean, std):
|
|
|
|
data = ds.NumpySlicesDataset([item], shuffle=False)
|
|
|
|
data = data.map(c_vision.Normalize(mean, std))
|
|
|
|
for d in data.create_tuple_iterator(num_epochs=1, output_numpy=True):
|
|
|
|
actual = d[0]
|
|
|
|
mean = np.array(mean, dtype=item.dtype)
|
|
|
|
std = np.array(std, dtype=item.dtype)
|
|
|
|
expected = item
|
|
|
|
if len(item.shape) != 1 and len(mean) == 1:
|
|
|
|
mean = [mean[0]] * expected.shape[-1]
|
|
|
|
std = [std[0]] * expected.shape[-1]
|
|
|
|
if len(item.shape) == 2:
|
|
|
|
expected = np.expand_dims(expected, 2)
|
|
|
|
for c in range(expected.shape[-1]):
|
|
|
|
expected[:, :, c] = (expected[:, :, c] - mean[c]) / std[c]
|
|
|
|
expected = expected.squeeze()
|
|
|
|
|
|
|
|
np.testing.assert_almost_equal(actual, expected, decimal=6)
|
|
|
|
|
|
|
|
util_test(np.ones(shape=[2, 2, 3]), mean=[0.5, 0.6, 0.7], std=[0.1, 0.2, 0.3])
|
|
|
|
util_test(np.ones(shape=[20, 45, 3]) * 1.3, mean=[0.5, 0.6, 0.7], std=[0.1, 0.2, 0.3])
|
|
|
|
util_test(np.ones(shape=[20, 45, 4]) * 1.3, mean=[0.5, 0.6, 0.7, 0.8], std=[0.1, 0.2, 0.3, 0.4])
|
|
|
|
util_test(np.ones(shape=[2, 2]), mean=[0.5], std=[0.1])
|
|
|
|
util_test(np.ones(shape=[2, 2, 5]), mean=[0.5], std=[0.1])
|
2021-05-19 00:23:11 +08:00
|
|
|
util_test(np.ones(shape=[6, 6, 129]), mean=[0.5]*129, std=[0.1]*129)
|
|
|
|
util_test(np.ones(shape=[6, 6, 129]), mean=[0.5], std=[0.1])
|
|
|
|
|
2021-05-08 00:31:33 +08:00
|
|
|
|
|
|
|
|
2020-03-27 14:49:12 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
test_decode_op()
|
|
|
|
test_decode_normalize_op()
|
2020-06-02 03:03:05 +08:00
|
|
|
test_normalize_op_c(plot=True)
|
|
|
|
test_normalize_op_py(plot=True)
|
|
|
|
test_normalize_md5_01()
|
|
|
|
test_normalize_md5_02()
|
|
|
|
test_normalize_exception_unequal_size_c()
|
|
|
|
test_normalize_exception_unequal_size_py()
|
|
|
|
test_normalize_exception_invalid_size_py()
|
|
|
|
test_normalize_exception_invalid_range_py()
|
|
|
|
test_normalize_grayscale_md5_01()
|
|
|
|
test_normalize_grayscale_md5_02()
|
|
|
|
test_normalize_grayscale_exception()
|