From 509e497fec85abc75f9e3b01622b669b3a3e5506 Mon Sep 17 00:00:00 2001 From: lilei Date: Fri, 4 Sep 2020 16:47:08 +0800 Subject: [PATCH] Add data type check --- mindspore/common/initializer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mindspore/common/initializer.py b/mindspore/common/initializer.py index 546d1e99b1..68964afd8b 100644 --- a/mindspore/common/initializer.py +++ b/mindspore/common/initializer.py @@ -457,6 +457,10 @@ def initializer(init, shape=None, dtype=mstype.float32): elif isinstance(shape, numbers.Number): shape = (shape,) + for value in shape if shape is not None else (): + if not isinstance(value, int) or value <= 0: + raise ValueError(f"shape is invalid, shape value must be positive integer, shape:{shape}") + if isinstance(init, Initializer): init.shape = init.shape if init.shape is not None else shape init.dtype = init.dtype if init.dtype is not None else dtype