Openpose gives error:The CPU/GPU pointer data cannot be accessed from a different thread - openpose

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?

Your PoseExtractor object should be initialize with the function PoseExtractor::initializationOnThread() before you can call getPoseKeypoints(). I got the exact same same error while developing my own multithreaded application because the initialization was called from the parent thread while I was trying to get the pose keypoints from a child thread. I solved the problem by making sure both functions were called within the same thread.

Related

When I try to handle the exception by using the custom exception class , do I need to use alias?

class InsufficientBalance(ZeroDivisionError):
def __init__(self,text):
self.text=text
balance=5000
try:
AmtToBeWithdrawn=int(input("Enter the amount you want to withdraw"))
if AmtToBeWithdrawn>balance:
raise InsufficientBalance("Bhosdike aukat me rahkar amount dal")
except InsufficientBalance as i:
print(i.text)
else:
balance=balance-AmtToBeWithdrawn
print("Withdrawal Successfull")
finally:
print("Remaining balance on the account",balance)
When we use the as keyword in the above code , does the as keyword create the object of the InsufficientBalance class? because if that does not create the object then , how is it possible to access the instance variable text? When I just write
except InsufficientBalance as i:
print(i.text)
it gives the exception
Traceback (most recent call last):
File "C:/Users/HP/Desktop/Fullstack dev SR/Python/ASS27.py", line 103, in <module>
print(InsufficientBalance.text)
AttributeError: type object 'InsufficientBalance' has no attribute 'text'
but when I write
except InsufficientBalance as i:
print(i.text)
the code does not produce any exception , why is it so?
Thanks in advance for replying.

How to call save method in mongoengine.EmbeddedDocument class

import mongoengine
class Model1(mongoengine.DynamicDocument):
name = mongoengine.StringField()
addr = mongoengine.EmbeddedDocumentField(Model2)
class Model2(mongoengine.EmbeddedDocument):
loc = mongoengine.StringField()
# do some stuff
def save(self, *args, **kwargs):
print "test line print...."
super(Model2, self).save(*args, **kwargs)
now when I save Model1 instance. it doesn't call save method
m2 = Model2(loc='some text')
m1 = Model1(name='name')
m1.addr = m2
m1.save()
if I try to explicity call the save method on Model2, it complains that NoneType object has no attr save
m2 (embedded doc) does have a save method. It calls m1.save(). See the code.
The assumption calling m1.save() will call save() on all embedded documents is false. (I fell in the same trap...)
So unfortunately, you can't safely override an embedded document's save method expecting it to be called each time the document is saved.
But you can add it a pre_save method you call from m1.save() (or in a callback catching the pre_save signal in the document).
However, calling m2.save() should call m1.save() and save the whole document. I can't explain this error: NoneType object has no attr save. You should edit your question to provide the full traceback.

Calling method from console: "No current object"

I have a method that I need to test. I would like to do so from the console. Here is the method, as well as some metadata from the class:
Include HS.Common
Class Custom.class Extends Ens.BusinessOperation
{
Parameter ADAPTER = "EnsLib.EMail.OutboundAdapter";
Property Adapter As EnsLib.EMail.OutboundAdapter;
Method SendMessage(pSubject As %String, pMessage As %String, pEmailAddresses) As %Status
{
set tSC=$$$OK
set tMailMessage=##class(%Net.MailMessage).%New()
do tMailMessage.To.Insert($PIECE(pEmailAddresses,",",1))
for tI=2:1:$LENGTH(pEmailAddresses,",") {
do tMailMessage.Cc.Insert($PIECE(pEmailAddresses,",",tI))
}
set tMailMessage.Subject=pSubject
set tMailMessage.Charset="iso-8859-1"
set tSC=tMailMessage.TextData.Write(pMessage)
quit:'tSC
Set tSC1=..Adapter.SendMail(tMailMessage)
if 'tSC1 {
//Log warning about being unable to send mail.
do $SYSTEM.Status.DecomposeStatus(tSC1,.err)
$$$LOGWARNING("Could not send email: "_err(err))
kill err
}
quit tSC
}
...other methods here...
}
but when I perform this command:
set tResult = ##class(Custom.class).SendMessage("Test Subject","Test Message","my#email.com")
I get this error:
Set tSC1=..Adapter.SendMail(tMailMessage)
^
<NO CURRENT OBJECT>zSendMessage+11^Custom.class.1
I tried instantiating adapter, much like the property definition, before calling the method but that did not work. How can I call this method from a console session?
this method is an instance method, and you can't call it directly just for some class. Before, you should create an object, and then for that object, you can call any instance methods. But you still trying to call Ensemble classes, it is not so easy, because you should prepare environment, such as configured and started Ensemble Production, your class should be added as an Operation, configured and activated.
set oper=##class(Custom.class).%New("configName")
where configName - name for that operation in your production, by default it is same as class name (e.g. "Custom.class"). And now you can call your method.
write oper.SendMessage("testSubj","test body","my#mail.com")
But I would not recommend such way. It would be better if you test it through production, just sent test messages to this operation.

How to invoke an interface method with Mono Embedding?

I load an assembly and from that a class of the object I want to create. From that class I check for interfaces (mono_class_get_interfaces) and find the interface class I want (IDispose).
I create the object with mono_object_new and call mono_runtime_object_init directly afterward. I then call mono_object_castclass_mbyref to cast the object to an interface reference. Then I retrieve the interface method I want to call (Dispose) from the interface class with mono_class_get_method_from_name.
I call mono_object_get_virtual_method to make sure I have the correct implementation and then try to call it with mono_runtime_invoke using the interface MonoObject * reference and the interface virtual method MonoMethod * (args = NULL) -> which is unsuccessful.
I have also tried to call mono_method_get_unmanaged_thunk with the same parameter, that doesn't work either.
In both cases I get a value back for the exception argument. Problem is, I haven't found a way to look inside the exception...
Question is:
Is the sequence of calls correct to work with managed interfaces and call the correct (most specific) interface methods?
How to get more information on the MonoException (I assume the MonoObject * returned by invoke is a MonoException instance)?
There is no need to invoke any castclass function to cast a managed reference to an 'interface reference': the value is the same.
Once you have your IDispose MonoClass* pointer, you should get the MonoMethod* for the method you want to call and pass that to mono_object_get_virtual_method(). The result of this function is what you should pass to mono_runtime_invoke().
For the exception, you can invoke the get_Message method method, for example, or any of the methods you'd call to deal with it if you were in C# code.
Simple tested code below, str is a MonoString*:
icloneable_class = mono_class_from_name (mono_get_corlib (), "System", "ICloneable");
iface_method = mono_class_get_method_from_name (icloneable_class, "Clone", 0);
iface_impl_method = mono_object_get_virtual_method (str, iface_method);
exc = NULL;
obj = mono_runtime_invoke (iface_impl_method, str, NULL, &exc);
The method is correctly invoked and exc will be NULL.

will be assumed to return id

I import oourafft.h and oourafft.m class, but get strange error while ooura initialize.
OouraFFT * myFFT = [OouraFFT initForSignalsOfLength:1024 numberOfWindows:10];
OouraFFT may not respond to +initForSignalsOfLength: numberOfWindows
Messages without matching method signature will be assumed to return 'id' and accept argument - Warning
I think that it some kind of error import .h file
You are trying to call class method which does not exist in OouraFFT - this method is instance method, so you need to allocate object at first.
You should do the following:
OouraFFT * myFFT = [[OouraFFT alloc] initForSignalsOfLength:1024 andNumWindows:10];
And don't forget that you own object after this, therefore you should release or autorelease in an appropriate place.