Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'keras_contrib'

Tags:

python

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'

like image 372
Arun Avatar asked Apr 12 '18 08:04

Arun


3 Answers

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')

like image 133
Prady_gupta Avatar answered Sep 19 '22 04:09

Prady_gupta


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.

like image 23
Hagbard Avatar answered Nov 09 '22 17:11

Hagbard


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.

like image 3
Tomáš Cerha Avatar answered Nov 09 '22 17:11

Tomáš Cerha