使用PaddleSeg训练并导出的unet语义分割模型该怎样部署到AIStudio上?
Created by: exploreearth
怎样将paddleseg导出的模型部署到AIStudio上?求好心的大佬指点 第一步:添加模型; 第二步:设置参数:一个参数是图片网址,在处理时先下载图片再读取输入到exe中,输出为字符串 第三步: 输入处理的函数
# -*- coding: utf-8 -*-
"""
Hook
"""
import os
import sys
sys.path.append("..")
from PIL import Image
import cv2
import numpy as np
import paddle.fluid as fluid
def reader_infer(data_args):
def cv2_imread(file_path, flag=cv2.IMREAD_COLOR):
# resolve cv2.imread open Chinese file path issues on Windows Platform.
return cv2.imdecode(np.fromfile(file_path, dtype=np.uint8), flag)
def reader():
image_shape = [3, 500, 500]
image = fluid.layers.data(name='image', shape=image_shape, dtype='float32')
feeder = fluid.DataFeeder(place=fluid.CPUPlace(), feed_list=[image])
url = data_args["image"]
os.system("wget %s -O gf1.png"%url)
datatype= data_args["datatype"]
cv2_imread_flag = cv2.IMREAD_COLOR
mean=[0.5, 0.5, 0.5]
std=[0.5, 0.5, 0.5]
if datatype=="rgba":
cv2_imread_flag = cv2.IMREAD_UNCHANGED
mean = [0.5, 0.5, 0.5,0.5]
std = [0.5, 0.5, 0.5,0.5]
img=cv2_imread("gf1.png",cv2_imread_flag)
img = img.transpose((2, 0, 1)).astype('float32') / 255.0
img_mean = np.array(mean).reshape((len(mean), 1, 1))
img_std = np.array(std).reshape((len(std), 1, 1))
img -= img_mean
img /= img_std
return [[img]], feeder
return reader
输出处理的函数:
# -*- coding: utf-8 -*-
"""
Hook
"""
def output(results, data_args):
"""
示例为目标检测的输出hook
将模型预测的结果,转换为直线坐标
:param results 模型预测结果
:param data_args: 接口传入的数据,以k-v形式
:return array 需要能被json_encode的数据格式
"""
lines=[]
#lines = [str(results)]
lines.append({"out":str(results)})
return lines
第四步输入名称保存
最后测试
{ "image": "https://sino-resource.oss-cn-beijing.aliyuncs.com/rs-tiff/GF1_49_1.png", "datatype": "rgb" }
报错:
Python Call stacks:
File "/usr/local/lib/python3.5/site-packages/paddle/fluid/framework.py", line 1774, in append_op
attrs=kwargs.get("attrs", None))
File "/usr/local/lib/python3.5/site-packages/paddle/fluid/io.py", line 641, in load_vars
'file_path': os.path.join(load_dirname, new_var.name)
File "/usr/local/lib/python3.5/site-packages/paddle/fluid/io.py", line 619, in load_vars
filename=filename)
File "/usr/local/lib/python3.5/site-packages/paddle/fluid/io.py", line 755, in load_persistables
filename=filename)
File "/usr/local/lib/python3.5/site-packages/paddle/fluid/io.py", line 1207, in load_inference_model
load_persistables(executor, load_dirname, program, params_filename)
File "/home/work/serving/webserver/home/serving.py", line 20, in infer
executor=exe)
File "/home/work/serving/webserver/home/views.py", line 48, in index
out = serving.infer(json.loads(req))
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/utils/deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/utils/deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/utils/deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/utils/deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/utils/deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/utils/deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 75, in get_response
response = self._middleware_chain(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 141, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py", line 65, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python3.5/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 194, in handle_one_request
handler.run(self.server.get_app())
File "/usr/local/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 169, in handle
self.handle_one_request()
File "/usr/local/lib/python3.5/socketserver.py", line 681, in __init__
self.handle()
File "/usr/local/lib/python3.5/socketserver.py", line 354, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/lib/python3.5/socketserver.py", line 625, in process_request_thread
self.finish_request(request, client_address)
File "/usr/local/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.5/threading.py", line 882, in _bootstrap
self._bootstrap_inner()
C++ Call stacks:
Cannot open file /home/work/serving/webserver/model/work/model/decode/decode1/up/conv1/BatchNorm/gamma for load op at [/paddle/paddle/fluid/operators/load_op.h:37]
PaddlePaddle Call Stacks:
0 0x7f2f9243a260p void paddle::platform::EnforceNotMet::Init<char const*>(char const*, char const*, int) + 352
1 0x7f2f9243a5d9p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 137
2 0x7f2f92b574c6p paddle::operators::LoadOpKernel<paddle::platform::CPUDeviceContext, float>::Compute(paddle::framework::ExecutionContext const&) const + 774
3 0x7f2f92b57733p std::_Function_handler<void (paddle::framework::ExecutionContext const&), paddle::framework::OpKernelRegistrarFunctor<paddle::platform::CPUPlace, false, 0ul, paddle::operators::LoadOpKernel<paddle::platform::CPUDeviceContext, float>, paddle::operators::LoadOpKernel<paddle::platform::CPUDeviceContext, double>, paddle::operators::LoadOpKernel<paddle::platform::CPUDeviceContext, int>, paddle::operators::LoadOpKernel<paddle::platform::CPUDeviceContext, signed char>, paddle::operators::LoadOpKernel<paddle::platform::CPUDeviceContext, long> >::operator()(char const*, char const*, int) const::{lambda(paddle::framework::ExecutionContext const&)#1}>::_M_invoke(std::_Any_data const&, paddle::framework::ExecutionContext const&) + 35
4 0x7f2f93797ad7p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&, paddle::framework::RuntimeContext*) const + 375
5 0x7f2f93798241p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) const + 529
6 0x7f2f937931e4p paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) + 260
7 0x7f2f925ba11ep paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 206
8 0x7f2f925bd1afp paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::vector<std::string, std::allocator<std::string> > const&, bool) + 143
9 0x7f2f9242ca3dp
10 0x7f2f92469c26p
11 0x7f2ff8dbaf96p PyCFunction_Call + 118
12 0x7f2ff8dfc29dp PyEval_EvalFrameEx + 19613
13 0x7f2ff8dfc04ap PyEval_EvalFrameEx + 19018
14 0x7f2ff8dfc04ap PyEval_EvalFrameEx + 19018
15 0x7f2ff8dfc04ap PyEval_EvalFrameEx + 19018
16 0x7f2ff8dfc04ap PyEval_EvalFrameEx + 19018
17 0x7f2ff8dfc04ap PyEval_EvalFrameEx + 19018
18 0x7f2ff8dfcadcp PyEval_EvalFrameEx + 21724
19 0x7f2ff8df7d27p PyEval_EvalFrameEx + 1831
20 0x7f2ff8df6d10p PyEval_EvalCodeEx + 768
21 0x7f2ff8d9f977p
22 0x7f2ff8d88543p PyObject_Call + 67
23 0x7f2ff8dfa03dp PyEval_EvalFrameEx + 10813
24 0x7f2ff8df7d27p PyEval_EvalFrameEx + 1831
25 0x7f2ff8dfcadcp PyEval_EvalFrameEx + 21724
26 0x7f2ff8df6d10p PyEval_EvalCodeEx + 768
27 0x7f2ff8d9f7c3p
28 0x7f2ff8d88543p PyObject_Call + 67
29 0x7f2ff8d9738ep
30 0x7f2ff8d88543p PyObject_Call + 67
31 0x7f2ff8e4e6a0p
32 0x7f2ff8d88543p PyObject_Call + 67
33 0x7f2ff8dfbbe4p PyEval_EvalFrameEx + 17892
34 0x7f2ff8dfcadcp PyEval_EvalFrameEx + 21724
35 0x7f2ff8df6d10p PyEval_EvalCodeEx + 768
36 0x7f2ff8d9f7c3p
37 0x7f2ff8d88543p PyObject_Call + 67
38 0x7f2ff8d9738ep
39 0x7f2ff8d88543p PyObject_Call + 67
40 0x7f2ff8e4e6a0p
41 0x7f2ff8d88543p PyObject_Call + 67
42 0x7f2ff8dfbbe4p PyEval_EvalFrameEx + 17892
43 0x7f2ff8dfcadcp PyEval_EvalFrameEx + 21724
44 0x7f2ff8df6d10p PyEval_EvalCodeEx + 768
45 0x7f2ff8d9f7c3p
46 0x7f2ff8d88543p PyObject_Call + 67
47 0x7f2ff8d9738ep
48 0x7f2ff8d88543p PyObject_Call + 67
49 0x7f2ff8e4e6a0p
50 0x7f2ff8d88543p PyObject_Call + 67
51 0x7f2ff8dfbbe4p PyEval_EvalFrameEx + 17892
52 0x7f2ff8dfcadcp PyEval_EvalFrameEx + 21724
53 0x7f2ff8df6d10p PyEval_EvalCodeEx + 768
54 0x7f2ff8d9f7c3p
55 0x7f2ff8d88543p PyObject_Call + 67
56 0x7f2ff8d9738ep
57 0x7f2ff8d88543p PyObject_Call + 67
58 0x7f2ff8e4e6a0p
59 0x7f2ff8d88543p PyObject_Call + 67
60 0x7f2ff8dfbbe4p PyEval_EvalFrameEx + 17892
61 0x7f2ff8dfcadcp PyEval_EvalFrameEx + 21724
62 0x7f2ff8df6d10p PyEval_EvalCodeEx + 768
63 0x7f2ff8d9f7c3p
64 0x7f2ff8d88543p PyObject_Call + 67
65 0x7f2ff8d9738ep
66 0x7f2ff8d88543p PyObject_Call + 67
67 0x7f2ff8e4e6a0p
68 0x7f2ff8d88543p PyObject_Call + 67
69 0x7f2ff8dfbbe4p PyEval_EvalFrameEx + 17892
70 0x7f2ff8dfcadcp PyEval_EvalFrameEx + 21724
71 0x7f2ff8df6d10p PyEval_EvalCodeEx + 768
72 0x7f2ff8d9f7c3p
73 0x7f2ff8d88543p PyObject_Call + 67
74 0x7f2ff8d9738ep
75 0x7f2ff8d88543p PyObject_Call + 67
76 0x7f2ff8e4e6a0p
77 0x7f2ff8d88543p PyObject_Call + 67
78 0x7f2ff8dfbbe4p PyEval_EvalFrameEx + 17892
79 0x7f2ff8dfcadcp PyEval_EvalFrameEx + 21724
80 0x7f2ff8df7d27p PyEval_EvalFrameEx + 1831
81 0x7f2ff8df6d10p PyEval_EvalCodeEx + 768
82 0x7f2ff8d9f7c3p
83 0x7f2ff8d88543p PyObject_Call + 67
84 0x7f2ff8d9738ep
85 0x7f2ff8d88543p PyObject_Call + 67
86 0x7f2ff8e4e6a0p
87 0x7f2ff8d88543p PyObject_Call + 67
88 0x7f2ff8dfbbe4p PyEval_EvalFrameEx + 17892
89 0x7f2ff8df7031p PyEval_EvalCodeEx + 1569
90 0x7f2ff8d9f7c3p
91 0x7f2ff8d88543p PyObject_Call + 67
92 0x7f2ff8d9738ep
93 0x7f2ff8d88543p PyObject_Call + 67
94 0x7f2ff8e4e6a0p
95 0x7f2ff8d88543p PyObject_Call + 67
96 0x7f2ff8dfbbe4p PyEval_EvalFrameEx + 17892
97 0x7f2ff8df7d27p PyEval_EvalFrameEx + 1831
98 0x7f2ff8df7d27p PyEval_EvalFrameEx + 1831
99 0x7f2ff8df7d27p PyEval_EvalFrameEx + 1831
"}```