angel_30
angel_30

Reputation: 1

ImportError: You need to first `import keras` in order to use `keras_applications`

I was trying to run a machine learning code using Tensorflow/Keras in Anaconda 3. I initially had a problem HERE, but I downgraded Keras to 2.1.6, and that error is resolved. Now I get the following error:

    raise ImportError('You need to first `import keras` '
ImportError: You need to first `import keras` in order to use `keras_applications`. For instance, you can do:

```
import keras
from keras_applications import vgg16
```

Or, preferably, this equivalent formulation:

```
from keras import applications
```

And here is my import list:

import glob, cv2, pickle, re
import numpy as np
from collections import defaultdict
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.decomposition import PCA
from keras.models import load_model, Model
from keras_applications.mobilenet import relu6
from layers import SRU, Attention, ShuffleImages
import tensorflow as tf

How can I resolve the issue?

Upvotes: 3

Views: 9211

Answers (1)

MFigueredo
MFigueredo

Reputation: 153

This a problem related to the backend choosed for your keras. Try verify if the backend in the keras configuration file is the same installed in your enviromment. To do so:

nano ~/.keras/keras.json

The file should be similar to :

{
    "image_data_format": "channels_last",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "tensorflow"
}

In this case, tensorflow must be installed correctly in your computer. If want to change the backend to another one ("theano", "tensorflow", or "cntk") just change in the keras.json file.

Upvotes: 2

Related Questions