Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import keras.engine.topology in Tensorflow?

Tags:

I want to import keras.engine.topology in Tensorflow. I used to add the word tensorflow at the beginning of every Keras import if I want to use the Tensorflow version of Keras.

For example: instead of writing:

from keras.layers import Dense, Dropout, Input

I just write the following code and it works fine :

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

But that's not the case for this specific import:

from tensorflow.keras.engine.topology import Layer, InputSpec

And I m getting the following error message:

No module named 'tensorflow.keras.engine'
like image 453
nairouz mrabah Avatar asked Jul 14 '18 10:07

nairouz mrabah


2 Answers

You can import Layer and InputSpec from TensorFlow as follows:

from tensorflow.python.keras.layers import Layer, InputSpec

UPDATE: 30/10/2019

from tensorflow.keras.layers import Layer, InputSpec
like image 55
rvinas Avatar answered Sep 20 '22 16:09

rvinas


In order to import keras.engine you may try using:

import tensorflow.python.keras.engine

Note: But from tensorflow.python.keras.engine you cannot import topology

like image 42
Rahul kumar Avatar answered Sep 21 '22 16:09

Rahul kumar