[ME] Bug fix

pull/7379/head
chenzomi 5 years ago
parent 1ac9196587
commit 5b769dfb20

@ -451,7 +451,8 @@ class CentralCrop(Cell):
def __init__(self, central_fraction): def __init__(self, central_fraction):
super(CentralCrop, self).__init__() super(CentralCrop, self).__init__()
validator.check_value_type("central_fraction", central_fraction, [float], self.cls_name) validator.check_value_type("central_fraction", central_fraction, [float], self.cls_name)
self.central_fraction = validator.check_float_range(0.0, 1.0, Rel.INC_RIGHT, 'central_fraction', central_fraction, self.cls_name) self.central_fraction = validator.check_float_range(central_fraction, 0.0, 1.0, Rel.INC_RIGHT,
'central_fraction', self.cls_name)
self.slice = P.Slice() self.slice = P.Slice()
def construct(self, image): def construct(self, image):

@ -16,7 +16,7 @@
import math import math
import os import os
from mindspore._checkparam import Validator, check_int from mindspore._checkparam import Validator
from .. import context, nn from .. import context, nn
from ._utils import _exec_datagraph, _get_types_and_shapes, _construct_tensor_list from ._utils import _exec_datagraph, _get_types_and_shapes, _construct_tensor_list
from ..nn.wrap import GetNextSingleOp from ..nn.wrap import GetNextSingleOp
@ -124,7 +124,7 @@ class DatasetHelper:
def __init__(self, dataset, dataset_sink_mode=True, sink_size=-1, epoch_num=1): def __init__(self, dataset, dataset_sink_mode=True, sink_size=-1, epoch_num=1):
dataset_sink_mode = Validator.check_bool(dataset_sink_mode) dataset_sink_mode = Validator.check_bool(dataset_sink_mode)
check_int(sink_size) Validator.check_is_int(sink_size)
if sink_size < -1 or sink_size == 0: if sink_size < -1 or sink_size == 0:
raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size)) raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size))

@ -22,7 +22,7 @@ import numpy as np
from mindspore import log as logger from mindspore import log as logger
from ..common.tensor import Tensor from ..common.tensor import Tensor
from ..nn.metrics import get_metrics from ..nn.metrics import get_metrics
from .._checkparam import check_input_data, check_output_data, Validator, check_int from .._checkparam import check_input_data, check_output_data, Validator
from .callback import _InternalCallbackParam, RunContext, _CallbackManager from .callback import _InternalCallbackParam, RunContext, _CallbackManager
from .. import context from .. import context
from ..parallel._utils import _get_parallel_mode, _get_device_num, _get_global_rank, \ from ..parallel._utils import _get_parallel_mode, _get_device_num, _get_global_rank, \
@ -551,7 +551,7 @@ class Model:
dataset_sink_mode = Validator.check_bool(dataset_sink_mode) dataset_sink_mode = Validator.check_bool(dataset_sink_mode)
if sink_size == -1: if sink_size == -1:
sink_size = train_dataset.get_dataset_size() sink_size = train_dataset.get_dataset_size()
check_int(sink_size) Validator.check_is_int(sink_size)
if sink_size < -1 or sink_size == 0: if sink_size < -1 or sink_size == 0:
raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size)) raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size))

@ -15,7 +15,7 @@
"""Dataset help for minddata dataset""" """Dataset help for minddata dataset"""
import math import math
import os import os
from mindspore._checkparam import Validator, check_int from mindspore._checkparam import Validator
from mindspore import context from mindspore import context
from mindspore.train._utils import _exec_datagraph, _get_types_and_shapes from mindspore.train._utils import _exec_datagraph, _get_types_and_shapes
from mindspore.nn.wrap import GetNextSingleOp from mindspore.nn.wrap import GetNextSingleOp
@ -62,7 +62,7 @@ class DatasetHelper:
def __init__(self, dataset, dataset_sink_mode=True, sink_size=-1, epoch_num=1, iter_first_order=1): def __init__(self, dataset, dataset_sink_mode=True, sink_size=-1, epoch_num=1, iter_first_order=1):
dataset_sink_mode = Validator.check_bool(dataset_sink_mode) dataset_sink_mode = Validator.check_bool(dataset_sink_mode)
check_int(sink_size) Validator.check_is_int(sink_size)
if sink_size < -1 or sink_size == 0: if sink_size < -1 or sink_size == 0:
raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size)) raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size))

@ -16,7 +16,7 @@
import os import os
from mindspore import context from mindspore import context
from mindspore._checkparam import Validator, check_int from mindspore._checkparam import Validator
from mindspore.parallel._utils import _get_device_num, _need_to_full, _to_full_shapes from mindspore.parallel._utils import _get_device_num, _need_to_full, _to_full_shapes
from mindspore.train._utils import _exec_datagraph, _get_types_and_shapes from mindspore.train._utils import _exec_datagraph, _get_types_and_shapes
@ -59,7 +59,7 @@ class DatasetHelper:
def __init__(self, dataset, dataset_sink_mode=True, sink_size=-1, epoch_num=1, iter_first_order=0): def __init__(self, dataset, dataset_sink_mode=True, sink_size=-1, epoch_num=1, iter_first_order=0):
dataset_sink_mode = Validator.check_bool(dataset_sink_mode) dataset_sink_mode = Validator.check_bool(dataset_sink_mode)
check_int(sink_size) Validator.check_is_int(sink_size)
if sink_size < -1 or sink_size == 0: if sink_size < -1 or sink_size == 0:
raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size)) raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size))

