early-stopping-pytorch icon indicating copy to clipboard operation
early-stopping-pytorch copied to clipboard

ImportError: cannot import name 'EarlyStopping' from 'pytorchtools'

Open HripsimeS opened this issue 3 years ago • 9 comments

Hello @Bjarten

I am trying to use your approach for the early stopping. I installed pytorchtools by using "pip install pytorchtools" Then I wanted to import EarlyStopping using "from pytorchtools import EarlyStopping", but eventually I received the following error:

ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (C:\Users\Name\anaconda3\envs\abys\lib\site-packages\pytorchtools_init_.py)

Can you please let me know why I am receiving this error and how to fix it potentially? Thank you in advance!

HripsimeS avatar Apr 11 '22 14:04 HripsimeS

Hi Hripsime,

You can not download this code using pip. You need to download this project to your computer and install the dependencies using the requirements.txt file to use it.

Best regards, Bjarte


From: Hripsime Snkhchyan @.> Sent: Monday, April 11, 2022 4:53 PM To: Bjarten/early-stopping-pytorch @.> Cc: Bjarte Mehus Sunde @.>; Mention @.> Subject: [Bjarten/early-stopping-pytorch] ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (Issue #15)

Hello @Bjartenhttps://github.com/Bjarten

I am trying to use your approach for the early stopping. I installed pytorchtools by using "pip install pytorchtools" Then I wanted to import EarlyStopping using "from pytorchtools import EarlyStopping", but eventually I received the following error:

ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (C:\Users\Name\anaconda3\envs\abys\lib\site-packages\pytorchtools_init_.py)

Can you please let me know why I am receiving this error and how to fix it potentially? Thank you in advance!

— Reply to this email directly, view it on GitHubhttps://github.com/Bjarten/early-stopping-pytorch/issues/15, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA5QP46TVLNGPQPAAMMSA53VEQ4GRANCNFSM5TDO5M5Q. You are receiving this because you were mentioned.Message ID: @.***>

Bjarten avatar Apr 15 '22 07:04 Bjarten

@Bjarten thanks for your reply! I downloaded the project and installed the dependencies using pip install -r requirements.txt. But when I do "from pytorchtools import EarlyStopping", it gives me this error ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (C:\Users\Hripsime\anaconda3\envs\abys\lib\site-packages\pytorchtools_init_.py)

Can you please let me know how to fix this issue to make it work eventually. Thanks in advance!

HripsimeS avatar Apr 19 '22 15:04 HripsimeS

You need to add pytorchtools.py to the same folder as the python script you are running, or add it's location to the PYTHONPATH environmental variable.

Bjarte

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Hripsime Snkhchyan @.> Sent: Tuesday, April 19, 2022 5:15:20 PM To: Bjarten/early-stopping-pytorch @.> Cc: Bjarte Mehus Sunde @.>; Mention @.> Subject: Re: [Bjarten/early-stopping-pytorch] ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (Issue #15)

@Bjartenhttps://github.com/Bjarten thanks for your reply! I downloaded the project and installed the dependencies using pip install -r requirements.txt. But when I do "from pytorchtools import EarlyStopping", it gives me this error ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (C:\Users\Name\anaconda3\envs\abys\lib\site-packages\pytorchtools_init_.py)

Can you please let me know how to fix this issue to make it work eventually. Thanks in advance!

— Reply to this email directly, view it on GitHubhttps://github.com/Bjarten/early-stopping-pytorch/issues/15#issuecomment-1102777335, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA5QP475ARIXLXM3G5RKCVLVF3EYRANCNFSM5TDO5M5Q. You are receiving this because you were mentioned.Message ID: @.***>

Bjarten avatar Apr 19 '22 15:04 Bjarten

Yes, you can try that

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Hripsime Snkhchyan @.> Sent: Tuesday, April 19, 2022 5:42:36 PM To: Bjarten/early-stopping-pytorch @.> Cc: Bjarte Mehus Sunde @.>; Mention @.> Subject: Re: [Bjarten/early-stopping-pytorch] ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (Issue #15)

@Bjartenhttps://github.com/Bjarten thanks for your quick reply. For the moment I am using a Jupyter Notebook file (.ipynb) and I need to add the pytorchtools.py file in the same folder where my notebook is located?

— Reply to this email directly, view it on GitHubhttps://github.com/Bjarten/early-stopping-pytorch/issues/15#issuecomment-1102806803, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA5QP42YDHE7O4KYDX65WG3VF3H6ZANCNFSM5TDO5M5Q. You are receiving this because you were mentioned.Message ID: @.***>

Bjarten avatar Apr 19 '22 15:04 Bjarten

@Bjarten thanks a lot, it worked eventually when I moved pytorchtools.py file to the corresponding folder 👍 🥇

HripsimeS avatar Apr 19 '22 16:04 HripsimeS

Great! Glad to hear you got it to work.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Hripsime Snkhchyan @.> Sent: Tuesday, April 19, 2022 6:56:21 PM To: Bjarten/early-stopping-pytorch @.> Cc: Bjarte Mehus Sunde @.>; Mention @.> Subject: Re: [Bjarten/early-stopping-pytorch] ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (Issue #15)

@Bjartenhttps://github.com/Bjarten thanks a lot, it worked eventually when I moved pytorchtools.py file to the corresponding folder 👍 🥇

— Reply to this email directly, view it on GitHubhttps://github.com/Bjarten/early-stopping-pytorch/issues/15#issuecomment-1102877805, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA5QP43GRWXURXLS5SGKPPDVF3QTLANCNFSM5TDO5M5Q. You are receiving this because you were mentioned.Message ID: @.***>

Bjarten avatar Apr 19 '22 16:04 Bjarten

Hello @Bjarten. Thanks for creating a nice EarlyStopping. It worked fine with my model, but I got a bit strange outcome "nan" values at some point and could not figure out why. Any ideas why I could get those "nan" values? Thanks in advance :)

NAN_value

HripsimeS avatar Apr 20 '22 21:04 HripsimeS

Take a look at this link

https://stackoverflow.com/questions/66648432/pytorch-test-loss-becoming-nan-after-some-iteration

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Hripsime Snkhchyan @.> Sent: Wednesday, April 20, 2022 11:18:21 PM To: Bjarten/early-stopping-pytorch @.> Cc: Bjarte Mehus Sunde @.>; Mention @.> Subject: Re: [Bjarten/early-stopping-pytorch] ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (Issue #15)

Hello @Bjartenhttps://github.com/Bjarten. Thanks for creating a nice EarlyStopping class in pytorchtool.py. It worked fine with my model, I just got a bit strange outcome "nan" values at some point and could not figure out why. Any ideas why I could get those "nan" values? Thanks in advance :)

[NAN_value]https://user-images.githubusercontent.com/42246765/164324580-86f8b9d8-cd64-4f85-bbb7-9a010e1ba237.png

— Reply to this email directly, view it on GitHubhttps://github.com/Bjarten/early-stopping-pytorch/issues/15#issuecomment-1104464357, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA5QP47HE2OEJUQSECI7S73VGBYB3ANCNFSM5TDO5M5Q. You are receiving this because you were mentioned.Message ID: @.***>

Bjarten avatar Apr 20 '22 21:04 Bjarten

Yes, edit the existing variable by adding your path


From: Hripsime Snkhchyan @.> Sent: Tuesday, April 19, 2022 5:54 PM To: Bjarten/early-stopping-pytorch @.> Cc: Bjarte Mehus Sunde @.>; Mention @.> Subject: Re: [Bjarten/early-stopping-pytorch] ImportError: cannot import name 'EarlyStopping' from 'pytorchtools' (Issue #15)

@Bjartenhttps://github.com/Bjarten no it did not help unfortunately moving the pytorchtools.py file to the same folder. I add new variable in "System variables" to add a path of pytorchtools.py file. This is a correct way or I need to modify it? C:\Users\Hripsime\anaconda3\envs\abys\Lib\site-packages\pytorchtools\pytorchtools.py

[image]https://user-images.githubusercontent.com/42246765/164044464-b2207ad6-d68f-4520-b2f6-2c4682a32555.png

— Reply to this email directly, view it on GitHubhttps://github.com/Bjarten/early-stopping-pytorch/issues/15#issuecomment-1102819792, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA5QP46CNSIEP62VNLY4SMLVF3JNFANCNFSM5TDO5M5Q. You are receiving this because you were mentioned.Message ID: @.***>

Bjarten avatar Oct 11 '22 08:10 Bjarten