tsai icon indicating copy to clipboard operation
tsai copied to clipboard

AttributeError: Exception occured in `ShowGraph` when calling event `after_epoch`: 'NoneType' object has no attribute 'update'

Open sunmingliu opened this issue 2 years ago • 10 comments

from tsai.all import * my_setup() regression_list dsid = 'AppliancesEnergy' X, y, splits = get_regression_data(dsid, split_data=False) X.shape, y.shape, y[:10] check_data(X, y, splits) tfms = [None, [TSRegression()]] batch_tfms = TSStandardize(by_sample=True, by_var=True) dls = get_ts_dls(X, y, splits=splits, tfms=tfms, batch_tfms=batch_tfms, bs=128) dls.one_batch() dls.c dls.show_batch() learn = ts_learner(dls, InceptionTime, metrics=[mae, rmse], cbs=ShowGraph()) learn.lr_find() learn.loss_func learn = ts_learner(dls, InceptionTime, metrics=[mae, rmse], cbs=ShowGraph()) learn.fit_one_cycle(50, 1e-2)

epoch train_loss valid_loss mae _rmse time
0 212.116226 199.891907 13.711620 14.138313 00:00
Figure(600x400) Traceback (most recent call last): File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\contextlib.py", line 131, in exit self.gen.throw(type, value, traceback) File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastai\learner.py", line 132, in added_cbs try: yield File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastai\learner.py", line 222, in fit self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup) File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastai\learner.py", line 164, in with_events try: self(f'before{event_type}'); f() File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastai\learner.py", line 213, in _do_fit self._with_events(self._do_epoch, 'epoch', CancelEpochException) File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastai\learner.py", line 166, in with_events self(f'after{event_type}'); final() File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastai\learner.py", line 142, in call def call(self, event_name): L(event_name).map(self._call_one) File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastcore\foundation.py", line 155, in map def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs)) File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastcore\basics.py", line 780, in map_ex return list(res) File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastcore\basics.py", line 765, in call return self.func(*fargs, **kwargs) File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastai\learner.py", line 146, in _call_one for cb in self.cbs.sorted('order'): cb(event_name) File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\fastai\callback\core.py", line 57, in call try: res = getattr(self, event_name, noop)() File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\tsai-0.3.1-py3.8.egg\tsai\callback\core.py", line 94, in after_epoch self.update_graph([(iters, rec.losses), (self.nb_batches, val_losses)], x_bounds, y_bounds) File "C:\softwares\study\Anaconda\path\envs\tsai_0.3.1\lib\site-packages\tsai-0.3.1-py3.8.egg\tsai\callback\core.py", line 113, in update_graph self.graph_out.update(self.graph_ax.figure) AttributeError: Exception occured in ShowGraph when calling event after_epoch: 'NoneType' object has no attribute 'update' python-BaseException

sunmingliu avatar May 22 '22 03:05 sunmingliu

Hi @sunmingliu, I tried to reproduce your issue but the code works well (see gist). You may need to upgrade tsai to the most recent version.

oguiza avatar May 22 '22 07:05 oguiza

Hi, @oguiza , I installed tsai-0.3.2 with python==3.8. Could you please tell me your tsai and python version?

C:\softwares\study\Anaconda\path\envs\tsai_0.3.2\python.exe D:/projects/20220304/CloudGame/regression.py os : Windows-10-10.0.19041-SP0 python : 3.8.0 tsai : 0.3.2 fastai : 2.5.6 fastcore : 1.4.3 torch : 1.11.0+cpu device : cpu cpu cores : 20 RAM : 31.75 GB GPU memory : [6.0] GB regression datasets: ['AppliancesEnergy', 'AustraliaRainfall', 'BeijingPM10Quality', 'BeijingPM25Quality', 'BenzeneConcentration', 'Covid3Month', 'FloodModeling1', 'FloodModeling2', 'FloodModeling3', 'HouseholdPowerConsumption1', 'HouseholdPowerConsumption2', 'IEEEPPG', 'LiveFuelMoistureContent', 'NewsHeadlineSentiment', 'NewsTitleSentiment'] X - shape: [137 samples x 24 features x 144 timesteps] type: memmap dtype:float64 isnan: 0 y - shape: (137,) type: memmap dtype:float64 isnan: 0 splits - n_splits: 2 shape: [95, 42] overlap: False epoch train_loss valid_loss mae _rmse time
0 233.184723 206.332840 13.945362 14.364290 00:00
Figure(600x400)

sunmingliu avatar May 22 '22 09:05 sunmingliu

I usually use this:

# **************** UNCOMMENT AND RUN THIS CELL IF YOU NEED TO INSTALL/ UPGRADE TSAI ****************
stable = False # Set to True for latest pip version or False for main branch in GitHub
!pip install {"tsai -U" if stable else "git+https://github.com/timeseriesAI/tsai.git"} >> /dev/null

I run it in colab. These is the setup (you can just run my_setup() to get yours):

