I have now been able to train my model. I am now attempting to use the model to make predictions, however, once I pass the data tensor to the model:
import torch
from NNModel import NeuralNetwork
import numpy as np
from numpy import genfromtxt
model = NeuralNetwork()
model.load_state_dict(torch.load("model_100Epoch.pth"))
print(model)
data_path = "5.csv"
g = genfromtxt(data_path, delimiter=',')
g = g[:,1]
window_size = 10
window = np.divide(np.ones(window_size), window_size)
g_s = np.convolve(g, window, mode='valid')
g_s = np.multiply(g_s, -1)
g_s = np.divide(np.subtract(g_s, np.min(g_s)), np.max(g_s))
idx = np.argmax(g_s)
g_c = torch.from_numpy(g_s[(idx - 1200):(idx + 1200)]).to(torch.float32)
model.eval()
results = model(g_c)
I get the following error:
NeuralNetwork(
(flatten): Flatten(start_dim=1, end_dim=-1)
(tanhshrink_stack): Sequential(
(0): Linear(in_features=2400, out_features=1200, bias=True)
(1): Linear(in_features=1200, out_features=600, bias=True)
(2): Linear(in_features=600, out_features=300, bias=True)
(3): Linear(in_features=300, out_features=150, bias=True)
(4): Linear(in_features=150, out_features=75, bias=True)
(5): Linear(in_features=75, out_features=38, bias=True)
(6): Linear(in_features=38, out_features=19, bias=True)
(7): Linear(in_features=19, out_features=10, bias=True)
(8): Linear(in_features=10, out_features=5, bias=True)
(9): Linear(in_features=5, out_features=2, bias=True)
)
)
Traceback (most recent call last):
File ".\Measure.py", line 23, in <module>
results = model(g_c)
.\AppData\Roaming\Python\Python310\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
return forward_call(*input, **kwargs)
File ".\NNModel.py", line 22, in forward
x = self.flatten(x)
.\AppData\Roaming\Python\Python310\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
return forward_call(*input, **kwargs)
.\AppData\Roaming\Python\Python310\site-packages\torch\nn\modules\flatten.py", line 46, in forward
return input.flatten(self.start_dim, self.end_dim)
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)
What does this error mean? Am I passing the data to the model incorrectly?