Converting placeholder from tensorflow to pytorch

I am a newbie programmer in pytorch. I am trying to convert this code from Approximate Inference for Deep Latent Gaussian Mixtures paper written in tensorflow to pytorch. I have a difficult time finding out how I can translate tf.placeholder syntax from tensorflow to pytorch explicitly for this part of the aforementioned code:
line 84 of script

class GaussMMVAE(object):
    def __init__(self, hyperParams):

        self.X = tf.placeholder("float", [None, hyperParams['input_d']])
        self.prior = hyperParams['prior']
        self.K = hyperParams['K']

        self.encoder_params = self.init_encoder(hyperParams)
        self.decoder_params = self.init_decoder(hyperParams)

I have read many posts that there isn’t any one to one function for placeholder but given the above example code, I reckon there should be a case by case solution. Thanks in advance for any instructive suggestion.

As you’ve already read, there are not placeholders in PyTorch and you can directly use tensors (similar to how you would use numpy). I don’t know why the tf.placeholder is assigned to self.X, but your translated code in PyTorch should just accept an input tensor in the forward(self, x) method and could use x directly in all operations.

1 Like