I need some basic help with setting up my data for training

TorchedEarthCampaign: <p>I think I need some help in preparing my numpy dataset for training with Torch.</p>
<p>I have multiple arrays of dimension <code>[10000, 100, 24]</code>, which corresponds to <code>(time_index, player, playerdata)</code>. The array isn’t 100% filled and has many zeroes, but I suspect that’s another issue, and I hear I can use a dropout layer later.</p>
<p>I have this code to try and train a model:</p>
<pre><code class="lang-auto">...
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
def ConvertndArraytoTensor(ndarray):
    return torch.from_numpy(ndarray).float().to(DEVICE)

def PytorchTrainOnData(data, model, optimizer, loss_fn, epochs, batch_size, device):
    for epoch in range(epochs):
        for batch in data:
            batch = ConvertndArraytoTensor(batch)
            optimizer.zero_grad()
            output = model(batch)
            loss = loss_fn(output, batch)
            loss.backward()
            optimizer.step()
        print("Epoch: " + str(epoch) + " Loss: " + str(loss))

def DefineTorchModel(input_size, hidden_size, output_size):
    model = torch.nn.Sequential(
        torch.nn.Linear(input_size, hidden_size),
        torch.nn.ReLU(),
        torch.nn.Linear(hidden_size, output_size),
    )
    model.to(DEVICE)
    return model

model = DefineTorchModel(input_size=3, hidden_size=10, output_size=3)
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
loss_fn = torch.nn.MSELoss()
epochs = 10
batch_size = 1
PytorchTrainOnData(data, model, optimizer, loss_fn, epochs, batch_size, DEVICE)
</code></pre>
<p>And I get this error:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "/home/user/git/ai/TrainTrackingModel/train_pytorch.py", line 48, in &lt;module&gt;
    PytorchTrainOnData(data, model, optimizer, loss_fn, epochs, batch_size, device)
  File "/home/user/git/ai/TrainTrackingModel/train_pytorch.py", line 28, in PytorchTrainOnData
    output = model(batch)
  File "/home/user/Programs/miniconda3/envs/pytorch/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/user/Programs/miniconda3/envs/pytorch/lib/python3.9/site-packages/torch/nn/modules/container.py", line 141, in forward
    input = module(input)
  File "/home/user/Programs/miniconda3/envs/pytorch/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/user/Programs/miniconda3/envs/pytorch/lib/python3.9/site-packages/torch/nn/modules/linear.py", line 103, in forward
    return F.linear(input, self.weight, self.bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (1000000x24 and 3x10)

Process finished with exit code 1
</code></pre>
<p>My goal is to train a model that can make predictions about what would happen in the next <code>time_index</code>, but I think I’m making basic mistakes about how to prepare the data and batch it.</p>
<p>Can someone suggest what I should fix?</p>

ptrblck: <p>Your current input has the shape <code>[batch_size=10000, seq=100, in_features=24]</code> while the model uses a linear layer with <code>in_features=input_size=3</code> which doesn’t match the feature dimension.<br>
Change it to <code>24</code> and it should work.</p>