You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OK, an update. I found that by changing the model line
Linear(in_features = 1152, out_features=16),
to
Linear(in_features = 256, out_features=16),
It stops erroring on that.
Now it has other errors of a similar type. I will just keep working on that.
I am still interested if someone can explain where these numbers come from and how I could calculate them before hand.
Thanks in advance for anyone looking through this. I have been trying to solve it for a week and have not made any progress in understanding it,
I am trying to work my own version of a program based on:
"Reading multiple csv files in PyTorch" Author: Biswajit Sahoo https://biswajitsahoo1111.github.io/post/reading-multiple-csv-files-in-pytorch/
I loaded that in Jupyter notebook and it works perfectly. They use created ramdom data.
The essence of all below is that I get the error:
RuntimeError: mat1 and mat2 shapes cannot be multiplied (10x256 and 1152x16)
I don't see where 10x256 comes from. I think I understand the 1152x16 form the model.
Below explains how the data is prepared and what the model looks like. This error happens on the code step in the traing loop:
outputs = model(inputs.float())
Sorry about formatting, I don't know how this interface works. I had prepared my question in a Jupyter Notebook file.
I am extracting data from a proprietary application and writing that out in csv file.
The data is converted to normalized and is between 0-1
There are 160 rows in each csv file, not counting the first label line.
There are 1101 files.
They divide into two directories depending on the known outcome. Since the example program got the label from the file name I have used that approach.
I create a dataset this way, the example uses batches of 10 so I am too
There is a bunch of code that puts the files in separate direcctories and works out the labels.
And divides into trainig and test. They also produce a validation set, so I did that too.
The data is then read into 3 data sets and then those are loaded into 3 data loaders.
###The model they use is this. I don;t know if it will work for my solution, but I have not been able to run it yet
model = Sequential(
Conv2d(in_channels = 1, out_channels = 16, kernel_size = 1),
ReLU(),
MaxPool2d(2),
Conv2d(16,32,1),
ReLU(),
MaxPool2d(2),
Flatten(),
Linear(in_features = 1152, out_features=16),
ReLU(),
Linear(16, 1),
Softmax(dim = 1)
)
model.to(dev)
summary(model,input_size = (1,5,32), device = dev.type)
model
####the model looks like this,
I can't see a reason why I get the error from anything in this. It is copied form the article
model = model.float() # We will make all model parameters floats.
epochs = 10
for epoch in range(epochs):
running_loss_train = 0.0
running_loss_val = 0.0
correct_train = 0.0
correct_val = 0.0
num_labels_train = 0.0
num_labels_val = 0.0
I don't know where that number comes from. Is that the flatten step doing that?
On the 10x256 I don't know where 256 comes from.
If someone can point me to where my data shape gets off from what it needs to be that would help a lot.
This is difficult for me since the class was all about images and I need to use sequential data, not images.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
OK, an update. I found that by changing the model line
Linear(in_features = 1152, out_features=16),
to
Linear(in_features = 256, out_features=16),
It stops erroring on that.
Now it has other errors of a similar type. I will just keep working on that.
I am still interested if someone can explain where these numbers come from and how I could calculate them before hand.
Thanks in advance for anyone looking through this. I have been trying to solve it for a week and have not made any progress in understanding it,
I am trying to work my own version of a program based on:
"Reading multiple csv files in PyTorch" Author: Biswajit Sahoo
https://biswajitsahoo1111.github.io/post/reading-multiple-csv-files-in-pytorch/
I loaded that in Jupyter notebook and it works perfectly. They use created ramdom data.
The essence of all below is that I get the error:
RuntimeError: mat1 and mat2 shapes cannot be multiplied (10x256 and 1152x16)
I don't see where 10x256 comes from. I think I understand the 1152x16 form the model.
Below explains how the data is prepared and what the model looks like. This error happens on the code step in the traing loop:
outputs = model(inputs.float())
Sorry about formatting, I don't know how this interface works. I had prepared my question in a Jupyter Notebook file.
I am extracting data from a proprietary application and writing that out in csv file.
The data is converted to normalized and is between 0-1
There are 160 rows in each csv file, not counting the first label line.
There are 1101 files.
They divide into two directories depending on the known outcome. Since the example program got the label from the file name I have used that approach.
I create a dataset this way, the example uses batches of 10 so I am too
check_dataset = CustomDataset(filenames = files, batch_size = 10)_
Checking the shape and labels
for i, (data, labels) in enumerate(check_dataset):
print(data.shape, labels.shape)
print(labels)
if i == 3 break
this produces the output
The dataloader input shape in their example is (10, 1, 32, 32) Their files are much larger.
Maybe this is where I am going wrong.
(10, 1, 5, 32) (10,)
[0 0 0 0 0 0 0 0 0 0]
(10, 1, 5, 32) (10,)
[0 0 0 0 0 0 0 0 0 0]
(10, 1, 5, 32) (10,)
[0 0 0 0 0 0 0 0 0 0]
###make the data;pader from the check_dataset above
dataloader = DataLoader(check_dataset,batch_size = None, shuffle = True)
Checking the dataloader
for i, (data,labels) in enumerate(dataloader):
print(data.shape, labels.shape)
print(labels) # Just to see the labels.
if i == 3: break
this outputs the below
torch.Size([10, 1, 5, 32]) torch.Size([10])
tensor([1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=torch.int32)
torch.Size([10, 1, 5, 32]) torch.Size([10])
tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=torch.int32)
torch.Size([10, 1, 5, 32]) torch.Size([10])
tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=torch.int32)
torch.Size([10, 1, 5, 32]) torch.Size([10])
tensor([1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=torch.int32)
My label indexes are just 0 and 1
There is a bunch of code that puts the files in separate direcctories and works out the labels.
And divides into trainig and test. They also produce a validation set, so I did that too.
The data is then read into 3 data sets and then those are loaded into 3 data loaders.
###The model they use is this. I don;t know if it will work for my solution, but I have not been able to run it yet
model = Sequential(
Conv2d(in_channels = 1, out_channels = 16, kernel_size = 1),
ReLU(),
MaxPool2d(2),
Conv2d(16,32,1),
ReLU(),
MaxPool2d(2),
Flatten(),
Linear(in_features = 1152, out_features=16),
ReLU(),
Linear(16, 1),
Softmax(dim = 1)
)
model.to(dev)
summary(model,input_size = (1,5,32), device = dev.type)
model
####the model looks like this,
Sequential(
(0): Conv2d(1, 16, kernel_size=(1, 1), stride=(1, 1))
(1): ReLU()
(2): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(3): Conv2d(16, 32, kernel_size=(1, 1), stride=(1, 1))
(4): ReLU()
(5): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(6): Flatten(start_dim=1, end_dim=-1)
(7): Linear(in_features=1152, out_features=16, bias=True)
(8): ReLU()
(9): Linear(in_features=16, out_features=1, bias=True)
(10): Softmax(dim=1)
)
this is to show the shape of the inputs from dataloader
for inputs, labels in train_dataloader:
print(inputs.shape)
torch.Size([10, 1, 5, 32])
torch.Size([10, 1, 5, 32])
torch.Size([10, 1, 5, 32])
torch.Size([10, 1, 5, 32])
torch.Size([10, 1, 5, 32])
I can't see a reason why I get the error from anything in this. It is copied form the article
model = model.float() # We will make all model parameters floats.
epochs = 10
for epoch in range(epochs):
running_loss_train = 0.0
running_loss_val = 0.0
correct_train = 0.0
correct_val = 0.0
num_labels_train = 0.0
num_labels_val = 0.0
The error I get is:
RuntimeError: mat1 and mat2 shapes cannot be multiplied (10x256 and 1152x16)
I can see where the model defines the 1152 on the line:
Linear(in_features=1152, out_features=16, bias=True)
I don't know where that number comes from. Is that the flatten step doing that?
On the 10x256 I don't know where 256 comes from.
If someone can point me to where my data shape gets off from what it needs to be that would help a lot.
This is difficult for me since the class was all about images and I need to use sequential data, not images.
Beta Was this translation helpful? Give feedback.
All reactions