[MO] remove deprecated mean_file option (#14137)
Signed-off-by: andrei.kochin <andrei.kochin@intel.com> Signed-off-by: andrei.kochin <andrei.kochin@intel.com>
This commit is contained in:
parent
b808fb7f4f
commit
1a4117b855
@ -17,19 +17,6 @@ Caffe-specific parameters:
|
||||
Path to python Caffe parser generated from caffe.proto
|
||||
-k K Path to CustomLayersMapping.xml to register custom
|
||||
layers
|
||||
--mean_file MEAN_FILE, -mf MEAN_FILE
|
||||
[DEPRECATED] Mean image to be used for the input. Should be a
|
||||
binaryproto file
|
||||
--mean_file_offsets MEAN_FILE_OFFSETS, -mo MEAN_FILE_OFFSETS
|
||||
[DEPRECATED] Mean image offsets to be used for the input
|
||||
binaryproto file. When the mean image is bigger than
|
||||
the expected input, it is cropped. By default, centers
|
||||
of the input image and the mean image are the same and
|
||||
the mean image is cropped by dimensions of the input
|
||||
image. The format to pass this option is the
|
||||
following: "-mo (x,y)". In this case, the mean file is
|
||||
cropped by dimensions of the input image with offset
|
||||
(x,y) from the upper left corner of the mean image
|
||||
--disable_omitting_optional
|
||||
Disable omitting optional attributes to be used for
|
||||
custom layers. Use this option if you want to transfer
|
||||
|
@ -237,18 +237,6 @@ def arguments_post_parsing(argv: argparse.Namespace):
|
||||
if is_tf and argv.tensorflow_use_custom_operations_config is not None:
|
||||
argv.transformations_config = argv.tensorflow_use_custom_operations_config
|
||||
|
||||
if is_caffe and argv.mean_file and argv.mean_values:
|
||||
raise Error('Both --mean_file and mean_values are specified. Specify either mean file or mean values. ' +
|
||||
refer_to_faq_msg(17))
|
||||
elif is_caffe and argv.mean_file and argv.mean_file_offsets:
|
||||
values = get_tuple_values(argv.mean_file_offsets, t=int, num_exp_values=2)
|
||||
mean_file_offsets = mo_array([int(x) for x in values[0].split(',')])
|
||||
if not all([offset >= 0 for offset in mean_file_offsets]):
|
||||
raise Error("Negative value specified for --mean_file_offsets option. "
|
||||
"Please specify positive integer values in format '(x,y)'. " +
|
||||
refer_to_faq_msg(18))
|
||||
argv.mean_file_offsets = mean_file_offsets
|
||||
|
||||
if argv.scale and argv.scale_values:
|
||||
raise Error(
|
||||
'Both --scale and --scale_values are defined. Specify either scale factor or scale values per input ' +
|
||||
|
@ -26,59 +26,6 @@ def import_caffe_pb2(caffe_parser_path: str):
|
||||
|
||||
return caffe_pb2
|
||||
|
||||
|
||||
def parse_mean(file_path: str, in_shape: np.ndarray, mean_file_offsets: [tuple, None], caffe_pb2):
|
||||
blob = caffe_pb2.BlobProto()
|
||||
with open(file_path, 'rb') as file:
|
||||
data = file.read()
|
||||
|
||||
if not data:
|
||||
raise Error('Mean file "{}" is empty.' + refer_to_faq_msg(5),
|
||||
file_path)
|
||||
|
||||
try:
|
||||
blob.ParseFromString(data)
|
||||
data = mo_array(blob.data) # pylint: disable=no-member
|
||||
|
||||
if blob.HasField('channels') or blob.HasField('height') or blob.HasField('width'):
|
||||
data = data.reshape(blob.channels, blob.height, blob.width) # pylint: disable=no-member
|
||||
else:
|
||||
data = data.reshape(blob.shape.dim) # pylint: disable=no-member
|
||||
# crop mean image according to input size
|
||||
if in_shape[2] > data.shape[1] or in_shape[3] > data.shape[2]:
|
||||
raise Error(
|
||||
'Input image of shape {} is larger than mean image {} from file "{}". ' +
|
||||
refer_to_faq_msg(4),
|
||||
in_shape,
|
||||
data.shape,
|
||||
file_path
|
||||
)
|
||||
|
||||
if mean_file_offsets is not None and len(mean_file_offsets) == 2:
|
||||
offset_x = mean_file_offsets[0]
|
||||
offset_y = mean_file_offsets[1]
|
||||
else:
|
||||
offset_x = int((data.shape[1] - in_shape[2]) / 2)
|
||||
offset_y = int((data.shape[2] - in_shape[3]) / 2)
|
||||
|
||||
mean = []
|
||||
for i in range(in_shape[1]):
|
||||
data_channel = np.zeros(in_shape[2] * in_shape[3], dtype=np.float32)
|
||||
for x in range(in_shape[2]):
|
||||
for y in range(in_shape[3]):
|
||||
data_channel[x * in_shape[3] + y] = data[i, x + offset_x, y + offset_y]
|
||||
mean.append(data_channel)
|
||||
|
||||
return mean
|
||||
|
||||
except Exception as err:
|
||||
raise Error(
|
||||
'While processing mean file "{}": {}. Probably mean file has incorrect format. ' +
|
||||
refer_to_faq_msg(6),
|
||||
file_path,
|
||||
str(err)) from err
|
||||
|
||||
|
||||
def load_caffe_proto_model(caffe_pb2, proto_path: str, model_path: [str, None] = None):
|
||||
# 1. python protobuf is used
|
||||
if api_implementation._implementation_type == 'python':
|
||||
|
@ -28,17 +28,4 @@ class CaffeMeanFileProcessing(MiddleReplacementPattern):
|
||||
caffe_pb2 = graph.graph['caffe_pb2']
|
||||
del graph.graph['caffe_pb2']
|
||||
input_names = find_inputs(graph)
|
||||
mf = []
|
||||
try:
|
||||
if argv.mean_file and len(original_shapes) == 1:
|
||||
mf = loader.parse_mean(argv.mean_file, original_shapes[input_names[0]],
|
||||
argv.mean_file_offsets, caffe_pb2)
|
||||
elif argv.mean_file:
|
||||
raise Error('Mean file for topologies with multiple inputs is not supported. ' +
|
||||
refer_to_faq_msg(9))
|
||||
except ValueError as e:
|
||||
raise Error('Cannot load or process mean file: value error {}. ' +
|
||||
refer_to_faq_msg(10), str(e)) from e
|
||||
|
||||
graph.graph['mf'] = mf
|
||||
graph.graph['input_names'] = input_names
|
||||
|
@ -823,8 +823,6 @@ class DeprecatedCanonicalizePathCheckExistenceAction(CanonicalizePathCheckExiste
|
||||
option_string)
|
||||
if 'tensorflow_use_custom_operations_config' in option_string:
|
||||
dep_msg += 'Please use --transformations_config cli option instead'
|
||||
if 'mean_file' in option_string or 'mean_offset' in option_string:
|
||||
dep_msg += 'Please use --mean_values cli option instead.'
|
||||
log.error(dep_msg, extra={'is_warning': True})
|
||||
super().__call__(parser, namespace, values, option_string)
|
||||
|
||||
@ -1127,8 +1125,6 @@ def get_caffe_cli_options():
|
||||
d = {
|
||||
'input_proto': ['- Path to the Input prototxt', lambda x: x],
|
||||
'caffe_parser_path': ['- Path to Python Caffe* parser generated from caffe.proto', lambda x: x],
|
||||
'mean_file': ['- Path to a mean file', lambda x: x if x else 'Not specified'],
|
||||
'mean_file_offsets': ['- Offsets for a mean file', lambda x: x if x else 'Not specified'],
|
||||
'k': '- Path to CustomLayersMapping.xml',
|
||||
'disable_resnet_optimization': ['- Enable resnet optimization', lambda x: not x],
|
||||
}
|
||||
@ -1181,8 +1177,8 @@ def get_onnx_cli_options():
|
||||
|
||||
def get_params_with_paths_list():
|
||||
return ['input_model', 'output_dir', 'caffe_parser_path', 'extensions', 'k', 'output_dir',
|
||||
'input_checkpoint', 'input_meta_graph', 'input_proto', 'input_symbol', 'mean_file',
|
||||
'mean_file_offsets', 'pretrained_model_name', 'saved_model_dir', 'tensorboard_logdir',
|
||||
'input_checkpoint', 'input_meta_graph', 'input_proto', 'input_symbol',
|
||||
'pretrained_model_name', 'saved_model_dir', 'tensorboard_logdir',
|
||||
'tensorflow_custom_layer_libraries', 'tensorflow_custom_operations_config_update',
|
||||
'tensorflow_object_detection_api_pipeline_config', 'tensorflow_use_custom_operations_config',
|
||||
'transformations_config']
|
||||
@ -1219,20 +1215,6 @@ def get_caffe_cli_parser(parser: argparse.ArgumentParser = None):
|
||||
'front', 'caffe',
|
||||
'CustomLayersMapping.xml'),
|
||||
action=CanonicalizePathCheckExistenceAction)
|
||||
caffe_group.add_argument('--mean_file', '-mf',
|
||||
help='[DEPRECATED] ' +
|
||||
'Mean image to be used for the input. Should be a binaryproto file',
|
||||
default=None,
|
||||
action=DeprecatedCanonicalizePathCheckExistenceAction)
|
||||
caffe_group.add_argument('--mean_file_offsets', '-mo',
|
||||
help='[DEPRECATED] ' +
|
||||
'Mean image offsets to be used for the input binaryproto file. ' +
|
||||
'When the mean image is bigger than the expected input, it is cropped. By default, centers ' +
|
||||
'of the input image and the mean image are the same and the mean image is cropped by ' +
|
||||
'dimensions of the input image. The format to pass this option is the following: "-mo (x,y)". In this ' +
|
||||
'case, the mean file is cropped by dimensions of the input image with offset (x,y) ' +
|
||||
'from the upper left corner of the mean image',
|
||||
default=None)
|
||||
caffe_group.add_argument('--disable_omitting_optional',
|
||||
help=mo_convert_params_caffe['disable_omitting_optional'].description,
|
||||
action='store_true',
|
||||
|
Loading…
Reference in New Issue
Block a user