timeseriesAI / tsai

Time series Timeseries Deep Learning Machine Learning Python Pytorch fastai | State-of-the-art Deep Learning library for Time Series and Sequences in Pytorch / fastai
https://timeseriesai.github.io/tsai/
Apache License 2.0
5.07k stars 633 forks source link

Model problem with dls.d and dls.c #667

Closed HasnainKhanNiazi closed 1 year ago

HasnainKhanNiazi commented 1 year ago

I am working on a multivariate time series regression problem where I am having 90 features and one output target. I am using TSMetaDataset for creating the dataset along with TSUnwindowedDataset. Now the problem comes when I set the y_func in the TSUnwindowedDataset. Let's say y_func is like this;

def y_func(y): 
    return y.astype('float').mean(1)

Now, let's say the window size is 40 then it will take the mean of all the 40 target values and will output only one target which can be retrieved by dls.c. But with this approach, the dynamics of the targets are being lost and despite the fact that the model is training well or not, we will not be having the dynamics which isn't good in my case as dynamics are really important.

Now, I tried to use dls.d parameter but with the help of that, the model is assuming that each timestamp is having 40 targets as it is giving 40 outputs which shouldn't be the case.

I wanna use the dls.c but at the same time, I want to have dls.c having data of all the 40 timestamps. I hope that my explanation makes sense, if not, I can explain it further. :)

HasnainKhanNiazi commented 1 year ago

While reading some previous issues, I came to know about the creation of custom_head, I will try it and will update here. Thanks

HasnainKhanNiazi commented 1 year ago
 xb, yb = dls.train.one_batch()
 learn.model.backbone(xb.to("cpu")).shape

Above line is giving torch.Size([128, 512, 40]) so I created a create_fc_head with these params;

bs = 128
nf = 512
c_out = 40
seq_len = 40
custom_head = create_fc_head(nf, c_out, seq_len, fc_dropout=0)

I am using TSTPlus with this custom head but this is giving this error TypeError: forward() takes 2 positional arguments but 4 were given, I had a look at the documentation where the head is being created like this, custom_head = partial(create_pool_plus_head, concat_pool=True) this head is working fine but above isn't working.

Any help will be appreciated. Thanks