I want to initialize an openose instance,save it as a class field,and this class implemented some grpc related logic,will listen on a port,and I want pass the request(an image) from this port to saved openpose instance for detection,then return back detection result to this port.
After googling.I found PyOpenpose,and implement my design like this:
class PosingServer:
def __init__(self, setting=PosingSetting):
self.setting=setting
self.initNetwork()
def detect(self, req):
#detect pose
net.detectPose(req.image)
#detect pose
return net.getKeypoints(net.KeypointType.POSE)[0]
def initNetwork(self):
setting = self.setting
self.net = OP.OpenPose(setting.poseSize, setting.faceHandSize, setting.outSize,\
setting.modelType, setting.modelFolder, setting.logLevel,\
setting.downloadHeatmaps)
*****grpc related stuffs*******
After PosingServer running,it can receive rpc request and perform detection but this line:
return net.getKeypoints(net.KeypointType.POSE)[0]
gives error:
The CPU/GPU pointer data cannot be accessed from a different thread.
Coming from:
- src/openpose/pose/poseExtractor.cpp:checkThread():341
- src/openpose/pose/poseExtractor.cpp:checkThread():345
- src/openpose/pose/poseExtractor.cpp:getPoseKeypoints():265
ERROR Exception calling application:
Error:
The CPU/GPU pointer data cannot be accessed from a different thread.
Coming from:
- src/openpose/pose/poseExtractor.cpp:checkThread():341
- src/openpose/pose/poseExtractor.cpp:checkThread():345
- src/openpose/pose/poseExtractor.cpp:getPoseKeypoints():265
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/grpc/_server.py", line 377, in _call_behavior
return behavior(argument, context), True
File "server/pose/PosingServer.py", line 81, in carryOut
return self.detector.detect(req)
File "server/pose/PosingServer.py", line 40, in detect
return net.getKeypoints(net.KeypointType.POSE)[0])
RuntimeError:
Error:
The CPU/GPU pointer data cannot be accessed from a different thread.
How to solve this problem?