Dear friends, I have a train data X_train which is a numpy array with dimension of (36000,15,15,30), where 36000 is number of image samples, 15 is height of image,15 is width of image and 30 is the number of channels in a image. y_train is the integer array of shape (36000,1) that contains the class labels of corresponding train images. I am new to PyTorch. Can any one please suggest me the procedure for giving this numpy arrays as input to the CNN model and train the model. I would also request to suggest me how to evaluate the model after the training process.
You can transform the numpy array to a PyTorch tensor via
tensor = torch.from_numpy(array) and would need to permute it afterwards, as PyTorch layers expect the input in the channels-first memory layout via:
tensor = tensor.permute(0, 3, 1, 2).
If you are dealing with a multi-class classification, your target should have the shape
[batch_size] without any additional dimension, so you could use
target = torch.from_numpy(target_array).squeeze(1) to remove
Once this is done, you can directly pass the input data to the model or use a
TensorDataset or a custom
Dataset as described here.
I would generally recommend to take a look at the tutorials for a general introduction.