| @@ -481,8 +481,8 @@ def _save_graph(network, file_name): | |||||
| graph_pb = network.get_func_graph_proto() | graph_pb = network.get_func_graph_proto() | ||||
| if graph_pb: | if graph_pb: | ||||
| with open(file_name, "wb") as f: | with open(file_name, "wb") as f: | ||||
| os.chmod(file_name, stat.S_IRUSR | stat.S_IWUSR) | |||||
| f.write(graph_pb) | f.write(graph_pb) | ||||
| os.chmod(file_name, stat.S_IRUSR) | |||||
| def _get_merged_param_data(net, param_name, param_data, integrated_save): | def _get_merged_param_data(net, param_name, param_data, integrated_save): | ||||
| @@ -637,7 +637,7 @@ def _export(net, file_name, file_format, *inputs): | |||||
| if not file_name.endswith('.onnx'): | if not file_name.endswith('.onnx'): | ||||
| file_name += ".onnx" | file_name += ".onnx" | ||||
| with open(file_name, 'wb') as f: | with open(file_name, 'wb') as f: | ||||
| os.chmod(file_name, stat.S_IWUSR | stat.S_IRUSR) | |||||
| os.chmod(file_name, stat.S_IRUSR | stat.S_IWUSR) | |||||
| f.write(onnx_stream) | f.write(onnx_stream) | ||||
| elif file_format == 'MINDIR': | elif file_format == 'MINDIR': | ||||
| _save_mindir(net, file_name, *inputs) | _save_mindir(net, file_name, *inputs) | ||||
| @@ -687,7 +687,7 @@ def _save_mindir(net, file_name, *inputs): | |||||
| dirname = os.path.dirname(current_path) | dirname = os.path.dirname(current_path) | ||||
| os.makedirs(dirname, exist_ok=True) | os.makedirs(dirname, exist_ok=True) | ||||
| with open(file_name, 'wb') as f: | with open(file_name, 'wb') as f: | ||||
| os.chmod(file_name, stat.S_IWUSR | stat.S_IRUSR) | |||||
| os.chmod(file_name, stat.S_IRUSR | stat.S_IWUSR) | |||||
| f.write(model.SerializeToString()) | f.write(model.SerializeToString()) | ||||
| else: | else: | ||||
| logger.warning("Parameters in the net capacity exceeds 1G, save MindIR model and parameters separately.") | logger.warning("Parameters in the net capacity exceeds 1G, save MindIR model and parameters separately.") | ||||
| @@ -701,6 +701,7 @@ def _save_mindir(net, file_name, *inputs): | |||||
| if os.path.exists(data_path): | if os.path.exists(data_path): | ||||
| shutil.rmtree(data_path) | shutil.rmtree(data_path) | ||||
| os.makedirs(data_path, exist_ok=True) | os.makedirs(data_path, exist_ok=True) | ||||
| os.chmod(data_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) | |||||
| index = 0 | index = 0 | ||||
| graphproto = graph_proto() | graphproto = graph_proto() | ||||
| data_size = 0 | data_size = 0 | ||||
| @@ -720,6 +721,7 @@ def _save_mindir(net, file_name, *inputs): | |||||
| if data_size > TOTAL_SAVE: | if data_size > TOTAL_SAVE: | ||||
| data_file_name = data_path + "/" + "data_" + str(index) | data_file_name = data_path + "/" + "data_" + str(index) | ||||
| with open(data_file_name, "ab") as f: | with open(data_file_name, "ab") as f: | ||||
| os.chmod(file_name, stat.S_IRUSR | stat.S_IWUSR) | |||||
| f.write(graphproto.SerializeToString()) | f.write(graphproto.SerializeToString()) | ||||
| index += 1 | index += 1 | ||||
| data_size = 0 | data_size = 0 | ||||
| @@ -728,13 +730,14 @@ def _save_mindir(net, file_name, *inputs): | |||||
| if graphproto.parameter: | if graphproto.parameter: | ||||
| data_file_name = data_path + "/" + "data_" + str(index) | data_file_name = data_path + "/" + "data_" + str(index) | ||||
| with open(data_file_name, "ab") as f: | with open(data_file_name, "ab") as f: | ||||
| os.chmod(file_name, stat.S_IRUSR | stat.S_IWUSR) | |||||
| f.write(graphproto.SerializeToString()) | f.write(graphproto.SerializeToString()) | ||||
| # save graph | # save graph | ||||
| del model.graph.parameter[:] | del model.graph.parameter[:] | ||||
| graph_file_name = dirname + "/" + file_prefix + "_graph.mindir" | graph_file_name = dirname + "/" + file_prefix + "_graph.mindir" | ||||
| with open(graph_file_name, 'wb') as f: | with open(graph_file_name, 'wb') as f: | ||||
| os.chmod(graph_file_name, stat.S_IWUSR | stat.S_IRUSR) | |||||
| os.chmod(graph_file_name, stat.S_IRUSR | stat.S_IWUSR) | |||||
| f.write(model.SerializeToString()) | f.write(model.SerializeToString()) | ||||