Skip to content
Advertisement

Share the output of one class to another class python

I have two DNNs the first one returns two outputs. I want to use one of these outputs in a second class that represents another DNN as in the following example:

I want to pass the output (x) to the second class to be concatenated to another variable (v). I found a solution to make the variable (x) as a global variable, but I need another efficient solution

JavaScript

Advertisement

Answer

You should not have to rely on global variables, you need to solve this following common practices. You can pass both v, and x as parameters of the forward of Net2. Something like:

JavaScript

With dummy data:

JavaScript

First inference:

JavaScript

Second inference:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement