Openpose给出错误:无法从其他线程访问CPU / GPU指针数据

时间:2018-01-19 16:42:26

标签: openpose

我想初始化一个openose实例,将它保存为类字段,这个类实现了一些与grpc相关的逻辑,将侦听端口,并且我希望将请求(图像)从此端口传递给保存的openpose实例用于检测,然后将检测结果返回到此端口。

googling后。我找到了PyOpenpose,并实现了我的设计:

  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*******

PosingServer运行后,它可以接收rpc请求并执行检测,但是这一行:

return net.getKeypoints(net.KeypointType.POSE)[0]

给出错误:

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.

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

在调用PoseExtractor之前,应使用函数PoseExtractor::initializationOnThread()初始化您的getPoseKeypoints()对象。在开发自己的多线程应用程序时,我遇到了完全相同的错误,因为在尝试从子线程获取姿势关键点时,从父线程调用了初始化。我通过确保两个函数都在同一线程中被调用来解决了这个问题。