moment-timeseries-foundation-model / moment

MOMENT: A Family of Open Time-series Foundation Models
https://moment-timeseries-foundation-model.github.io/
MIT License
319 stars 51 forks source link

Easy tutorial on train on TOY Dataset #30

Open omaruno opened 3 months ago

omaruno commented 3 months ago

I have the following dataset

X = np.array([[(1,2,3,3,1),(3,2,1,3,2),(3,2,2,3,3),(2,2,1,1,2),(2,1,1,1,1)],
              [(4,5,6,4,4),(5,6,4,3,2),(5,5,6,1,3),(3,3,3,2,2),(2,3,3,2,1)],
              [(7,8,9,4,7),(7,7,6,7,8),(5,8,7,8,8),(6,7,6,7,8),(5,7,6,6,6)],
              [(7,8,9,8,6),(6,6,7,8,6),(8,7,8,8,8),(8,6,7,8,7),(8,6,7,8,8)],
              [(4,5,6,5,5),(5,5,5,6,4),(6,5,5,5,6),(4,4,3,3,3),(5,5,4,4,5)],
              [(4,5,6,5,5),(5,5,5,6,4),(6,5,5,5,6),(4,4,3,3,3),(5,5,4,4,5)],
              [(1,2,3,3,1),(3,2,1,3,2),(3,2,2,3,3),(2,2,1,1,2),(2,1,1,1,1)]])
y = np.array([0, 1, 2, 2, 1, 1, 0])

I want to train the model on X data and the corresponding Label y. This toy dataset is exacly how is structured my bigger and real dataset, for if it work here it works also on my real dataset. Thanks for the help.. I am convertin the numpy array to Pytorch dataset in the following way:

X_tensor = torch.from_numpy(X).float()
y_tensor = torch.from_numpy(y).long()
model.train()
outputs = model(X_tensor).
Error encountered
RuntimeError                              Traceback (most recent call last)
[<ipython-input-63-0b52f5a3a427>](https://localhost:8080/#) in <cell line: 8>()
      6 for el in x:
      7   print(el)
----> 8 output = model(x)
      9 pprint(output)

3 frames
[/usr/local/lib/python3.10/dist-packages/momentfm/utils/masking.py](https://localhost:8080/#) in convert_seq_to_patch_view(mask, patch_len, stride)
     26         """
     27         stride = patch_len if stride is None else stride
---> 28         mask = mask.unfold(dimension=-1, size=patch_len, step=stride)
     29         # mask : [batch_size x n_patches x patch_len]
     30         return (mask.sum(dim=-1) == patch_len).long()

RuntimeError: maximum size for tensor at dimension 1 is 5 but size is 8