(net_name, conf, enable_micro)
| 115 | |
| 116 | |
| 117 | def convert_net(net_name, conf, enable_micro): |
| 118 | option = cvt.ConverterOption() |
| 119 | option.name = net_name |
| 120 | option.order = conf.get(ModelKeys.order, 0) |
| 121 | if ModelKeys.quantize_stat in conf: |
| 122 | option.quantize_stat = conf[ModelKeys.quantize_stat] |
| 123 | else: |
| 124 | option.quantize_stat = False |
| 125 | |
| 126 | if ModelKeys.graph_optimize_options in conf: |
| 127 | option.transformer_option = conf[ModelKeys.graph_optimize_options] |
| 128 | if ModelKeys.winograd in conf: |
| 129 | option.winograd = conf[ModelKeys.winograd] |
| 130 | if ModelKeys.quantize in conf: |
| 131 | option.quantize = conf[ModelKeys.quantize] |
| 132 | if ModelKeys.quantize_schema in conf: |
| 133 | option.quantize_schema = conf[ModelKeys.quantize_schema] |
| 134 | if ModelKeys.quantize_large_weights in conf: |
| 135 | option.quantize_large_weights = conf[ModelKeys.quantize_large_weights] |
| 136 | if ModelKeys.quantize_range_file in conf: |
| 137 | option.quantize_range_file = conf[ModelKeys.quantize_range_file] |
| 138 | if ModelKeys.change_concat_ranges in conf: |
| 139 | option.change_concat_ranges = conf[ModelKeys.change_concat_ranges] |
| 140 | if ModelKeys.cl_mem_type in conf: |
| 141 | option.cl_mem_type = conf[ModelKeys.cl_mem_type] |
| 142 | if ModelKeys.platform in conf: |
| 143 | option.platform = conf[ModelKeys.platform] |
| 144 | if ModelKeys.runtime in conf: |
| 145 | option.device = conf[ModelKeys.runtime] |
| 146 | if option.device == DeviceType.CPU_GPU: |
| 147 | # when convert, cpu and gpu share the same model |
| 148 | option.device = DeviceType.CPU |
| 149 | # we don't need `value`, but to be consistent with legacy code |
| 150 | # used by `base_converter` |
| 151 | option.device = option.device.value |
| 152 | |
| 153 | if option.quantize_stat: |
| 154 | option.quantize = False |
| 155 | |
| 156 | option.enable_micro = enable_micro |
| 157 | option.data_type = conf[ModelKeys.data_type] |
| 158 | |
| 159 | for i in range(len(conf[ModelKeys.input_tensors])): |
| 160 | input_node = cvt.NodeInfo() |
| 161 | input_node.name = conf[ModelKeys.input_tensors][i] |
| 162 | if ModelKeys.input_aliases in conf: |
| 163 | input_node.alias = conf[ModelKeys.input_aliases][i] |
| 164 | else: |
| 165 | input_node.alias = input_node.name |
| 166 | input_node.shape = conf[ModelKeys.input_shapes][i] |
| 167 | input_node.data_type = conf[ModelKeys.input_data_types][i] |
| 168 | input_node.data_format = conf[ModelKeys.input_data_formats][i] |
| 169 | if (input_node.data_format == DataFormat.NCHW and len( |
| 170 | input_node.shape) == 4): |
| 171 | input_node.shape = transpose_shape(input_node.shape, [0, 2, 3, 1]) |
| 172 | input_node.data_format = DataFormat.NHWC |
| 173 | input_node.range = conf[ModelKeys.input_ranges][i] |
| 174 | option.add_input_node(input_node) |
no test coverage detected