@ -22,7 +22,7 @@ from mindspore._c_expression import init_exec_dataset
from mindspore import context from mindspore import context
from mindspore import log as logger from mindspore import log as logger
from mindspore import nn from mindspore import nn
from mindspore._checkparam import check_input_data, check_output_data, Validator, check_int from mindspore._checkparam import check_input_data, check_output_data, Validator
from mindspore.common import dtype as mstype from mindspore.common import dtype as mstype
from mindspore.common.dtype import pytype_to_dtype from mindspore.common.dtype import pytype_to_dtype
from mindspore.common.tensor import Tensor from mindspore.common.tensor import Tensor
@ -604,7 +604,7 @@ class Model:
>>> model.train(2, dataset) >>> model.train(2, dataset)
""" """
dataset_sink_mode = Validator.check_bool(dataset_sink_mode) dataset_sink_mode = Validator.check_bool(dataset_sink_mode)
check_int(sink_size) Validator.check_is_int(sink_size)
if sink_size < -1 or sink_size == 0: if sink_size < -1 or sink_size == 0:
raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size)) raise ValueError("The sink_size must be -1 or positive, but got sink_size {}.".format(sink_size))

@ -1,50 +0,0 @@
# Copyright 2020 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.
# ============================================================================
"""Component that Check if the function raises the expected Exception."""
import sys
import pytest
from ...components.icomponent import IExectorComponent
from ...utils import keyword
class CheckExceptionsEC(IExectorComponent):
"""
Check if the function raises the expected Exception and the error message contains specified keywords if not None.
Examples:
{
'block': f,
'exception': Exception,
'error_keywords': ['TensorAdd', 'shape']
}
"""
def __call__(self):
f = self.function[keyword.block]
args = self.inputs[keyword.desc_inputs]
e = self.function.get(keyword.exception, Exception)
error_kws = self.function.get(keyword.error_keywords, None)
try:
with pytest.raises(e) as exec_info:
f(*args)
except:
raise Exception(f"Expect {e}, but got {sys.exc_info()[0]}")
if error_kws and any(keyword not in str(exec_info.value) for keyword in error_kws):
raise ValueError('Error message `{}` does not contain all keywords `{}`'.format(
str(exec_info.value), error_kws))

@ -15,7 +15,6 @@
"""Pipelines for forward computing.""" """Pipelines for forward computing."""
from ...components.executor.check_exceptions import CheckExceptionsEC
from ...components.executor.exec_forward import IdentityEC from ...components.executor.exec_forward import IdentityEC
from ...components.facade.me_facade import MeFacadeFC from ...components.facade.me_facade import MeFacadeFC
from ...components.function.compile_block import CompileBlockBC from ...components.function.compile_block import CompileBlockBC
@ -61,4 +60,4 @@ pipeline_for_compile_forward_ge_graph_for_case_by_case_config = [MeFacadeFC, Gen
IdCartesianProductFIPC, IdentityEC] IdCartesianProductFIPC, IdentityEC]
pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception = [MeFacadeFC, GenerateFromShapeDC, RunBlockBC, pipeline_for_compile_forward_ge_graph_for_case_by_case_config_exception = [MeFacadeFC, GenerateFromShapeDC, RunBlockBC,
IdCartesianProductFIPC, CheckExceptionsEC] IdCartesianProductFIPC]

@ -15,7 +15,6 @@
"""Pipelines for exception checking.""" """Pipelines for exception checking."""
from ...components.executor.check_exceptions import CheckExceptionsEC
from ...components.facade.me_facade import MeFacadeFC from ...components.facade.me_facade import MeFacadeFC
from ...components.function.get_function_from_config import IdentityBC from ...components.function.get_function_from_config import IdentityBC
from ...components.function_inputs_policy.cartesian_product_on_id_for_function_inputs import IdCartesianProductFIPC from ...components.function_inputs_policy.cartesian_product_on_id_for_function_inputs import IdCartesianProductFIPC
@ -34,4 +33,4 @@ Example:
] ]
""" """
pipeline_for_verify_exception_for_case_by_case_config = [MeFacadeFC, IdentityDC, IdentityBC, pipeline_for_verify_exception_for_case_by_case_config = [MeFacadeFC, IdentityDC, IdentityBC,
IdCartesianProductFIPC, CheckExceptionsEC] IdCartesianProductFIPC]

