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.16k stars 644 forks source link

MiniRocket Tutorial Notebook #162

Closed YojoNick closed 3 years ago

YojoNick commented 3 years ago

I'm trying to run this notebook: https://github.com/timeseriesAI/tsai/blob/main/tutorial_nbs/10_Time_Series_Classification_and_Regression_with_MiniRocket.ipynb

I wanted to execute the code relevant to the Pytorch implementation with any number of samples.

I executed the 2nd cell, which returned this for the libraries installed - tsai : 0.2.18 fastai : 2.4.1 fastcore : 1.3.20 torch : 1.9.0+cu111

Then, I skipped down to the cell titled "Pytorch implementation (any # samples)".

I was able to successfully execute this block:

# Create the MiniRocket features and store them in memory.
dsid = 'LSST'
X, y, splits = get_UCR_data(dsid, split_data=False)

But then trying to execute the cell after that resulted in an error:

mrf = MiniRocketFeatures(X.shape[1], X.shape[2]).to(default_device())
X_train = X[splits[0]]
mrf.fit(X_train)
X_feat = get_minirocket_features(X, mrf, chunksize=1024, to_np=True)
X_feat.shape, type(X_feat)

Error:

/usr/local/lib/python3.6/dist-packages/tsai/models/MINIROCKET_Pytorch.py in forward(self, x) 69 70 # Convolution ---> 71 C = F.conv1d(x, self.kernels, padding=padding, dilation=dilation, groups=self.c_in) 72 if self.c_in > 1: # multivariate 73 C = C.reshape(x.shape[0], self.c_in, self.num_kernels, -1)

TypeError: conv1d() received an invalid combination of arguments - got (numpy.ndarray, Parameter, groups=int, padding=numpy.int64, dilation=numpy.int32), but expected one of:

  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)

Any idea what I'm doing wrong?

Thanks in advance for any help you can provide.

oguiza commented 3 years ago

Hi @YojoNick, I've rerun the notebook in Colab based on your previous message and I didn't get any issues. I guess the only difference is that I'm using tsai 0.2.19. Could you upgrade tsaiusing this:

## NOTE: UNCOMMENT AND RUN THIS CELL IF YOU NEED TO INSTALL/ UPGRADE TSAI
stable = False # True: latest version from github, False: stable version in pip
if stable: 
    !pip install tsai -U >> /dev/null
else:      
    !pip install git+https://github.com/timeseriesAI/tsai.git -U >> /dev/null

## NOTE: REMEMBER TO RESTART YOUR RUNTIME ONCE THE INSTALLATION IS FINISHED

If you leave stable = False it will upgrade it to the same version. If you still have any issues, you'll need to send me the full stack trace.

YojoNick commented 3 years ago

Hi @oguiza !

tl-dr: That worked!

Details: Thank you for the fast response.

When I try to run this:

### NOTE: UNCOMMENT AND RUN THIS CELL IF YOU NEED TO INSTALL/ UPGRADE TSAI
stable = False # True: latest version from github, False: stable version in pip
if stable: 
    !pip install tsai -U >> /dev/null
else:      
    !pip install git+https://github.com/timeseriesAI/tsai.git -U >> /dev/null

### NOTE: REMEMBER TO RESTART YOUR RUNTIME ONCE THE INSTALLATION IS FINISHED

I get this:

Running command git clone -q https://github.com/timeseriesAI/tsai.git /tmp/pip-req-build-2dfyzmsj ERROR: Command errored out with exit status 1: command: /usr/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-2dfyzmsj/setup.py'"'"'; file='"'"'/tmp/pip-req-build-2dfyzmsj/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-j_b4tw6v cwd: /tmp/pip-req-build-2dfyzmsj/ Complete output (7 lines): Traceback (most recent call last): File "", line 1, in File "/tmp/pip-req-build-2dfyzmsj/setup.py", line 39, in long_description = open('README.md').read() File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 714: ordinal not in range(128)

WARNING: Discarding git+https://github.com/timeseriesAI/tsai.git. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

However, this somehow fixes it and gets the command to run:

# ## NOTE: UNCOMMENT AND RUN THIS CELL IF YOU NEED TO INSTALL/ UPGRADE TSAI
stable = False # True: latest version from github, False: stable version in pip
if stable: 
    !pip3 install tsai -U >> /dev/null
else:      
    !LC_ALL=C.UTF-8 pip3 install git+https://github.com/timeseriesAI/tsai.git -U >> /dev/null

# ## NOTE: REMEMBER TO RESTART YOUR RUNTIME ONCE THE INSTALLATION IS FINISHED

Now when I run this:

from tsai.all import *
print('tsai       :', tsai.__version__)
print('fastai     :', fastai.__version__)
print('fastcore   :', fastcore.__version__)
print('torch      :', torch.__version__)

I get this:

tsai : 0.2.19 fastai : 2.4.1 fastcore : 1.3.20 torch : 1.9.0+cu111

Then when I run this:

# Create the MiniRocket features and store them in memory.
dsid = 'LSST'
X, y, splits = get_UCR_data(dsid, split_data=False)

mrf = MiniRocketFeatures(X.shape[1], X.shape[2]).to(default_device())
X_train = X[splits[0]]
mrf.fit(X_train)
X_feat = get_minirocket_features(X, mrf, chunksize=1024, to_np=True)
X_feat.shape, type(X_feat)

I get this:

((4925, 9996, 1), numpy.ndarray)

The rest of the notebook also works without any errors.

YojoNick commented 3 years ago

On the off chance some other person on the internet winds up in this thread with the same issue as me, this is where I found the fix to install tsai via pip: https://github.com/mroosmalen/nanosv/issues/45

This error happened to me on Ubuntu 18.04.

If you are using docker, add something like this to your docker container (from the above): RUN LC_ALL=C.UTF-8 python3.6 -m pip install git+https://github.com/timeseriesAI/tsai.git -U >> /dev/null

oguiza commented 3 years ago

Thanks for documenting this @YojoNick ! Should I close this issue then?

YojoNick commented 3 years ago

Yes please. Thanks again for your help @oguiza :)