diff --git a/hub_module/modules/image/keypoint_detection/hand_pose_localization/model.py b/hub_module/modules/image/keypoint_detection/hand_pose_localization/model.py index c79e8177f08c645b401ac73fa9d92499147dcb86..acc47f7fc0a170aab56dcb71e7049e2b07d37e12 100644 --- a/hub_module/modules/image/keypoint_detection/hand_pose_localization/model.py +++ b/hub_module/modules/image/keypoint_detection/hand_pose_localization/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,31 +18,33 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - - # 预训练模型路径 - model = os.path.join(modelpath, "__model__") - params = os.path.join(modelpath, "__params__") - + # 加载模型参数 - config = AnalysisConfig(model, params) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) + config.enable_memory_optim() config.switch_use_feed_fetch_ops(False) config.switch_specify_input_names(True) @@ -58,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/keypoint_detection/hand_pose_localization/module.py b/hub_module/modules/image/keypoint_detection/hand_pose_localization/module.py index 74a4125314aaf805107214e1ac6cba8765f02a3b..04e5342a05d0bfd42f13ad29d5610d8d33a29c8a 100644 --- a/hub_module/modules/image/keypoint_detection/hand_pose_localization/module.py +++ b/hub_module/modules/image/keypoint_detection/hand_pose_localization/module.py @@ -1,4 +1,3 @@ -# coding=utf-8 import os from paddlehub import Module @@ -22,7 +21,7 @@ class Hand_Pose_Localization(Module): self.model_path = os.path.join(self.directory, "hand_pose_localization") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=True) # 关键点检测函数 def keypoint_detection( diff --git a/hub_module/modules/image/style_transfer/UGATIT_100w/model.py b/hub_module/modules/image/style_transfer/UGATIT_100w/model.py index f1639493622da8209cdb6d28808fc0aaad154349..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/UGATIT_100w/model.py +++ b/hub_module/modules/image/style_transfer/UGATIT_100w/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,24 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() diff --git a/hub_module/modules/image/style_transfer/UGATIT_100w/module.py b/hub_module/modules/image/style_transfer/UGATIT_100w/module.py index 5a2bdd0fe8dd9bf03baa13c73e6ee3c170a60fbf..f00f3ae188777c0e74bbc40c7a428ff3f0d96371 100644 --- a/hub_module/modules/image/style_transfer/UGATIT_100w/module.py +++ b/hub_module/modules/image/style_transfer/UGATIT_100w/module.py @@ -21,7 +21,7 @@ class UGATIT_100w(Module): self.model_path = os.path.join(self.directory, "UGATIT_100w") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/UGATIT_83w/model.py b/hub_module/modules/image/style_transfer/UGATIT_83w/model.py index f1639493622da8209cdb6d28808fc0aaad154349..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/UGATIT_83w/model.py +++ b/hub_module/modules/image/style_transfer/UGATIT_83w/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,24 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() diff --git a/hub_module/modules/image/style_transfer/UGATIT_83w/module.py b/hub_module/modules/image/style_transfer/UGATIT_83w/module.py index 7baf4584a6b2eda3b061db91602d139fb0ae68c6..26c0d4880c26de942c89af89ee7ca94d2008a894 100644 --- a/hub_module/modules/image/style_transfer/UGATIT_83w/module.py +++ b/hub_module/modules/image/style_transfer/UGATIT_83w/module.py @@ -21,7 +21,7 @@ class UGATIT_83w(Module): self.model_path = os.path.join(self.directory, "UGATIT_83w") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/UGATIT_92w/model.py b/hub_module/modules/image/style_transfer/UGATIT_92w/model.py index f1639493622da8209cdb6d28808fc0aaad154349..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/UGATIT_92w/model.py +++ b/hub_module/modules/image/style_transfer/UGATIT_92w/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,24 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() diff --git a/hub_module/modules/image/style_transfer/UGATIT_92w/module.py b/hub_module/modules/image/style_transfer/UGATIT_92w/module.py index b6a8723a88337359685a56c8a0049a0b87e65971..cb5443a08ce0970bf81b94e84909f01154b7d3fe 100644 --- a/hub_module/modules/image/style_transfer/UGATIT_92w/module.py +++ b/hub_module/modules/image/style_transfer/UGATIT_92w/module.py @@ -21,7 +21,7 @@ class UGATIT_92w(Module): self.model_path = os.path.join(self.directory, "UGATIT_92w") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/animegan_v1_hayao_60/model.py b/hub_module/modules/image/style_transfer/animegan_v1_hayao_60/model.py index a72cf8a33eac897f749b92a3f1d7fe70b792807a..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v1_hayao_60/model.py +++ b/hub_module/modules/image/style_transfer/animegan_v1_hayao_60/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,25 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() @@ -55,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/style_transfer/animegan_v1_hayao_60/module.py b/hub_module/modules/image/style_transfer/animegan_v1_hayao_60/module.py index 8b77d8944b814ddf95c94d8042ac01a57d7cc5ed..7cc68bd7f1be32dc6faf7360c93ce95c20f8ab38 100644 --- a/hub_module/modules/image/style_transfer/animegan_v1_hayao_60/module.py +++ b/hub_module/modules/image/style_transfer/animegan_v1_hayao_60/module.py @@ -21,7 +21,7 @@ class Animegan_V1_Hayao_60(Module): self.model_path = os.path.join(self.directory, "animegan_v1_hayao_60") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/animegan_v2_hayao_64/model.py b/hub_module/modules/image/style_transfer/animegan_v2_hayao_64/model.py index a72cf8a33eac897f749b92a3f1d7fe70b792807a..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_hayao_64/model.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_hayao_64/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,25 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() @@ -55,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/style_transfer/animegan_v2_hayao_64/module.py b/hub_module/modules/image/style_transfer/animegan_v2_hayao_64/module.py index cdb31f679435880aced64d86ec7a2529ae950a08..15e8aa166b0cd69601a0150b5f49887d8dbabb8f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_hayao_64/module.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_hayao_64/module.py @@ -21,7 +21,7 @@ class Animegan_V2_Hayao_64(Module): self.model_path = os.path.join(self.directory, "animegan_v2_hayao_64") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/animegan_v2_hayao_99/model.py b/hub_module/modules/image/style_transfer/animegan_v2_hayao_99/model.py index a72cf8a33eac897f749b92a3f1d7fe70b792807a..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_hayao_99/model.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_hayao_99/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,25 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() @@ -55,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/style_transfer/animegan_v2_hayao_99/module.py b/hub_module/modules/image/style_transfer/animegan_v2_hayao_99/module.py index ebb1640ee159fcc54b4655e80329c7259bc0ca74..4a842288a2b981e2b747fce8bcd3e86a03bb08df 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_hayao_99/module.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_hayao_99/module.py @@ -21,7 +21,7 @@ class Animegan_V2_Hayao_99(Module): self.model_path = os.path.join(self.directory, "animegan_v2_hayao_99") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/animegan_v2_paprika_54/model.py b/hub_module/modules/image/style_transfer/animegan_v2_paprika_54/model.py index a72cf8a33eac897f749b92a3f1d7fe70b792807a..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_paprika_54/model.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_paprika_54/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,25 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() @@ -55,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/style_transfer/animegan_v2_paprika_54/module.py b/hub_module/modules/image/style_transfer/animegan_v2_paprika_54/module.py index 4631c2811eacff546e612d56ca425a9daa4f43d7..c689126a19f0a16f02e10f1890b8d378d14bf3ea 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_paprika_54/module.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_paprika_54/module.py @@ -21,7 +21,7 @@ class Animegan_V2_Paprika_54(Module): self.model_path = os.path.join(self.directory, "animegan_v2_paprika_54") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/animegan_v2_paprika_74/model.py b/hub_module/modules/image/style_transfer/animegan_v2_paprika_74/model.py index a72cf8a33eac897f749b92a3f1d7fe70b792807a..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_paprika_74/model.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_paprika_74/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,25 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() @@ -55,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/style_transfer/animegan_v2_paprika_74/module.py b/hub_module/modules/image/style_transfer/animegan_v2_paprika_74/module.py index 7d54fafabb396b3f0c8f360d182e1c9e2ac00cc4..653894236c71176f80cfb2e74697c9da9ac953d3 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_paprika_74/module.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_paprika_74/module.py @@ -21,7 +21,7 @@ class Animegan_V2_Paprika_74(Module): self.model_path = os.path.join(self.directory, "animegan_v2_paprika_74") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/animegan_v2_paprika_97/model.py b/hub_module/modules/image/style_transfer/animegan_v2_paprika_97/model.py index a72cf8a33eac897f749b92a3f1d7fe70b792807a..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_paprika_97/model.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_paprika_97/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,25 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() @@ -55,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/style_transfer/animegan_v2_paprika_97/module.py b/hub_module/modules/image/style_transfer/animegan_v2_paprika_97/module.py index c57d71727f69f18bc700d8776027130176b52b0f..0fd91bebb6d0699c3c0548b5bb593584a96f393f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_paprika_97/module.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_paprika_97/module.py @@ -21,7 +21,7 @@ class Animegan_V2_Paprika_97(Module): self.model_path = os.path.join(self.directory, "animegan_v2_paprika_97") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/animegan_v2_paprika_98/model.py b/hub_module/modules/image/style_transfer/animegan_v2_paprika_98/model.py index a72cf8a33eac897f749b92a3f1d7fe70b792807a..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_paprika_98/model.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_paprika_98/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,25 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() @@ -55,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/style_transfer/animegan_v2_paprika_98/module.py b/hub_module/modules/image/style_transfer/animegan_v2_paprika_98/module.py index 6daab80718a1e5809489df9e7732edee05472dce..d040ca4228a846765f7704cdcb7f013b6080f988 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_paprika_98/module.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_paprika_98/module.py @@ -21,7 +21,7 @@ class Animegan_V2_Paprika_98(Module): self.model_path = os.path.join(self.directory, "animegan_v2_paprika_98") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/animegan_v2_shinkai_33/model.py b/hub_module/modules/image/style_transfer/animegan_v2_shinkai_33/model.py index a72cf8a33eac897f749b92a3f1d7fe70b792807a..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_shinkai_33/model.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_shinkai_33/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,25 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() @@ -55,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/style_transfer/animegan_v2_shinkai_33/module.py b/hub_module/modules/image/style_transfer/animegan_v2_shinkai_33/module.py index cc0612f2f92a40683d5ca6fe2cd24f769ef5b1a4..ab016ba852abd20f03519ce76e12701e8380a5ae 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_shinkai_33/module.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_shinkai_33/module.py @@ -21,7 +21,7 @@ class Animegan_V2_Shinkai_33(Module): self.model_path = os.path.join(self.directory, "animegan_v2_shinkai_33") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer( diff --git a/hub_module/modules/image/style_transfer/animegan_v2_shinkai_53/model.py b/hub_module/modules/image/style_transfer/animegan_v2_shinkai_53/model.py index a72cf8a33eac897f749b92a3f1d7fe70b792807a..66db7bba3d3db8d86f038b62a337a48bb218b55f 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_shinkai_53/model.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_shinkai_53/model.py @@ -7,9 +7,9 @@ __all__ = ['Model'] class Model(): # 初始化函数 - def __init__(self, modelpath, use_gpu): + def __init__(self, modelpath, use_gpu=False, use_mkldnn=True, combined=True): # 加载模型预测器 - self.predictor = self.load_model(modelpath, use_gpu) + self.predictor = self.load_model(modelpath, use_gpu, use_mkldnn, combined) # 获取模型的输入输出 self.input_names = self.predictor.get_input_names() @@ -18,25 +18,30 @@ class Model(): self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) # 模型加载函数 - def load_model(self, modelpath, use_gpu): + def load_model(self, modelpath, use_gpu, use_mkldnn, combined): # 对运行位置进行配置 if use_gpu: try: - places = os.environ["CUDA_VISIBLE_DEVICES"] - places = int(places[0]) - except Exception as e: - print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e) + int(os.environ.get('CUDA_VISIBLE_DEVICES')) + except Exception: + print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.') use_gpu = False - + # 加载模型参数 - config = AnalysisConfig(modelpath) + if combined: + model = os.path.join(modelpath, "__model__") + params = os.path.join(modelpath, "__params__") + config = AnalysisConfig(model, params) + else: + config = AnalysisConfig(modelpath) # 设置参数 if use_gpu: - config.enable_use_gpu(100, places) + config.enable_use_gpu(100, 0) else: config.disable_gpu() - config.enable_mkldnn() + if use_mkldnn: + config.enable_mkldnn() config.disable_glog_info() config.switch_ir_optim(True) config.enable_memory_optim() @@ -55,7 +60,8 @@ class Model(): # 遍历输入数据进行预测 for input_data in input_datas: - self.input_tensor.copy_from_cpu(input_data) + inputs = input_data.copy() + self.input_tensor.copy_from_cpu(inputs) self.predictor.zero_copy_run() output = self.output_tensor.copy_to_cpu() outputs.append(output) diff --git a/hub_module/modules/image/style_transfer/animegan_v2_shinkai_53/module.py b/hub_module/modules/image/style_transfer/animegan_v2_shinkai_53/module.py index d733092d979e610c2aff2fc719113a6b8b4298db..c16775e589d565f465b9f7d31023f96a1b2c7f52 100644 --- a/hub_module/modules/image/style_transfer/animegan_v2_shinkai_53/module.py +++ b/hub_module/modules/image/style_transfer/animegan_v2_shinkai_53/module.py @@ -21,7 +21,7 @@ class Animegan_V2_Shinkai_53(Module): self.model_path = os.path.join(self.directory, "animegan_v2_shinkai_53") # 加载模型 - self.model = Model(self.model_path, use_gpu) + self.model = Model(self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False) # 关键点检测函数 def style_transfer(