'Grab the theano tensor representing the computation of this
layer/operator iff `arg` is a layer.
:type collect_params: bool
:param collect_params: Flag. If true, also collect the parameters
and inputs of the layer `arg` and make them parameters and inputs
needed to compute the current layer/operator'

def tensor_from_layer(self, arg, collect_params=True):

    if (not collect_params):
        if isinstance(arg, Container):
            return arg.out
        else:
            return arg
    if isinstance(arg, Container):
        self.merge_params(arg)
        return arg.out
    elif isinstance(arg, theano.gof.Variable):
        inps = [x for x in theano.gof.graph.inputs([arg]) if (not isinstance(x, (TT.Constant, theano.compile.SharedVariable)))]
        self.add_inputs(inps)
        return arg
    else:
        return arg
