I am trying to import Keras lib code to execute CRF using the import command below but an error raises as titled. Please share the solution for this.
The command used to execute is
from keras_contrib.layers import CRF
Traceback (most recent call last):
File "", line 1, in from keras_contrib.layers import CRF
ImportError: No module named 'keras_contrib'
If you are trying to install the tensorflow-keras version or even the keras version using git cloning and setup.py installing and getting the above error then you might want to add the path of the keras-contrib folder to system path using -
import sys
sys.path.append('<remaining_path>/keras_contrib')
A simple
(sudo) pip install git+https://www.github.com/keras-team/keras-contrib.git
as mentioned in the installation instructions did the trick for me.
This error means that Python is unable to find the module in one of the directories defined by Python path. The module is either not installed or is installed in another directory.
If not installed, then see https://github.com/keras-team/keras-contrib for installation instructions.
If installed but not found, you will most likely need to add the directory where it is installed to your Python path. You can find out what your current Python path is by inspecting the variable sys.path
(such as python -c 'import sys; print sys.path'
). You may need to add another directory to your path by setting the environment variable PYTHONPATH
before running your script, but there are other options. See for example PYTHONPATH vs. sys.path for some insight.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With