faustomorales / vit-keras

Keras implementation of ViT (Vision Transformer)
Apache License 2.0
329 stars 78 forks source link

RuntimeError: when unable to load the library or get the python wrappers. #10

Closed pranavchat14 closed 3 years ago

pranavchat14 commented 3 years ago

I was facing an error in loading the model. Resolved by downgrading Tensorflow version to 2.1.0. Upgrading this repo to latest version of Tensorflow would simply things a little more. Thanks for the implementation.

faustomorales commented 3 years ago

Yes, the intention is for this package to work with the latest available version of TensorFlow. Could you provide the following?

The dependencies for this package are specified using pyproject.toml, which would make a requirements.txt superfluous. TensorFlow is not specified there in order to allow people to install their preferred flavor of the package (e.g., some people still use tensorflow-gpu or build from source).

pranavchat14 commented 3 years ago

I am using Google Colab. I am doing exactly like instructed in README.md.

I have installed vit-keras using pip. Then I go with this example code:

image_size = 224 model = vit.vit_l32( image_size=image_size, activation='sigmoid', pretrained=True, include_top=True, pretrained_top=False, classes=200 )

The details are as follows:


NotFoundError Traceback (most recent call last)

in () 8 include_top=True, 9 pretrained_top=False, ---> 10 classes=200 11 ) 14 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/load_library.py in load_op_library(library_filename) 55 RuntimeError: when unable to load the library or get the python wrappers. 56 """ ---> 57 lib_handle = py_tf.TF_LoadLibrary(library_filename) 58 try: 59 wrappers = _pywrap_python_op_gen.GetPythonWrappers( NotFoundError: /usr/local/lib/python3.6/dist-packages/tensorflow_addons/custom_ops/activations/_activation_ops.so: undefined symbol: _ZN10tensorflow14kernel_factory17OpKernelRegistrar12InitInternalEPKNS_9KernelDefEN4absl11string_viewESt10unique_ptrINS0_15OpKernelFactoryESt14default_deleteIS8_EE
faustomorales commented 3 years ago

Ah, you've run into a compatibility problem between tensorflow_addons and tensorflow. Unfortunately, users have to manage the version compatibility for these two packages manually. See the tensorflow_addons README for more information on why that's the case. Unfortunately, it's not something that vit-keras can handle automatically.

Because Google Colab periodically updates the version of TensorFlow that ships, it's also not easy to just set a version of tensorflow_addons to fix it. For that reason, I suggest setting a fixed version for both tensorflow and tensorflow_addons at the top of your notebook.

As an example, if you want to use tensorflow==2.4.1, you can look it up on the tensorflow_addons compatibility chart and see that it requires tensorflow_addons==0.12.1. And so the following would work in a Google Colab notebook.

!pip install -q vit-keras tensorflow==2.4.1 tensorflow_addons==0.12.1

import vit_keras.vit as vit

image_size = 224
model = vit.vit_l32(
  image_size=image_size,
  activation='sigmoid',
  pretrained=True,
  include_top=True,
  pretrained_top=False,
  classes=200
)

Closing this for now but let me know if this doesn't solve your problem.