def args_check(cls, node, **kwargs): # update cast_map base on auto_cast flag cls.indices_cast_map[ tf.uint64] = tf.int64 if sys_config.auto_cast else None cls.depth_cast_map[ tf.uint32] = tf.int32 if sys_config.auto_cast else None cls.depth_cast_map[ tf.uint64] = tf.int32 if sys_config.auto_cast else None cls.depth_cast_map[ tf.int64] = tf.int32 if sys_config.auto_cast else None tensor_dict = kwargs["tensor_dict"] indices = tensor_dict[node.inputs[0]] depth = tensor_dict[node.inputs[1]] indices_dtype = indices.dtype depth_dtype = depth.dtype if indices_dtype in cls.indices_cast_map and cls.indices_cast_map[ indices_dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "OneHot input " + node.inputs[0] + " with data type '" + data_type.tf_to_np_str(indices_dtype) + "'", data_type.tf_to_np_str_list(cls.indices_supported_type)) if depth_dtype in cls.depth_cast_map and cls.depth_cast_map[ depth_dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "OneHot input " + node.inputs[1] + " with data type '" + data_type.tf_to_np_str(depth_dtype) + "'", data_type.tf_to_np_str_list(cls.depth_supported_type))
def args_check(cls, node, **kwargs): dtype = kwargs["tensor_dict"][node.inputs[0]].dtype if dtype in cls.cast_map and cls.cast_map[dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "Sub input " + node.inputs[0] + " with data type '" + data_type.tf_to_np_str(dtype) + "'", data_type.tf_to_np_str_list(cls.supported_types))
def args_check(cls, node, **kwargs): x = kwargs["tensor_dict"][node.inputs[0]] # throw an error if the data type is not natively supported by # Tensorflow, cannot be safely cast, and auto-cast option is False if x.dtype in cls.cast_map and cls.cast_map[x.dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "CumSum input " + node.inputs[0] + " with data type '" + data_type.tf_to_np_str(x.dtype) + "'", data_type.tf_to_np_str_list(cls.supported_types))
def args_check(cls, node, **kwargs): # update cast map based on the auto_cast config option cls.cast_map[tf.uint64] = tf.int64 if sys_config.auto_cast else None x = kwargs["tensor_dict"][node.inputs[0]] y = kwargs["tensor_dict"][node.inputs[1]] # throw an error if the data type is not natively supported by # Tensorflow, cannot be safely cast, and auto_cast option is False if x.dtype in cls.cast_map and cls.cast_map[x.dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "LessOrEqual input " + node.inputs[0] + " with data type '" + data_type.tf_to_np_str(x.dtype) + "'", data_type.tf_to_np_str_list(cls.supported_types)) if y.dtype in cls.cast_map and cls.cast_map[y.dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "LessOrEqual input " + node.inputs[1] + " with data type '" + data_type.tf_to_np_str(y.dtype) + "'", data_type.tf_to_np_str_list(cls.supported_types))
def args_check(cls, node, **kwargs): # update cast map based on the auto_cast config option cls.cast_map[tf.uint64] = tf.int64 if sys_config.auto_cast else None inp_dtype = kwargs["tensor_dict"][node.inputs[0]].dtype if inp_dtype in cls.cast_map and cls.cast_map[inp_dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "Min input " + node.inputs[0] + " with data type '" + data_type.tf_to_np_str(inp_dtype) + "'", data_type.tf_to_np_str_list(cls.supported_types))
def args_check(cls, node, **kwargs): # update cast_map base on auto_cast flag cls.cast_map[ tf.complex64] = tf.float64 if sys_config.auto_cast else None cls.cast_map[ tf.complex128] = tf.float64 if sys_config.auto_cast else None data = kwargs["tensor_dict"][node.inputs[0]] data_dtype = data.dtype if data_dtype in cls.cast_map and cls.cast_map[data_dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "ScatterElements input " + node.inputs[0] + " and " + node.inputs[2] + " with data type '" + data_type.tf_to_np_str(data_dtype) + "'", data_type.tf_to_np_str_list(cls.supported_types))
def args_check(cls, node, **kwargs): x = kwargs["tensor_dict"][node.inputs[0]] y = kwargs["tensor_dict"][node.inputs[1]] # throw an error if the data type is not natively supported by # Tensorflow, cannot be safely cast, and auto-cast option is False if x.dtype in cls.cast_map and cls.cast_map[x.dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "Mod input " + node.inputs[0] + " with data type '" + data_type.tf_to_np_str(x.dtype) + "'", data_type.tf_to_np_str_list(cls.supported_types)) # throw an error if inputs A and B are not in the same data type if x.dtype != y.dtype: exception.OP_UNSUPPORTED_EXCEPT("Mod with inputs in different data types", "Tensorflow")
def args_check(cls, node, **kwargs): # update cast maps based on the auto_cast config option cls.x_cast_map[tf.uint64] = tf.int64 if sys_config.auto_cast else None cls.x_cast_map[ tf.complex64] = tf.float64 if sys_config.auto_cast else None cls.x_cast_map[ tf.complex128] = tf.float64 if sys_config.auto_cast else None cls.roi_cast_map[ tf.float64] = tf.float32 if sys_config.auto_cast else None x = kwargs["tensor_dict"][node.inputs[0]] x_shape = x.get_shape().as_list() x_dtype = x.dtype if len(x_shape) != 4: exception.OP_UNSUPPORTED_EXCEPT("Resize required 4D input", "Tensorflow") if x_dtype in cls.x_cast_map and cls.x_cast_map[x_dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "Resize input " + node.inputs[0] + " with data type '" + data_type.tf_to_np_str(x_dtype) + "'", data_type.tf_to_np_str_list(cls.x_supported_types)) if cls.SINCE_VERSION >= 11: # supported attributes combination # ____________________________________________________________________________________________________________________________________________________ # | mode | coordinate_transformation_mode | cubic_coeff_a | exclude_outside | extrapolation_value | nearest_mode | scales | sizes | # |_________|________________________________|_______________|_________________|_____________________|___________________|_______________|___________| # | nearest | align_corners | not apply | 0 | not apply | round_prefer_ceil | supported (1) | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | nearest | asymmetric | not apply | 0 | not apply | floor | supported (1) | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | nearest | tf_half_pixel_for_nn | not apply | 0 | not apply | floor | supported (1) | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | linear | align_corners | not apply | 0 | not apply | not apply | supported (1) | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | linear | asymmetric | not apply | 0 | not apply | not apply | supported (1) | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | linear | half_pixel | not apply | 0 | not apply | not apply | supported (1) | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | cubic | align_corners | -0.5 | 1 | not apply | not apply | supported (1) | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | cubic | asymmetric | -0.5 | 1 | not apply | not apply | supported (1) | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | cubic | half_pixel | -0.5 | 1 | not apply | not apply | supported (1) | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | nearest | tf_crop_and_resize | not apply | 0 | any float value | round_prefer_ceil | supported | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # | linear | tf_crop_and_resize | not apply | 0 | any float value | not apply | supported | supported | # |---------|--------------------------------|---------------|-----------------|---------------------|-------------------|---------------|-----------| # Note: # 1. The accuracy of your model will go down, if the height and the width of the new sizes(scales * origial sizes) are not in whole numbers. coordinate_transformation_mode = node.attrs.get( "coordinate_transformation_mode", "half_pixel") cubic_coeff_a = node.attrs.get("cubic_coeff_a", -0.75) exclude_outside = node.attrs.get("exclude_outside", 0) mode = node.attrs.get("mode", "nearest") nearest_mode = node.attrs.get("nearest_mode", "round_prefer_floor") if coordinate_transformation_mode == "tf_crop_and_resize": if x_dtype in cls.cr_x_cast_map and cls.cr_x_cast_map[ x_dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "Resize input " + node.inputs[0] + " with data type '" + data_type.tf_to_np_str(x_dtype) + "'", data_type.tf_to_np_str_list(cls.cr_x_supported_types)) roi = kwargs["tensor_dict"][node.inputs[1]] roi_dtype = roi.dtype if roi_dtype in cls.roi_cast_map and cls.roi_cast_map[ roi_dtype] is None: exception.DTYPE_NOT_CAST_EXCEPT( "Resize input " + node.inputs[1] + " with data type '" + data_type.tf_to_np_str(roi_dtype) + "'", data_type.tf_to_np_str_list(cls.roi_supported_types)) if coordinate_transformation_mode == "pytorch_half_pixel": exception.OP_UNSUPPORTED_EXCEPT( "Resize coordinate_transformation_mode=pytorch_half_pixel", "Tensorflow") if (coordinate_transformation_mode == "half_pixel" and mode == "nearest" ) or (coordinate_transformation_mode == "tf_half_pixel_for_nn" and mode in ["linear", "cubic"]) or ( coordinate_transformation_mode == "tf_crop_and_resize" and mode == "cubic"): exception.OP_UNSUPPORTED_EXCEPT( "Resize coordinate_transformation_mode=" + coordinate_transformation_mode + " and mode=" + mode, "Tensorflow") if (exclude_outside == 1 and mode in ["nearest", "linear"]) or ( exclude_outside == 0 and mode == "cubic"): exception.OP_UNSUPPORTED_EXCEPT( "Resize mode=" + mode + " and exclude_outside=" + str(exclude_outside), "Tensorflow") if cubic_coeff_a != -0.5 and mode == "cubic": exception.OP_UNSUPPORTED_EXCEPT( "Resize mode=cubic and cubic_coeff_a=" + cubic_coeff_a, "Tensorflow") if mode == "nearest": if (nearest_mode in [ "round_prefer_floor", "ceil" ]) or (coordinate_transformation_mode in ["align_corners", "tf_crop_and_resize"] and nearest_mode == "floor") or ( coordinate_transformation_mode in ["asymmetric", "tf_half_pixel_for_nn"] and nearest_mode == "round_prefer_ceil"): exception.OP_UNSUPPORTED_EXCEPT( "Resize coordinate_transformation_mode=" + coordinate_transformation_mode + ", mode=nearest and nearest_mode=" + nearest_mode, "Tensorflow")