The DataLoader calls into Dataset.__getitem__ to get the current sample and creates a batch out of these samples. It can also use different samplers, a custom collate_fn, multiple workers etc.
The image tensor shape if defined in your Dataset, i.e. how you are loading and preprocessing the images. If you want to resize the tensors to a specific shape, you could use transformation such as torchvision.transforms.Resize inside Dataset.__getitem__.
Thank you for your explanation. What I have done is transformed body signals ( 4hz) into a graph using mathplotlib. I then save them as a png, so I have like 200 png files. I will try later today to load them using your tips. Let’s see how I go.
Note, and it goes without saying I am a very beginner in the world of deep learning.
I am attempting to take up this dataset ImageFolder… and my model expects a Tensor instead of the raw PNG Binary… but when I attempt to add the transform.ToTensor I get an error
File "/home/emcp/anaconda3/envs/pytorch_150/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 61, in __call__
img = t(img)
TypeError: ToTensor() takes no arguments
EDIT:
I found the solution, seems I need to call toTensor()
It depends a bit what the dimensions represent.
If dim0 is the batch dimension and you are only dealing with a single feature, you could try to use transposed convolutions to upsample the single sample.
On the other hand, if both dimensions represent some kind of features, you could try to reshape the input to e.g. an image tensor of [batch_size, 1, 8, 5] and create a custom CNN which could deal with these tiny images.
Note that CNNs try to use the spatial features of your data. If your data doesn’t contain any correlation between neighboring values, I would rather stick to linear layers.
Hi Patrick, I am dealing with body signals as responses from certain stimuli, and I need to use this stimulus to classify a class. So far I manage to get the 1d working Thank so much)
But for example, you can use libraries such as librosa to transform the sound into signals representations. Its is just a time series of 40 or 80 points, but there is a time attached, so they correlate.
When Inspect the images which are a time series, there are not really a lot of similarities in the curves. So what I am doing is trying to normalize and centre all the signals first. Once this is done I am planning to save these images as png in a folder. Load as a picture and then classify using a conv2d.
Are you planning on saving images of the waveform and classify it with a CNN?
This might work, if you see that these waveforms differ enough between classes.
However, I would also recommend to check, if creating spectra wouldn’t work better.
Saved the images as png to try fitting a 2d CNN, really struggling to load a png properly. I think im not that far. I’ve followed the PyTorch tutorial then had a PIL error, got some help and fix that, now another error:
PicklingError: Can’t pickle <class ‘main.MyDataset’>: it’s not the same object as main.MyDataset
Could you use num_workers=0 and check, if the code is working?
If yes, then you might have forgotten the if-clause protection for Windows as explained here.
Sort of worked but having issues with the target variable, I thought by setting the images on folder 1/2/3 respectively would’ve loaded the target correctly.
I followed some of the other comments you had for other people on how to unsqueeze the data and so on, But my target comes out of the loader as an int, not an an ‘I guess’ hot encode PyTorch tensor?
if I print right after input, i get a torch.Size([1, 256, 256]) and the output is just a integer.
I did some transformations, but i think i am doing the wrong thing because my train loss is fixed.
Why are the labels not loaded properly as a long encode when using image folder?
Could you print the shape of your input, output, and target tensors?
By “output is just an integer”, do you mean a scalar tensor or a Python integer?
How did you set the folders to 1/2/3?