From 1ba9b4c2db89984cc7837ffac238303e95b767d3 Mon Sep 17 00:00:00 2001 From: chenjian Date: Mon, 16 Jan 2023 11:10:18 +0800 Subject: [PATCH] fix a bug for string format (#1199) Co-authored-by: heliqi <1101791222@qq.com> --- .../fastdeploy_client/http_client_manager.py | 4 +-- .../inference/fastdeploy_client/visualizer.py | 32 +++++++++---------- .../component/inference/fastdeploy_lib.py | 22 ++++++++----- .../component/inference/fastdeploy_server.py | 9 +++--- .../inference/model_convert_server.py | 12 +++---- .../component/profiler/profiler_reader.py | 14 ++++---- 6 files changed, 50 insertions(+), 43 deletions(-) diff --git a/visualdl/component/inference/fastdeploy_client/http_client_manager.py b/visualdl/component/inference/fastdeploy_client/http_client_manager.py index e5fe85c0..858c9c62 100644 --- a/visualdl/component/inference/fastdeploy_client/http_client_manager.py +++ b/visualdl/component/inference/fastdeploy_client/http_client_manager.py @@ -307,8 +307,8 @@ class HttpClientManager: return fastdeploy_client except Exception: raise RuntimeError( - 'Can not connect to server {}, please check your \ - server address'.format(server_url)) + 'Can not connect to server {}, please check your ' + 'server address'.format(server_url)) def infer(self, server_url, model_name, model_version, inputs): fastdeploy_client = self._create_client(server_url) diff --git a/visualdl/component/inference/fastdeploy_client/visualizer.py b/visualdl/component/inference/fastdeploy_client/visualizer.py index 2c6abe0b..c64a2427 100644 --- a/visualdl/component/inference/fastdeploy_client/visualizer.py +++ b/visualdl/component/inference/fastdeploy_client/visualizer.py @@ -27,8 +27,8 @@ def visualize_detection(image, data): import fastdeploy as fd except Exception: raise RuntimeError( - "fastdeploy is required for visualizing results,please refer to \ - https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") + "fastdeploy is required for visualizing results,please refer to " + "https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") boxes = np.array(data['boxes']) scores = np.array(data['scores']) label_ids = np.array(data['label_ids']) @@ -49,8 +49,8 @@ def visualize_keypoint_detection(image, data): import fastdeploy as fd except Exception: raise RuntimeError( - "fastdeploy is required for visualizing results,please refer to \ - https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") + "fastdeploy is required for visualizing results,please refer to " + "https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") keypoints = np.array(data['keypoints']) scores = np.array(data['scores']) num_joints = np.array(data['num_joints']) @@ -69,8 +69,8 @@ def visualize_face_detection(image, data): import fastdeploy as fd except Exception: raise RuntimeError( - "fastdeploy is required for visualizing results,please refer to \ - https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") + "fastdeploy is required for visualizing results,please refer to " + "https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") data = np.array(data['data']) scores = np.array(data['scores']) landmarks = np.array(data['landmarks']) @@ -91,8 +91,8 @@ def visualize_face_alignment(image, data): import fastdeploy as fd except Exception: raise RuntimeError( - "fastdeploy is required for visualizing results,please refer to \ - https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") + "fastdeploy is required for visualizing results,please refer to " + "https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") landmarks = np.array(data['landmarks']) facealignment_result = fd.C.vision.FaceAlignmentResult() @@ -107,8 +107,8 @@ def visualize_segmentation(image, data): import fastdeploy as fd except Exception: raise RuntimeError( - "fastdeploy is required for visualizing results,please refer to \ - https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") + "fastdeploy is required for visualizing results,please refer to " + "https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") label_ids = np.array(data['label_ids']) score_map = np.array(data['score_map']) shape = np.array(data['shape']) @@ -127,8 +127,8 @@ def visualize_matting(image, data): import fastdeploy as fd except Exception: raise RuntimeError( - "fastdeploy is required for visualizing results,please refer to \ - https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") + "fastdeploy is required for visualizing results,please refer to " + "https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") alpha = np.array(data['alpha']) foreground = np.array(data['foreground']) contain_foreground = data['contain_foreground'] @@ -149,8 +149,8 @@ def visualize_ocr(image, data): import fastdeploy as fd except Exception: raise RuntimeError( - "fastdeploy is required for visualizing results,please refer to \ - https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") + "fastdeploy is required for visualizing results,please refer to " + "https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") boxes = np.array(data['boxes']) text = np.array(data['text']) rec_scores = np.array(data['rec_scores']) @@ -173,8 +173,8 @@ def visualize_headpose(image, data): import fastdeploy as fd except Exception: raise RuntimeError( - "fastdeploy is required for visualizing results,please refer to \ - https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") + "fastdeploy is required for visualizing results,please refer to " + "https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") euler_angles = np.array(data['euler_angles']) headpose_result = fd.C.vision.HeadPoseResult() diff --git a/visualdl/component/inference/fastdeploy_lib.py b/visualdl/component/inference/fastdeploy_lib.py index 5264c6e7..28934b3c 100644 --- a/visualdl/component/inference/fastdeploy_lib.py +++ b/visualdl/component/inference/fastdeploy_lib.py @@ -467,14 +467,20 @@ def launch_process(kwargs: dict): logfilename = 'logfile-{}'.format(get_random_string(8)) while os.path.exists(os.path.join(FASTDEPLOYSERVER_PATH, logfilename)): logfilename = 'logfile-{}'.format(get_random_string(8)) - p = Popen( - cmd, - stdout=open( - os.path.join(FASTDEPLOYSERVER_PATH, logfilename), 'w', - buffering=1), - stderr=STDOUT, - universal_newlines=True, - env=launch_env) + try: + p = Popen( + cmd, + stdout=open( + os.path.join(FASTDEPLOYSERVER_PATH, logfilename), + 'w', + buffering=1), + stderr=STDOUT, + universal_newlines=True, + env=launch_env) + except Exception: + raise RuntimeError( + "Failed to launch fastdeployserver,please check fastdeployserver is installed in environment." + ) server_name = start_args['server-name'] if start_args[ 'server-name'] else p.pid with open( diff --git a/visualdl/component/inference/fastdeploy_server.py b/visualdl/component/inference/fastdeploy_server.py index 8d07b1fa..b6280329 100644 --- a/visualdl/component/inference/fastdeploy_server.py +++ b/visualdl/component/inference/fastdeploy_server.py @@ -156,8 +156,8 @@ class FastDeployServerApi(object): self._poll_zombie_process() if check_process_zombie(server_id) is True: raise RuntimeError( - "Server {} is down due to exception or killed,please check the reason according to the log, \ - then close this server.".format(server_id)) + "Server {} is down due to exception or killed,please check the reason according to the log, " + "then close this server.".format(server_id)) return @result() @@ -207,8 +207,9 @@ class FastDeployServerApi(object): import fastdeploy as fd except Exception: raise RuntimeError( - "fastdeploy is required for visualizing results,please refer to \ - https://github.com/PaddlePaddle/FastDeploy to install fastdeploy") + "fastdeploy is required for visualizing results,please refer to " + "https://github.com/PaddlePaddle/FastDeploy to install fastdeploy" + ) model_path = fd.download_model( name=pretrain_model_name, path=version_resource_dir) if model_path: diff --git a/visualdl/component/inference/model_convert_server.py b/visualdl/component/inference/model_convert_server.py index 35ad8711..edbb4281 100644 --- a/visualdl/component/inference/model_convert_server.py +++ b/visualdl/component/inference/model_convert_server.py @@ -47,8 +47,8 @@ class ModelConvertApi(object): file_handle = request.files['file'] data = file_handle.stream.read() if format not in self.supported_formats: - raise RuntimeError('Model format {} is not supported. \ - Only onnx and caffe models are supported now.'.format(format)) + raise RuntimeError('Model format {} is not supported. "\ + "Only onnx and caffe models are supported now.'.format(format)) result = {} result['from'] = format result['to'] = 'paddle' @@ -99,14 +99,14 @@ class ModelConvertApi(object): dirname, filename) if prototxt_path is None or weight_path is None: raise RuntimeError( - ".prototxt or .caffemodel file is missing in your archive file, \ - please check files uploaded.") + ".prototxt or .caffemodel file is missing in your archive file, " + "please check files uploaded.") caffe2paddle(prototxt_path, weight_path, target_path, None) except Exception as e: raise RuntimeError( - "[Convertion error] {}.\n Please open an issue at \ - https://github.com/PaddlePaddle/X2Paddle/issues to report your problem." + "[Convertion error] {}.\n Please open an issue at " + "https://github.com/PaddlePaddle/X2Paddle/issues to report your problem." .format(e)) with self.lock: # we need to enter dirname(target_path) to archive, # in case unneccessary directory added in archive. diff --git a/visualdl/component/profiler/profiler_reader.py b/visualdl/component/profiler/profiler_reader.py index 85230c72..78ae1522 100644 --- a/visualdl/component/profiler/profiler_reader.py +++ b/visualdl/component/profiler/profiler_reader.py @@ -202,9 +202,9 @@ class ProfilerReader(object): try: import paddle except Exception as e: - print('Paddle is required to read protobuf file.\ - Please install [paddlepaddle](https://www.paddlepaddle.org.cn/install/quick?\ - docurl=/documentation/docs/zh/develop/install/pip/linux-pip.html) first.' + print('Paddle is required to read protobuf file. "\ + "Please install [paddlepaddle](https://www.paddlepaddle.org.cn/install/quick?"\ + "docurl=/documentation/docs/zh/develop/install/pip/linux-pip.html) first.' ) raise RuntimeError(str(e)) if packaging.version.parse( @@ -223,10 +223,10 @@ class ProfilerReader(object): profile_result = ProfilerResult(content) except Exception as e: raise RuntimeError( - "An error occurred while loading the protobuf file, which may be caused\ - by the outdated version of paddle that generated the profile file. \ - Please make sure protobuf file is exported by paddlepaddle version >= 2.4.0. \ - Error message: {}".format(e)) + "An error occurred while loading the protobuf file, which may be caused " + "by the outdated version of paddle that generated the profile file. " + "Please make sure protobuf file is exported by paddlepaddle version >= 2.4.0. " + "Error message: {}".format(e)) self.profile_result_queue.put( (run, filename, worker_name, profile_result)) -- GitLab