未验证 提交 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 numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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()
config.switch_use_feed_fetch_ops(False)
config.switch_specify_input_names(True)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +61,13 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
inputs = input_data.copy()
self.input_tensor.copy_from_cpu(inputs)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from UGATIT_100w.processor import base64_to_cv2, cv2_to_base64, Processor
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="UGATIT_100w", # 模型介绍
version="1.0.0" # 版本号
version="1.0.1" # 版本号
)
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 = 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):
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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()
config.switch_use_feed_fetch_ops(False)
config.switch_specify_input_names(True)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +61,13 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
inputs = input_data.copy()
self.input_tensor.copy_from_cpu(inputs)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from UGATIT_83w.processor import base64_to_cv2, cv2_to_base64, Processor
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="UGATIT", # 模型介绍
version="1.0.0" # 版本号
version="1.0.1" # 版本号
)
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 = 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):
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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()
config.switch_use_feed_fetch_ops(False)
config.switch_specify_input_names(True)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +61,13 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
inputs = input_data.copy()
self.input_tensor.copy_from_cpu(inputs)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from UGATIT_92w.processor import base64_to_cv2, cv2_to_base64, Processor
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="UGATIT_92w", # 模型介绍
version="1.0.0" # 版本号
version="1.0.1" # 版本号
)
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 = 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):
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from animegan_v1_hayao_60.processor import base64_to_cv2, cv2_to_base64, Process
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v1_hayao_60", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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,
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from animegan_v2_hayao_64.processor import base64_to_cv2, cv2_to_base64, Process
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_hayao_64", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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,
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from animegan_v2_hayao_99.processor import base64_to_cv2, cv2_to_base64, Process
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_hayao_99", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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,
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from animegan_v2_paprika_54.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_paprika_54", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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,
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from animegan_v2_paprika_74.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_paprika_74", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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,
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from animegan_v2_paprika_97.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_paprika_97", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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,
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from animegan_v2_paprika_98.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_paprika_98", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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,
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from animegan_v2_shinkai_33.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_shinkai_33", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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,
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -56,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -13,16 +13,16 @@ from animegan_v2_shinkai_53.processor import base64_to_cv2, cv2_to_base64, Proce
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="animegan_v2_shinkai_53", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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,
......
import os
import numpy as np
from paddle.fluid.core import AnalysisConfig, create_paddle_predictor
from paddle.inference import create_predictor, Config
__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()
self.output_names = self.predictor.get_output_names()
self.input_tensor = self.predictor.get_input_tensor(self.input_names[0])
self.output_tensor = self.predictor.get_output_tensor(self.output_names[0])
self.input_handle = self.predictor.get_input_handle(self.input_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:
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 = Config(model, params)
else:
config = Config(modelpath)
# 设置参数
if use_gpu:
config.enable_use_gpu(100, places)
if use_gpu:
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)
# 通过参数加载模型预测器
predictor = create_paddle_predictor(config)
predictor = create_predictor(config)
# 返回预测器
return predictor
......@@ -59,13 +60,14 @@ class Model():
# 遍历输入数据进行预测
for input_data in input_datas:
self.input_tensor.copy_from_cpu(input_data)
self.predictor.zero_copy_run()
output = self.output_tensor.copy_to_cpu()
inputs = input_data.copy()
self.input_handle.copy_from_cpu(inputs)
self.predictor.run()
output = self.output_handle.copy_to_cpu()
outputs.append(output)
# 预测结果合并
outputs = np.concatenate(outputs, 0)
# 返回预测结果
return outputs
return outputs
\ No newline at end of file
......@@ -14,16 +14,16 @@ from hand_pose_localization.processor import base64_to_cv2, Processor
author="jm12138", # 作者名称
author_email="jm12138@qq.com", # 作者邮箱
summary="hand_pose_localization", # 模型介绍
version="1.0.0" # 版本号
version="1.0.2" # 版本号
)
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 = 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):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册