martinsbruveris / tensorflow-image-models

TensorFlow port of PyTorch Image Models (timm) - image models with pretrained weights.
https://tfimm.readthedocs.io/en/latest/
Apache License 2.0
286 stars 25 forks source link

Error while importing tfimm library #58

Closed iftiben10 closed 2 years ago

iftiben10 commented 2 years ago

Problem:

When I try to install and import tfimm packages:

!pip install tfimm import tfimm

This error occurs:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_42/1172421075.py in <module>
      3 get_ipython().system('pip install timm')
      4 import timm
----> 5 import tfimm

/opt/conda/lib/python3.7/site-packages/tfimm/__init__.py in <module>
----> 1 from . import architectures  # noqa: F401
      2 from .models.factory import create_model, create_preprocessing  # noqa: F401
      3 from .models.registry import list_models  # noqa: F401
      4 from .utils import (  # noqa: F401
      5     cached_model_path,

/opt/conda/lib/python3.7/site-packages/tfimm/architectures/__init__.py in <module>
----> 1 from .cait import *  # noqa: F401
      2 from .convmixer import *  # noqa: F401
      3 from .convnext import *  # noqa: F401
      4 from .mlp_mixer import *  # noqa: F401
      5 from .pit import *  # noqa: F401

/opt/conda/lib/python3.7/site-packages/tfimm/architectures/cait.py in <module>
     15 from typing import List, Tuple
     16 
---> 17 import tensorflow as tf
     18 
     19 from tfimm.layers import (

/opt/conda/lib/python3.7/site-packages/tensorflow/__init__.py in <module>
     35 import typing as _typing
     36 
---> 37 from tensorflow.python.tools import module_util as _module_util
     38 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
     39 

/opt/conda/lib/python3.7/site-packages/tensorflow/python/__init__.py in <module>
     35 
     36 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
---> 37 from tensorflow.python.eager import context
     38 
     39 # pylint: enable=wildcard-import

/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/context.py in <module>
     33 from tensorflow.python import pywrap_tfe
     34 from tensorflow.python import tf2
---> 35 from tensorflow.python.client import pywrap_tf_session
     36 from tensorflow.python.eager import executor
     37 from tensorflow.python.eager import monitoring

/opt/conda/lib/python3.7/site-packages/tensorflow/python/client/pywrap_tf_session.py in <module>
     17 # pylint: disable=invalid-import-order,g-bad-import-order, wildcard-import, unused-import
     18 from tensorflow.python import pywrap_tensorflow
---> 19 from tensorflow.python.client._pywrap_tf_session import *
     20 from tensorflow.python.client._pywrap_tf_session import _TF_SetTarget
     21 from tensorflow.python.client._pywrap_tf_session import _TF_SetConfig

ImportError: SystemError: <built-in method __contains__ of dict object at 0x7f9744ee7280> returned a result with an error set

Desktop Environment:

Question

In other repositories I have found that upgrading NumPy solves the problem. But my NumPy has the latest version. Can anyone please help me to solve this error?

martinsbruveris commented 2 years ago

Interesting. Definitely shouldn't happen. Could you post the output of pip list?

iftiben10 commented 2 years ago

Thank you @martinsbruveris for your response. Code:

!pip list

Output: See attachment.

pip_list.txt

martinsbruveris commented 2 years ago

Can you run just

import tensorflow as tf

in your environment? It would appear that the error comes from a mismatch of versions between TensorFlow and numpy. I am not sure that tfimm is really involved here.

iftiben10 commented 2 years ago

Thank you @martinsbruveris for your response. My tensorflow version is already the latest version and also import tensorflow as tf. But it does not solves the error.

martinsbruveris commented 2 years ago

I understand that you are using the latest version of TensorFlow. I am just wondering how the issue you are encountering could have been caused by tfimm. Hence the question whether you can execute import tensorflow without error messages? Because, if you can't then this would suggest that the problem lies with the python environment rather than tfimm.