未验证 提交 5b1b11d0 编写于 作者: jm_12138's avatar jm_12138 提交者: GitHub

Update to Paddle 2.0 (#1140)

* update paddleinference to 2.0

* change _initialize to __init__

* change _initialize to __init__

* change version number

* change version number

* change version number
上级 2778d5f3
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
config.enable_memory_optim() config.enable_memory_optim()
...@@ -44,7 +49,7 @@ class Model(): ...@@ -44,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +61,9 @@ class Model(): ...@@ -56,9 +61,9 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
inputs = input_data.copy() inputs = input_data.copy()
self.input_tensor.copy_from_cpu(inputs) self.input_handle.copy_from_cpu(inputs)
self.predictor.zero_copy_run() self.predictor.run()
output = self.output_tensor.copy_to_cpu() output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from UGATIT_100w.processor import base64_to_cv2, cv2_to_base64, Processor ...@@ -13,16 +13,16 @@ from UGATIT_100w.processor import base64_to_cv2, cv2_to_base64, Processor
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="UGATIT_100w", # 模型介绍 summary="UGATIT_100w", # 模型介绍
version="1.0.0" # 版本号 version="1.0.1" # 版本号
) )
class UGATIT_100w(Module): class UGATIT_100w(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "UGATIT_100w") self.model_path = os.path.join(self.directory, "UGATIT_100w")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, images=None, paths=None, batch_size=1, output_dir='output', visualization=False): def style_transfer(self, images=None, paths=None, batch_size=1, output_dir='output', visualization=False):
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
config.enable_memory_optim() config.enable_memory_optim()
...@@ -44,7 +49,7 @@ class Model(): ...@@ -44,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +61,9 @@ class Model(): ...@@ -56,9 +61,9 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
inputs = input_data.copy() inputs = input_data.copy()
self.input_tensor.copy_from_cpu(inputs) self.input_handle.copy_from_cpu(inputs)
self.predictor.zero_copy_run() self.predictor.run()
output = self.output_tensor.copy_to_cpu() output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from UGATIT_83w.processor import base64_to_cv2, cv2_to_base64, Processor ...@@ -13,16 +13,16 @@ from UGATIT_83w.processor import base64_to_cv2, cv2_to_base64, Processor
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="UGATIT", # 模型介绍 summary="UGATIT", # 模型介绍
version="1.0.0" # 版本号 version="1.0.1" # 版本号
) )
class UGATIT_83w(Module): class UGATIT_83w(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "UGATIT_83w") self.model_path = os.path.join(self.directory, "UGATIT_83w")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, images=None, paths=None, batch_size=1, output_dir='output', visualization=False): def style_transfer(self, images=None, paths=None, batch_size=1, output_dir='output', visualization=False):
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
config.enable_memory_optim() config.enable_memory_optim()
...@@ -44,7 +49,7 @@ class Model(): ...@@ -44,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +61,9 @@ class Model(): ...@@ -56,9 +61,9 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
inputs = input_data.copy() inputs = input_data.copy()
self.input_tensor.copy_from_cpu(inputs) self.input_handle.copy_from_cpu(inputs)
self.predictor.zero_copy_run() self.predictor.run()
output = self.output_tensor.copy_to_cpu() output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from UGATIT_92w.processor import base64_to_cv2, cv2_to_base64, Processor ...@@ -13,16 +13,16 @@ from UGATIT_92w.processor import base64_to_cv2, cv2_to_base64, Processor
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="UGATIT_92w", # 模型介绍 summary="UGATIT_92w", # 模型介绍
version="1.0.0" # 版本号 version="1.0.1" # 版本号
) )
class UGATIT_92w(Module): class UGATIT_92w(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "UGATIT_92w") self.model_path = os.path.join(self.directory, "UGATIT_92w")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, images=None, paths=None, batch_size=1, output_dir='output', visualization=False): def style_transfer(self, images=None, paths=None, batch_size=1, output_dir='output', visualization=False):
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
...@@ -45,7 +49,7 @@ class Model(): ...@@ -45,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +60,10 @@ class Model(): ...@@ -56,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from animegan_v1_hayao_60.processor import base64_to_cv2, cv2_to_base64, Process ...@@ -13,16 +13,16 @@ from animegan_v1_hayao_60.processor import base64_to_cv2, cv2_to_base64, Process
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v1_hayao_60", # 模型介绍 summary="animegan_v1_hayao_60", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Animegan_V1_Hayao_60(Module): class Animegan_V1_Hayao_60(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "animegan_v1_hayao_60") self.model_path = os.path.join(self.directory, "animegan_v1_hayao_60")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, def style_transfer(self,
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
...@@ -45,7 +49,7 @@ class Model(): ...@@ -45,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +60,10 @@ class Model(): ...@@ -56,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from animegan_v2_hayao_64.processor import base64_to_cv2, cv2_to_base64, Process ...@@ -13,16 +13,16 @@ from animegan_v2_hayao_64.processor import base64_to_cv2, cv2_to_base64, Process
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_hayao_64", # 模型介绍 summary="animegan_v2_hayao_64", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Animegan_V2_Hayao_64(Module): class Animegan_V2_Hayao_64(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "animegan_v2_hayao_64") self.model_path = os.path.join(self.directory, "animegan_v2_hayao_64")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, def style_transfer(self,
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
...@@ -45,7 +49,7 @@ class Model(): ...@@ -45,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +60,10 @@ class Model(): ...@@ -56,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from animegan_v2_hayao_99.processor import base64_to_cv2, cv2_to_base64, Process ...@@ -13,16 +13,16 @@ from animegan_v2_hayao_99.processor import base64_to_cv2, cv2_to_base64, Process
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_hayao_99", # 模型介绍 summary="animegan_v2_hayao_99", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Animegan_V2_Hayao_99(Module): class Animegan_V2_Hayao_99(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "animegan_v2_hayao_99") self.model_path = os.path.join(self.directory, "animegan_v2_hayao_99")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, def style_transfer(self,
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
...@@ -45,7 +49,7 @@ class Model(): ...@@ -45,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +60,10 @@ class Model(): ...@@ -56,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from animegan_v2_paprika_54.processor import base64_to_cv2, cv2_to_base64, Proce ...@@ -13,16 +13,16 @@ from animegan_v2_paprika_54.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_paprika_54", # 模型介绍 summary="animegan_v2_paprika_54", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Animegan_V2_Paprika_54(Module): class Animegan_V2_Paprika_54(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "animegan_v2_paprika_54") self.model_path = os.path.join(self.directory, "animegan_v2_paprika_54")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, def style_transfer(self,
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
...@@ -45,7 +49,7 @@ class Model(): ...@@ -45,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +60,10 @@ class Model(): ...@@ -56,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from animegan_v2_paprika_74.processor import base64_to_cv2, cv2_to_base64, Proce ...@@ -13,16 +13,16 @@ from animegan_v2_paprika_74.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_paprika_74", # 模型介绍 summary="animegan_v2_paprika_74", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Animegan_V2_Paprika_74(Module): class Animegan_V2_Paprika_74(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "animegan_v2_paprika_74") self.model_path = os.path.join(self.directory, "animegan_v2_paprika_74")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, def style_transfer(self,
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
...@@ -45,7 +49,7 @@ class Model(): ...@@ -45,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +60,10 @@ class Model(): ...@@ -56,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from animegan_v2_paprika_97.processor import base64_to_cv2, cv2_to_base64, Proce ...@@ -13,16 +13,16 @@ from animegan_v2_paprika_97.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_paprika_97", # 模型介绍 summary="animegan_v2_paprika_97", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Animegan_V2_Paprika_97(Module): class Animegan_V2_Paprika_97(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "animegan_v2_paprika_97") self.model_path = os.path.join(self.directory, "animegan_v2_paprika_97")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, def style_transfer(self,
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
...@@ -45,7 +49,7 @@ class Model(): ...@@ -45,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +60,10 @@ class Model(): ...@@ -56,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from animegan_v2_paprika_98.processor import base64_to_cv2, cv2_to_base64, Proce ...@@ -13,16 +13,16 @@ from animegan_v2_paprika_98.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_paprika_98", # 模型介绍 summary="animegan_v2_paprika_98", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Animegan_V2_Paprika_98(Module): class Animegan_V2_Paprika_98(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "animegan_v2_paprika_98") self.model_path = os.path.join(self.directory, "animegan_v2_paprika_98")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, def style_transfer(self,
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
...@@ -45,7 +49,7 @@ class Model(): ...@@ -45,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +60,10 @@ class Model(): ...@@ -56,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from animegan_v2_shinkai_33.processor import base64_to_cv2, cv2_to_base64, Proce ...@@ -13,16 +13,16 @@ from animegan_v2_shinkai_33.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_shinkai_33", # 模型介绍 summary="animegan_v2_shinkai_33", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Animegan_V2_Shinkai_33(Module): class Animegan_V2_Shinkai_33(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "animegan_v2_shinkai_33") self.model_path = os.path.join(self.directory, "animegan_v2_shinkai_33")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, def style_transfer(self,
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 加载模型参数 # 加载模型参数
config = AnalysisConfig(modelpath) if combined:
model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__")
config = Config(model, params)
else:
config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
...@@ -45,7 +49,7 @@ class Model(): ...@@ -45,7 +49,7 @@ class Model():
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -56,9 +60,10 @@ class Model(): ...@@ -56,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -13,16 +13,16 @@ from animegan_v2_shinkai_53.processor import base64_to_cv2, cv2_to_base64, Proce ...@@ -13,16 +13,16 @@ from animegan_v2_shinkai_53.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_shinkai_53", # 模型介绍 summary="animegan_v2_shinkai_53", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Animegan_V2_Shinkai_53(Module): class Animegan_V2_Shinkai_53(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "animegan_v2_shinkai_53") self.model_path = os.path.join(self.directory, "animegan_v2_shinkai_53")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=False)
# 关键点检测函数 # 关键点检测函数
def style_transfer(self, def style_transfer(self,
......
import os import os
import numpy as np import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor from paddle.inference import create_predictor, Config
__all__ = ['Model'] __all__ = ['Model']
class 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() self.input_names = self.predictor.get_input_names()
self.output_names = self.predictor.get_output_names() self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0]) self.input_handle = self.predictor.get_input_handle(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0]) self.output_handle = self.predictor.get_output_handle(self.output_names[0])
# 模型加载函数 # 模型加载函数
def load_model(self, modelpath, use_gpu): def load_model(self, modelpath, use_gpu, use_mkldnn, combined):
# 对运行位置进行配置 # 对运行位置进行配置
if use_gpu: if use_gpu:
try: try:
places = os.environ["CUDA_VISIBLE_DEVICES"] int(os.environ.get('CUDA_VISIBLE_DEVICES'))
places = int(places[0]) except Exception:
except Exception as e: print('Error! Unable to use GPU. Please set the environment variables "CUDA_VISIBLE_DEVICES=GPU_id" to use GPU.')
print('Error: %s. Please set the environment variables "CUDA_VISIBLE_DEVICES".' % e)
use_gpu = False use_gpu = False
# 预训练模型路径 # 加载模型参数
if combined:
model = os.path.join(modelpath, "__model__") model = os.path.join(modelpath, "__model__")
params = os.path.join(modelpath, "__params__") params = os.path.join(modelpath, "__params__")
config = Config(model, params)
# 加载模型参数 else:
config = AnalysisConfig(model, params) config = Config(modelpath)
# 设置参数 # 设置参数
if use_gpu: if use_gpu:
config.enable_use_gpu(100, places) config.enable_use_gpu(100, 0)
else: else:
config.disable_gpu() config.disable_gpu()
if use_mkldnn:
config.enable_mkldnn() config.enable_mkldnn()
config.disable_glog_info() config.disable_glog_info()
config.switch_ir_optim(True) config.switch_ir_optim(True)
config.enable_memory_optim()
config.switch_use_feed_fetch_ops(False) config.switch_use_feed_fetch_ops(False)
config.switch_specify_input_names(True) config.switch_specify_input_names(True)
# 通过参数加载模型预测器 # 通过参数加载模型预测器
predictor = create_paddle_predictor(config) predictor = create_predictor(config)
# 返回预测器 # 返回预测器
return predictor return predictor
...@@ -59,9 +60,10 @@ class Model(): ...@@ -59,9 +60,10 @@ class Model():
# 遍历输入数据进行预测 # 遍历输入数据进行预测
for input_data in input_datas: for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data) inputs = input_data.copy()
self.predictor.zero_copy_run() self.input_handle.copy_from_cpu(inputs)
output = self.output_tensor.copy_to_cpu() self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output) outputs.append(output)
# 预测结果合并 # 预测结果合并
......
...@@ -14,16 +14,16 @@ from hand_pose_localization.processor import base64_to_cv2, Processor ...@@ -14,16 +14,16 @@ from hand_pose_localization.processor import base64_to_cv2, Processor
author="jm12138", # 作者名称 author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱 author_email="jm12138@qq.com", # 作者邮箱
summary="hand_pose_localization", # 模型介绍 summary="hand_pose_localization", # 模型介绍
version="1.0.0" # 版本号 version="1.0.2" # 版本号
) )
class Hand_Pose_Localization(Module): class Hand_Pose_Localization(Module):
# 初始化函数 # 初始化函数
def _initialize(self, use_gpu=False): def __init__(self, name=None, use_gpu=False):
# 设置模型路径 # 设置模型路径
self.model_path = os.path.join(self.directory, "hand_pose_localization") self.model_path = os.path.join(self.directory, "hand_pose_localization")
# 加载模型 # 加载模型
self.model = Model(self.model_path, use_gpu) self.model = Model(modelpath=self.model_path, use_gpu=use_gpu, use_mkldnn=False, combined=True)
# 关键点检测函数 # 关键点检测函数
def keypoint_detection(self, images=None, paths=None, batch_size=1, output_dir='output', visualization=False): def keypoint_detection(self, images=None, paths=None, batch_size=1, output_dir='output', visualization=False):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册