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

TypeError: __init__() got an unexpected keyword argument 'custom_head' on models with Plus #672

Closed AdoNunes closed 1 year ago

AdoNunes commented 1 year ago

For some reason, ts_learner passes the argument custom_head (my labels are 1D, but I see dls.d = 2).

So it is expected that models without the plus don't have cutom_head argument, however these models don't have the argument either:

FCNPlus MiniRocketPlus InceptionRocketPlus xresnet1d18plus xresnet1d34plus xresnet1d50plus xresnet1d101plus xresnet1d152plus xresnet1d18_deepplus xresnet1d34_deepplus xresnet1d50_deepplus xresnet1d18_deeperplus xresnet1d34_deeperplus xresnet1d50_deeperplus XceptionTimePlus

If the models rather than being called with ts_learner, they are called as

model = modelcalss(args) 
learn = ts_learner(dls, model,..)

then there is no issue.

The problem gets fixed if in the model class init args a **kwargs is passed.

oguiza commented 1 year ago

Hi @AdoNunes, Can you please share a code snippet to reproduce this issue? You mention you are using 1D labels, but dls.d is 2. That's pretty strange. And if that's the case, it's a bug.

cvonholly commented 1 year ago

I have the sameproblem, when calling learn = ts_learner(dls, InceptionTime, metrics=[mae, rmse], cbs=ShowGraph())

I copied my data (just 1 dimensional time series) into the notebook 04 from the intros

I get the error


TypeError Traceback (most recent call last)

in ----> 1 learn = ts_learner(dls, InceptionTime, metrics=[mae, rmse], cbs=ShowGraph()) 2 learn.lr_find()

6 frames

/usr/local/lib/python3.9/dist-packages/fastcore/meta.py in call(cls, *args, kwargs) 38 if type(res)==cls: 39 if hasattr(res,'pre_init'): res.pre_init(*args,*kwargs) ---> 40 res.init(args,kwargs) 41 if hasattr(res,'post_init'): res.post_init(*args,**kwargs) 42 return res

TypeError: init() got an unexpected keyword argument 'custom_head'

oguiza commented 1 year ago

@AdoNunes , @cvonholly , I still need a code snippet to reproduce this issue. Otherwise, I won't be able to fix it. You can use dummy data (torch.rand(shape of your data)).

qwreas commented 1 year ago

Here’s a numerical case. And I also have questions about ResNetPlus.

from tsai.all import *

X=torch.rand(500,20,200) y=torch.rand(500,1)

splits = TimeSplitter(100)(y)

batch_tfms = TSStandardize() ''' OK for RNNPluses, InceptionTimePlus, XCMPlus, TSTPlus '''

fcst = TSForecaster(X, y, splits=splits, path='models', batch_tfms=batch_tfms, bs=133, arch=InceptionTimePlus, metrics=mse, cbs=ShowGraph())

''' init() got an unexpected keyword argument 'custom_head' XceptionTime, FCN, InceptionRocket, MiniRocket can be solved by adding **kwargs to init() '''

fcst = TSForecaster(X, y, splits=splits, path='models', batch_tfms=batch_tfms, bs=133, arch=FCNPlus, metrics=mse, cbs=ShowGraph())

''' init() missing 1 required positional argument: 'seq_len' ResNet '''

fcst = TSForecaster(X, y, splits=splits, path='models', batch_tfms=batch_tfms, bs=133, arch=ResNetPlus, metrics=mse, cbs=ShowGraph())

''' 'ResNetPlus' object has no attribute 'name' ResNet ''' fcst = TSForecaster(X, y, splits=splits, path='models', batch_tfms=batch_tfms, bs=133, arch=ResNetPlus(c_in=20, c_out=1, seq_len=200), metrics=mse, cbs=ShowGraph())

fcst.fit_one_cycle(2, 1e-3)

oguiza commented 1 year ago

Hi all, I have a few clarifications:

  1. There was an issue in tsai=0.3.5 which has been fixed in GitHub. If you install it using:

    pip install git+https://github.com/timeseriesAI/tsai.git
  2. InceptionRocket doesn't exist in tsai. This is a model I created and there's only a InceptionRocketPlus version.

  3. Whenever you use a y with > 1 dimensions, you should use a model ending in Plus. This is true even if y has a shape=(500,1) like in the last example.

  4. There are 5 architectures that don't work with multidimensional targets (ResNetPlus, FCNPlus, InceptionRocketPlus, MiniRocketPlus and XResNet1dPlus). I've created a new issue (#718) to assess if it's possible to make them work with this type of targets. You can use this quick test to check which architectures pass/ fail when using multidimensional targets:

    
    from tsai.basics import *

X=torch.rand(16,2,200) y=torch.rand(16, 1) splits = TimeSplitter(show_plot=False)(y)

pass_test = [] fail_test = [] for arch in ["ResNetPlus", "RNNPlus", "LSTMPlus", "InceptionTimePlus", "XCMPlus", "TSTPlus", "XceptionTimePlus", "FCNPlus", "InceptionRocketPlus", "MiniRocketPlus"]: try: tfms = [None, TSRegression()] batch_tfms = TSStandardize() fcst = TSForecaster(X, y, splits=splits, path='models', tfms=tfms, batch_tfms=batch_tfms, arch=arch, metrics=mse) with ContextManagers([fcst.no_bar(), fcst.no_logging()]): fcst.fit_one_cycle(1, 1e-3) pass_test.append(arch) except Exception as e: print(arch, e) fail_test.append(arch)

oguiza commented 1 year ago

Based on what I commented before, I prefer to close this issue and track the resolution in #718