| @@ -178,10 +178,10 @@ class DirConvert: | |||
| def rename_generated_npy_file(self): | |||
| """Rename the npy file generated by HISI tool to MS file name format.""" | |||
| # before change, the file name is format like: | |||
| # {op_type}.{op_name_with_scope}.{task_id}(.stream_id).{timestamp}.{tensor_type}.{slot}.{shape}.npy | |||
| # after change, the file name is format like: | |||
| # {op_type}.{op_name}.{task_id}(.stream_id).{timestamp}.{tensor_type}.{slot}.{format}.npy | |||
| # before change | |||
| # file name: {op_type}.{op_name_with_scope}.{task_id}(.stream_id).{timestamp}.{tensor_type}.{slot}.{shape}.npy | |||
| # after change | |||
| # file name: {op_type}.{op_name}.{task_id}(.stream_id).{timestamp}.{tensor_type}.{slot}.{format}.npy | |||
| if not self._is_npy_target(): | |||
| return | |||
| self.hisi_utils.print_info_log( | |||
| @@ -193,6 +193,7 @@ class DirConvert: | |||
| name_splits[1] = name_splits[1].split('_')[-1] | |||
| name_splits[-2] = target_format | |||
| new_file_name = '.'.join(name_splits) | |||
| file.chmod(stat.S_IRUSR) | |||
| file.rename(file.with_name(new_file_name)) | |||
| def convert_failed_tensors(self): | |||
| @@ -200,6 +201,7 @@ class DirConvert: | |||
| failed_lines = [] | |||
| if not self.failed_file_path.is_file(): | |||
| return failed_lines | |||
| os.chmod(self.failed_file_path, stat.S_IRUSR) | |||
| with self.failed_file_path.open() as handler: | |||
| failed_line = handler.readline().strip('\n') | |||
| while failed_line: | |||
| @@ -224,7 +226,7 @@ class DirConvert: | |||
| for missing_tensor in missing_tensors: | |||
| tensor_type, idx = missing_tensor.split(':') | |||
| idx = int(idx) | |||
| tensor = op_data.input[idx] if tensor_type == 'input' else op_data.output[idx] | |||
| tensor = getattr(op_data, tensor_type)[idx] | |||
| dump_data_array = self.get_tensor_numpy_value(tensor) | |||
| self.save_tensor_file(op_file, tensor_type, idx, tensor, dump_data_array) | |||
| @@ -280,6 +282,7 @@ class DirConvert: | |||
| ) | |||
| out_path = os.path.join(self.args_parser.output_path, out_file_name) | |||
| np.save(out_path, dump_data_array) | |||
| os.chmod(out_path, stat.S_IRUSR) | |||
| def _save_tensor_in_bin(self, op_name, tensor_type, idx, tensor, dump_data_array): | |||
| """ | |||
| @@ -304,6 +307,7 @@ class DirConvert: | |||
| ) | |||
| out_path = os.path.join(self.args_parser.output_path, out_file_name) | |||
| dump_data_array.tofile(out_path) | |||
| os.chmod(out_path, stat.S_IRUSR) | |||
| class FileMapping: | |||
| @@ -474,14 +478,14 @@ class OpPath: | |||
| return [str(path) for path in path_gen] | |||
| @property | |||
| def input(self): | |||
| def inputs(self): | |||
| """The list of input tensor files.""" | |||
| if self._input_files is None: | |||
| self._input_files = self._convert_path_gen_to_list(self._input_gen) | |||
| return self._input_files | |||
| @property | |||
| def output(self): | |||
| def outputs(self): | |||
| """The list of output tensor file paths.""" | |||
| if self._output_files is None: | |||
| self._output_files = self._convert_path_gen_to_list(self._output_gen) | |||
| @@ -495,7 +499,7 @@ class OpPath: | |||
| def to_dict(self): | |||
| """Get operator files of one iteration in dict format.""" | |||
| res = { | |||
| 'input': self.input, | |||
| 'output': self.output | |||
| 'input': self.inputs, | |||
| 'output': self.outputs | |||
| } | |||
| return res | |||