Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import keras from tf.keras in Tensorflow?

import tensorflow as tf import tensorflow   from tensorflow import keras from keras.layers import Dense 

I am getting the below error

from keras.layers import Input, Dense Traceback (most recent call last):    File "<ipython-input-6-b5da44e251a5>", line 1, in <module>     from keras.layers import Input, Dense  ModuleNotFoundError: No module named 'keras' 

How do I solve this?

Note: I am using Tensorflow version 1.4

like image 789
GeorgeOfTheRF Avatar asked Nov 13 '17 11:11

GeorgeOfTheRF


People also ask

Is TF keras the same as keras?

The difference between tf. keras and keras is the Tensorflow specific enhancement to the framework. keras is an API specification that describes how a Deep Learning framework should implement certain part, related to the model definition and training.


Video Answer


1 Answers

Use the keras module from tensorflow like this:

import tensorflow as tf

Import classes

from tensorflow.python.keras.layers import Input, Dense

or use directly

dense = tf.keras.layers.Dense(...)

EDIT Tensorflow 2

from tensorflow.keras.layers import Input, Dense

and the rest stays the same.

like image 99
Mihail Burduja Avatar answered Sep 19 '22 13:09

Mihail Burduja