@ -15,27 +15,15 @@
""" test checkparameter """ """ test checkparameter """
import pytest import pytest
import numpy as np import numpy as np
from mindspore._checkparam import check_input_format, Validator, twice, Rel from mindspore._checkparam import twice, Validator
kernel_size = 5 kernel_size = 5
kernel_size1 = twice(kernel_size) kernel_size1 = twice(kernel_size)
assert kernel_size1 == (5, 5) assert kernel_size1 == (5, 5)
def test_check_integer1():
with pytest.raises(TypeError):
Validator.check_integer("input", 0, Rel.GE, "number")
def test_check_integer2():
with pytest.raises(ValueError):
Validator.check_integer(-1, 0, Rel.GE, "number")
def test_check_integer3():
input = np.random.randint(0, 100)
assert Validator.check_integer(input, 0, Rel.GE, "number") == input
def test_check_int1(): def test_check_int1():
input = np.random.randint(-100, 100) a = np.random.randint(-100, 100)
assert Validator.check_is_int(input) == input assert Validator.check_is_int(a) == a
def test_check_int2(): def test_check_int2():
with pytest.raises(TypeError): with pytest.raises(TypeError):
@ -56,16 +44,16 @@ def test_check_is_int5():
Validator.check_is_int(False) Validator.check_is_int(False)
def test_check_positive_int1(): def test_check_positive_int1():
input = np.random.randint(0, 100) a = np.random.randint(0, 100)
assert Validator.check_positive_int(input) == input assert Validator.check_positive_int(a) == a
def test_check_positive_int2(): def test_check_positive_int2():
input = np.random.randint(-100, 0) a = np.random.randint(-100, 0)
with pytest.raises(ValueError): with pytest.raises(ValueError):
Validator.check_positive_int(input) Validator.check_positive_int(a)
def test_check_positive_int3(): def test_check_positive_int3():
with pytest.raises(ValueError): with pytest.raises(TypeError):
Validator.check_positive_int(3.3) Validator.check_positive_int(3.3)
def test_check_positive_int4(): def test_check_positive_int4():
@ -73,16 +61,16 @@ def test_check_positive_int4():
Validator.check_positive_int("str") Validator.check_positive_int("str")
def test_check_negative_int1(): def test_check_negative_int1():
input = np.random.randint(-100, -1) a = np.random.randint(-100, -1)
assert Validator.check_negative_int(input) == input assert Validator.check_negative_int(a) == a
def test_check_negative_int2(): def test_check_negative_int2():
input = np.random.randint(0, 100) a = np.random.randint(0, 100)
with pytest.raises(ValueError): with pytest.raises(ValueError):
Validator.check_negative_int(input) Validator.check_negative_int(a)
def test_check_negative_int3(): def test_check_negative_int3():
with pytest.raises(ValueError): with pytest.raises(TypeError):
Validator.check_negative_int(3.3) Validator.check_negative_int(3.3)
def test_check_negative_int4(): def test_check_negative_int4():
@ -90,16 +78,16 @@ def test_check_negative_int4():
Validator.check_negative_int("str") Validator.check_negative_int("str")
def test_check_non_positive_int1(): def test_check_non_positive_int1():
input = np.random.randint(-100, 0) a = np.random.randint(-100, 0)
assert Validator.check_non_positive_int(input) == input assert Validator.check_non_positive_int(a) == a
def test_check_non_positive_int2(): def test_check_non_positive_int2():
input = np.random.randint(1, 100) a = np.random.randint(1, 100)
with pytest.raises(ValueError): with pytest.raises(ValueError):
Validator.check_non_positive_int(input) Validator.check_non_positive_int(a)
def test_check_non_positive_int3(): def test_check_non_positive_int3():
with pytest.raises(ValueError): with pytest.raises(TypeError):
Validator.check_non_positive_int(3.3) Validator.check_non_positive_int(3.3)
def test_check_non_positive_int4(): def test_check_non_positive_int4():

@ -15,7 +15,7 @@
""" test_checkparameter """ """ test_checkparameter """
import pytest import pytest
from mindspore._checkparam import check_int, Validator, check_input_format, _expand_tuple from mindspore._checkparam import Validator, check_input_format, _expand_tuple
once = _expand_tuple(1) once = _expand_tuple(1)
twice = _expand_tuple(2) twice = _expand_tuple(2)
@ -26,7 +26,7 @@ assert kernel_size1 == (5, 5)
def test_check_int_1(): def test_check_int_1():
assert check_int(3) == 3 assert Validator.check_is_int(3) == 3
def check_int_positive_1(): def check_int_positive_1():
@ -45,17 +45,17 @@ def test_NCHW3():
def test_check_int_2(): def test_check_int_2():
with pytest.raises(TypeError): with pytest.raises(TypeError):
check_int(3.3) Validator.check_is_int(3.3)
def test_check_int_3(): def test_check_int_3():
with pytest.raises(TypeError): with pytest.raises(TypeError):
check_int("str") Validator.check_is_int("str")
def test_check_int_4(): def test_check_int_4():
with pytest.raises(TypeError): with pytest.raises(TypeError):
check_int(True) Validator.check_is_int(True)
def test_check_bool_1(): def test_check_bool_1():

Loading…
Cancel
Save