os             : Linux-5.4.188+-x86_64-with-Ubuntu-18.04-bionic
python         : 3.7.13
tsai           : 0.3.2
fastai         : 2.6.3
fastcore       : 1.4.3
torch          : 1.11.0+cu113
device         : 1 gpu (['Tesla P100-PCIE-16GB'])
cpu cores      : 2
RAM            : 12.68 GB
GPU memory     : [15.9] GB

oguiza avatar May 22 '22 11:05 oguiza

I have tried different tsai versions on windows+pycharm. This error always appeared. I think something is wrong with IPython because it is always interrupted where self.graph_out.update(self.graph_ax.figure). I commented these codes and it ran well. os : Windows-10-10.0.19041-SP0 python : 3.8.0 tsai : 0.3.2 fastai : 2.5.6 fastcore : 1.4.3 torch : 1.11.0+cpu device : cpu cpu cores : 20 RAM : 31.75 GB GPU memory : [6.0] GB

sunmingliu avatar May 22 '22 12:05 sunmingliu

I encountered the same problem, tried various versions of the library, but it didn't work

guang7400613 avatar Jun 01 '22 15:06 guang7400613

sunmingliu's solution works for me.

I have tried different tsai versions on windows+pycharm. This error always appeared. I think something is wrong with IPython because it is always interrupted where self.graph_out.update(self.graph_ax.figure). I commented these codes and it ran well. os : Windows-10-10.0.19041-SP0 python : 3.8.0 tsai : 0.3.2 fastai : 2.5.6 fastcore : 1.4.3 torch : 1.11.0+cpu device : cpu cpu cores : 20 RAM : 31.75 GB GPU memory : [6.0] GB

huameichen0523 avatar Jun 21 '22 19:06 huameichen0523

Could anybody please confirm if this is still an open issue? Otherwise, I'll close it.

oguiza avatar Aug 18 '22 10:08 oguiza

Could anybody please confirm if this is still an open issue? Otherwise, I'll close it.

It's still an open issue! I'm facing the same error although using the library versions suggested above on Linux.

parshinsh avatar Aug 24 '22 16:08 parshinsh

I‘m also facing the same issue using tsai 0.3.1, python 3.8 and pytorch 1.10.1

takuyara avatar Aug 25 '22 15:08 takuyara

I also encountered the same problem mentioned in the issue. The solution proposed by @sunmingliu also works in my case.

The commented code location: callback\core.py line113

os : Windows-10-10.0.19041-SP0 python : 3.8.5 tsai : 0.3.1 fastai : 2.7.9 fastcore : 1.5.22 torch : 1.8.1+cu111 device : 1 gpu (['GeForce MX250']) cpu cores : 8 RAM : 11.82 GB GPU memory : [2.0] GB

hairtail-cheng avatar Aug 28 '22 16:08 hairtail-cheng

I also encountered the same problem mentioned in the issue. The solution proposed by @sunmingliu also works in my case. However, how can I view the figure after commenting the code?

yiyang129 avatar Sep 28 '22 03:09 yiyang129

Hi @hairtail-cheng , @sunmingliu , @huameichen0523 , When you say that commenting out line 113 (115 in the GitHub version 0.3.5) in callback\core.py works for you, do you mean the chart is still updated correctly? I've tried commenting out that line and the code runs, but I get no chart as expected.

There seems to be an open issue in fastai that might be related to this one: https://github.com/fastai/fastai/issues/3814

oguiza avatar Dec 07 '22 09:12 oguiza

It went wrong because self.graph_out is None. If you are asking why it is None, than I have no idea. But,instead of commenting it out, you can call it when it is not None by adding a if statement. Then it should work properly when it is not None.

Hope it helps.

On Wed, Dec 7, 2022, 4:54 AM Ignacio Oguiza @.***> wrote:

Hi @hairtail-cheng https://github.com/hairtail-cheng , @sunmingliu https://github.com/sunmingliu , @huameichen0523 https://github.com/huameichen0523 , When you say that commenting out line 113 (115 in the GitHub version 0.3.5) in callback\core.py works for you, do you mean the chart is still updated correctly? I've tried commenting out that line and the code runs, but I get no chart as expected.

There seems to be an open issue in fastai that might be related to this one: fastai/fastai#3814 https://github.com/fastai/fastai/issues/3814

— Reply to this email directly, view it on GitHub https://github.com/timeseriesAI/tsai/issues/518#issuecomment-1340679394, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG2APC2FTQG5KL2ZYY3RZ2LWMBNHDANCNFSM5WSXSR2Q . You are receiving this because you were mentioned.Message ID: @.***>

huameichen0523 avatar Dec 07 '22 11:12 huameichen0523

Thanks @huameichen0523 for your quick reply. My question is if the code when you modify the code adding an if statement:

if self.graph_out is not None:
            self.graph_out.update(self.graph_ax.figure)

does it still produce a chart that is updated with every epoch?

oguiza avatar Dec 07 '22 15:12 oguiza

Closed due to lack of response.

oguiza avatar Jan 19 '23 13:01 oguiza