Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: __init__() got an unexpected keyword argument 'n_indep_decoder' #374

Closed
balazsgonczy opened this issue Mar 23, 2022 · 11 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@balazsgonczy
Copy link

Hi,

I am trying to load a saved Tabnet model trained with your github repo.

Code:
from pytorch_tabnet.tab_model import TabNetClassifier
loaded_clf = TabNetClassifier()
loaded_clf.load_model("C:/Users/goncz/Desktop/test_model.zip")

Error message:

Device used : cpu

TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_3000/3925200397.py in
1 loaded_clf = TabNetClassifier()
----> 2 loaded_clf.load_model("C:/Users/goncz/Desktop/test_model.zip")
3

~\AppData\Local\Programs\Orange\lib\site-packages\pytorch_tabnet\abstract_model.py in load_model(self, filepath)
409 raise KeyError("Your zip file is missing at least one component")
410
--> 411 self.init(**loaded_params["init_params"])
412
413 self._set_network()

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

@balazsgonczy balazsgonczy added the bug Something isn't working label Mar 23, 2022
@balazsgonczy
Copy link
Author

Yes if you init the tabnet algo with this code "loaded_clf = TabNetClassifier()" then the 'n_indep_decoder' is going to be missed from the model. So it won't be able to load it.

@Optimox
Copy link
Collaborator

Optimox commented Mar 24, 2022

Hello @balazsgonczy,

Can you share a bit more information and ideally a reproducible error code where you save a model that can't be loaded back?

@balazsgonczy
Copy link
Author

Hello @Optimox,

I have used the forest example on my own data. Then I saved the model. There I could load it back without issue. But if I wanted to load the model to a new Jupyther notebook then it didn't worked. So I have to retrain the model each time I run my workflow in order to proceed with my task.

The main issue is what I have written. When you load back a model and before that you init the model like this: loaded_clf = TabNetClassifier() it won't match your saved model. Also I tried to init the missing parts like this: loaded_clf ="TabNetClassifier(n_indep_decoder=1)", but it retrieved the same error message.

I think the error arises from the init not being able to predefine certain parameters like shadder or indep_decoder. So I would check it out.

What considers the reproducible code... It is for a competition so I can only share it after the deadline.

Best,

Balázs

@Optimox
Copy link
Collaborator

Optimox commented Mar 24, 2022

I think what is most likely is that you have different versions of pytorch-tabnet installed in your different environments. So when you save your model the architecture is different between the two environments, hence your error when loading the weights.

Can you make sure that both environments have the exact same version and retry ?

@Optimox
Copy link
Collaborator

Optimox commented Mar 24, 2022

About reproducible errors : you do not need to give your full code (also it's better if I don't need to review an entire pipeline).

You should be able to reproduce your error with a randomly generated X_train, y_train.

If you manage to reproduce your error within a very simple setting that can be reproduce I can investigate directly what is going on. Otherwise I'm in the dark.

@balazsgonczy
Copy link
Author

pytorch_tabnet version: NA - in the forest notebook?

@balazsgonczy
Copy link
Author

I doubt this could be the issue. I am using Vscode + Jupyther Notebook with similar packages. I haven't created virtual environment for them so...

@balazsgonczy
Copy link
Author

My notebook:

Click to view session information

download 0.3.5
numpy 1.21.5
pandas 1.3.3
pytorch_tabnet NA
session_info 1.0.0
sklearn 0.23.2
torch 1.10.2+cpu

Click to view modules imported as dependencies
PIL 8.3.2
astunparse 1.6.3
backcall 0.2.0
bottleneck 1.3.2
brotli NA
certifi 2021.05.30
cffi 1.14.6
chardet 4.0.0
colorama 0.4.4
cycler 0.10.0
cython_runtime NA
dateutil 2.8.2
debugpy 1.4.1
decorator 4.4.2
defusedxml 0.7.1
django 4.0.3
entrypoints 0.3
google NA
idna 2.10
ipykernel 6.4.1
ipython_genutils 0.2.0
jedi 0.18.0
joblib 1.0.1
kiwisolver 1.3.2
matplotlib 3.4.3
matplotlib_inline NA
mpl_toolkits NA
nt NA
ntsecuritycon NA
orangecontrib NA
parso 0.8.2
pickleshare 0.7.5
pkg_resources NA
prompt_toolkit 3.0.20
pydev_ipython NA
pydevconsole NA
pydevd 2.4.1
pydevd_concurrency_analyser NA
pydevd_file_utils NA
pydevd_plugins NA
pydevd_tracing NA
pygments 2.10.0
pyparsing 2.4.7
pythoncom NA
pytz 2021.1
pywintypes NA
requests 2.25.1
scipy 1.5.3
sitecustomize NA
six 1.16.0
socks 1.7.1
storemagic NA
tornado 6.1
tqdm 4.63.0
traitlets 5.1.0
typing_extensions NA
urllib3 1.26.7
wcwidth 0.2.5
win32api NA
win32com NA
win32security NA
zmq 22.3.0

IPython 7.27.0
jupyter_client 7.0.3
jupyter_core 4.8.1

Python 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 15:50:08) [MSC v.1916 64 bit (AMD64)]
Windows-10-10.0.19041-SP0

Session information updated at 2022-03-24 15:00

Forest notebook:

Click to view session information

pytorch_tabnet NA
session_info 1.0.0

Click to view modules imported as dependencies
astunparse 1.6.3
backcall 0.2.0
bottleneck 1.3.2
colorama 0.4.4
cython_runtime NA
dateutil 2.8.2
debugpy 1.4.1
decorator 4.4.2
django 4.0.3
entrypoints 0.3
google NA
ipykernel 6.4.1
ipython_genutils 0.2.0
jedi 0.18.0
joblib 1.0.1
mpl_toolkits NA
nt NA
ntsecuritycon NA
numpy 1.21.5
orangecontrib NA
pandas 1.3.3
parso 0.8.2
pickleshare 0.7.5
pkg_resources NA
prompt_toolkit 3.0.20
pydev_ipython NA
pydevconsole NA
pydevd 2.4.1
pydevd_concurrency_analyser NA
pydevd_file_utils NA
pydevd_plugins NA
pydevd_tracing NA
pygments 2.10.0
pythoncom NA
pytz 2021.1
pywintypes NA
scipy 1.5.3
sitecustomize NA
six 1.16.0
sklearn 0.23.2
storemagic NA
torch 1.10.2+cpu
tornado 6.1
tqdm 4.63.0
traitlets 5.1.0
typing_extensions NA
wcwidth 0.2.5
win32api NA
win32com NA
win32security NA
zmq 22.3.0

IPython 7.27.0
jupyter_client 7.0.3
jupyter_core 4.8.1

Python 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 15:50:08) [MSC v.1916 64 bit (AMD64)]
Windows-10-10.0.19041-SP0

Session information updated at 2022-03-24 14:31

@Optimox
Copy link
Collaborator

Optimox commented Mar 25, 2022

how are you installing pytorch-tabnet ? with pip? from source?

what is the result of pip list for pytorch-tabnet on both environments?

@Optimox
Copy link
Collaborator

Optimox commented Mar 29, 2022

@balazsgonczy any news?

@Optimox
Copy link
Collaborator

Optimox commented Apr 4, 2022

I'm closing this since I'm not able to reproduce the error, please reopen with more information or a reproducible code.

@Optimox Optimox closed this as completed Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants