How to convert a ByteTensor into an image tensor?
I am converting images into binary files via matlab and try to load the binary matlab vectors (1d) into python and convert them into ByteTensors:
img = np.fromfile(dir_train + image_name)
img = torch.ByteTensor(img) 

This works fine. The ByteTensors are of the dimension 2. Afterwards I would like to convert them back into into images, like reshaping them, because the neural network (resnet18) needs 4-dimensional tensors. What is the best way to do that?
At the moment my network needs tensors of the dimension [64, 3, 7, 7], but the ByteTensors are [8, 1914].

I solved it this way:
img = np.fromfile(dir_train + image_name, 'bool')    # read in the binary file
img = img.reshape(1, 350, 350)    # reshape binary file
img = torch.ByteTensor(img)    # convert to ByteTensor
img = img.type(torch.FloatTensor)    # convert to FloatTensor

I think there is no better way than typecasting the ByteTensor. On top of that I changed the first convolutional layer of my network architecture (resnet18) in order to make sure, the input expected input matches the convertet binary input.
resnet18.conv1 = nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3, bias=False) 

