1

Error from importing keras

>>> import keras
/Users/ray_zhang/anaconda3/envs/idp3/lib/python3.6/site-packages/daal/__init__.py:19: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ray_zhang/anaconda3/envs/idp3/lib/python3.6/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/Users/ray_zhang/anaconda3/envs/idp3/lib/python3.6/site-packages/keras/utils/__init__.py", line 6, in <module>
    from . import conv_utils
  File "/Users/ray_zhang/anaconda3/envs/idp3/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "/Users/ray_zhang/anaconda3/envs/idp3/lib/python3.6/site-packages/keras/backend/__init__.py", line 98, in <module>
    raise ValueError('Invalid backend. Missing required entry : ' + e)
ValueError: Invalid backend. Missing required entry : placeholder

I installed mxnet correctly:

>>> import mxnet as mx
/Users/ray_zhang/anaconda3/envs/idp3/lib/python3.6/site-packages/daal/__init__.py:19: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
>>> a = mx.nd.ones((2,3))
>>> b = a*2+1
>>> b.asnumpy()
array([[3., 3., 3.],
       [3., 3., 3.]], dtype=float32)

My keras in pip

(idp3) ❯ pip freeze | grep keras
keras-mxnet==2.2.0

~/.keras/keras.json

(idp3) ❯ cat ~/.keras/keras.json
{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "mxnet",
    "image_data_format": "channels_last"
}

It appears that my __init__.py in my keras site packages is not the same as the current github version's:

My keras/backend/__init__.py
# Import backend functions.
if _BACKEND == 'cntk':
    sys.stderr.write('Using CNTK backend\n')
    from .cntk_backend import *
elif _BACKEND == 'theano':
    sys.stderr.write('Using Theano backend.\n')
    from .theano_backend import *
elif _BACKEND == 'tensorflow':
    sys.stderr.write('Using TensorFlow backend.\n')
    from .tensorflow_backend import *
else:
    # Try and load external backend.
    ...

But in keras-mxnet's github repo:

# Import backend functions.
if _BACKEND == 'cntk':
    sys.stderr.write('Using CNTK backend\n')
    from .cntk_backend import *
elif _BACKEND == 'theano':
    sys.stderr.write('Using Theano backend.\n')
    from .theano_backend import *
elif _BACKEND == 'tensorflow':
    sys.stderr.write('Using TensorFlow backend.\n')
    from .tensorflow_backend import *
elif _BACKEND == 'mxnet':
    sys.stderr.write('Using MXNet backend\n')
    from .mxnet_backend import *
else:
    # Try and load external backend.
    ...
OneRaynyDay
  • 3,658
  • 2
  • 23
  • 56

1 Answers1

5

It looks like you have a mix of Keras and Keras-MXNet installed, which would explain why your init.py is not up-to-date.

I'd recommend doing a pip uninstall of both keras and keras-mxnet then reinstall keras-mxnet.

If you really need both versions installed on a single machine you could install them in different conda environments.