binarize input for pytorch
may I ask how to make data loaded in pytorch become binarized once it is loaded? 
Like Tensorflow can done this through:

train_data  = mnist.input_data.read_data_sets(data_directory, one_hot=True)


How can pytorch achieve the one_hot=True effect. 

The data_loader I have now is:

torch.set_default_tensor_type('torch.FloatTensor')
train_loader = torch.utils.data.DataLoader(
        datasets.MNIST('data/', train=True, download=True,
                       transform=transforms.Compose([
                         # transforms.RandomHorizontalFlip(),
                           transforms.ToTensor()])),
        batch_size=batch_size, shuffle=False)


I want to make data in train_loader be binarized. 
Now what I am doing is: After loading the data, 

for data,_ in train_loader:
    torch.round(data) 
    data = Variable(data)


Use the torch.round() function. Is this correct?

The one-hot encoding idea is used for classification. It sounds like you are trying to create an autoencoder perhaps.

If you are creating an autoencoder then there is no need to round as BCELoss can handle values between 0 and 1. Note when training it is better not to apply the sigmoid and instead to use BCELossWithLogits as it provides numerical stability.

Here is an example of an autoencoder with MNIST

If instead you are attempting to do classifcation then there is no need for a one hot vector, you simply output the number of neurons equal to the number of classes i.e for MNIST output 10 neurons and then pass it to CrossEntropyLoss along with a LongTensor with corresponding expected class values

Here is an example of classification on MNIST
