-1

How can I return an value from a function when an object is created

Call:

gpuid = Vgg16Worker(Process,Queue)

Class:

class Vgg16Worker(Process):
    def __init__(self, gpuid, queue):
        Process.__init__(self, name='ModelProcessor')
        self._gpuid = gpuid
        self._queue = queue

        print('Queue initialisiert')
        return(self._gpuid)

Error:

__init__() should return None, not 'type'
Anja
  • 11
  • 3
  • Does this answer your question? [How to return a value from \_\_init\_\_ in Python?](https://stackoverflow.com/questions/2491819/how-to-return-a-value-from-init-in-python) – tomgalpin Mar 16 '20 at 15:34

2 Answers2

0

Maybe you should create a function in your class to get the value.

class Vgg16Worker(Process):
    def __init__(self, gpuid, queue):
        Process.__init__(self, name='ModelProcessor')
        self._gpuid = gpuid
        self._queue = queue

        print('Queue initialisiert')

    def getGPUID(self):
        return self._gpuid

gpuid = Vgg16Worker(Process,Queue)
gpuid.getGPUID()
jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
0

I have still one question I have a class for prediction:

def predict(self, xnet,frame):

    out = xnet.predict(np.expand_dims(frame, axis=0))[0]
    return np.argmax(out)

When the class is executed, the return value contains a value

nothing arrives in the main process?

Call:

ippreds = Vgg16Worker.predict(gpuid,model,ipframe)

What have I done wrong?

Anja
  • 11
  • 3
  • Hey,it should be another question.It is not good to post a new answer for a new question in the same questions due to the community guidelines.You can post a new question,so that more people can see your problem and help you.If my answer worked,don't forget to accept my answer by clicking the check mark besides my answer. :-). – jizhihaoSAMA Mar 17 '20 at 04:48