基于paddleDetection的 Faster_rcnn使用Python API预测时报错
Created by: ellinyang
训练环境:paddle1.5.1, cuda7, cudnn9; 测试环境:paddle1.6.0, cuda7, cudnn9; 代码环境:基于paddleDetection的Faster_rcnn,因为待检测目标较小,便修改了参数 "anchor_sizes": [16, 32, 64,128,256] , "anchor_start_size": 16 问题:训练正常、评估正常,但在服务部署时,使用cpu并enable_mkldnn预测时会报错;关掉enable_mkldnn 则预测正常,但速度慢很多,不能接受。 模型加载相关代码:
def load_inference_model(args):
use_gpu =False
# 设置AnalysisConfig
config = AnalysisConfig(os.path.join(args.weights, "model"), os.path.join(args.weights,"params"))
if use_gpu:
print("use gpu infer")
config.enable_use_gpu(memory_pool_init_size_mb=3000)
else:
print("use cpu infer")
config.disable_gpu()
thread_num = 20
config.set_cpu_math_library_num_threads(thread_num)
config.enable_mkldnn()
# 创建PaddlePredictor
predictor = create_paddle_predictor(config)
return predictor
#####
def infer(args):
data_list = []
for dd in data:
dd = np.array(dd)
image = PaddleTensor()
image.name = "data"
image.shape = [1] + list(dd.shape)
print("image.shape", image.shape)
image.dtype = PaddleDType.FLOAT32
image.data = PaddleBuf(
dd.astype("float32").flatten().tolist())
data_list.append(image)
print("data_list", data_list)
print("shapes", [dd.shape for dd in data_list])
####
postprocess_conf["im_height"] = im_height
postprocess_conf["im_width"] = im_width
outputs = predictor.run(data_list)
print("outputs", outputs[0].shape)
问题:
W1204 02:16:48.881902 2325 naive_executor.cc:43] The NaiveExecutor can not work properly if the cmake flag ON_INFER is not set.
W1204 02:16:48.881958 2325 naive_executor.cc:45] Unlike the training phase, all the scopes and variables will be reused to save the allocation overhead.
W1204 02:16:48.881970 2325 naive_executor.cc:48] Please re-compile the inference library by setting the cmake flag ON_INFER=ON if you are running Paddle Inference
Traceback (most recent call last):
File "infer_demo_mkldnn.py", line 233, in <module>
infer(args)
File "infer_demo_mkldnn.py", line 166, in infer
outputs = predictor.run(data_list)
paddle.fluid.core_avx.EnforceNotMet:
--------------------------------------------
C++ Call Stacks (More useful to developers):
--------------------------------------------
0 std::string paddle::platform::GetTraceBackString<std::string const&>(std::string const&, char const*, int)
1 paddle::platform::EnforceNotMet::EnforceNotMet(std::string const&, char const*, int)
2 paddle::operators::ConcatMKLDNNOpKernel<float>::Compute(paddle::framework::ExecutionContext const&) const
3 std::_Function_handler<void (paddle::framework::ExecutionContext const&), paddle::framework::OpKernelRegistrarFunctor<paddle::platform::CPUPlace, false, 0ul, paddle::operators::ConcatMKLDNNOpKernel<float>, paddle::operators::ConcatMKLDNNOpKernel<signed char>, paddle::operators::ConcatMKLDNNOpKernel<unsigned char> >::operator()(char const*, char const*, int) const::{lambda(paddle::framework::ExecutionContext const&)#1}>::_M_invoke(std::_Any_data const&, paddle::framework::ExecutionContext const&)
4 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
5 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
6 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&)
7 paddle::framework::NaiveExecutor::Run()
8 paddle::AnalysisPredictor::Run(std::vector<paddle::PaddleTensor, std::allocator<paddle::PaddleTensor> > const&, std::vector<paddle::PaddleTensor, std::allocator<paddle::PaddleTensor> >*, int)
------------------------------------------
Python Call Stacks (More useful to users):
------------------------------------------
File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/framework.py", line 1771, in append_op
attrs=kwargs.get("attrs", None))
File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/layer_helper.py", line 43, in append_op
return self.main_program.current_block().append_op(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/layers/tensor.py", line 210, in concat
attrs={'axis': axis})
File "/tmp/code/user_custom.py", line 822, in __call__
roi_feat_shuffle = fluid.layers.concat(roi_out_list)
File "/tmp/code/user_custom.py", line 194, in create_model
roi_feat = roi_extractor(body_feats, rois, spatial_scale)
File "command.py", line 103, in main
wfw_obj = wfw_cls(workflow_conf)
File "command.py", line 108, in <module>
main()
----------------------
Error Message Summary:
----------------------
PaddleCheckError: Expected input->layout() == DataLayout::kMKLDNN, but received input->layout():NCHW != DataLayout::kMKLDNN:MKLDNNLAYOUT.
Wrong layout set for Input tensor at [/paddle/paddle/fluid/operators/mkldnn/concat_mkldnn_op.cc:34]
[operator < concat > error]
[pid: 3791][tid: 139684194371328][INFO][2019-12-03 15:43:02,095][handler.py:171] Failed infering, EnforceNotMet: