Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Keras on Jupyter Notebook

I am new to Ml (Cat & Dog Detection). I have trouble in using Keras library in a Jupyter Notebook.

I tried to install Tensorflow within jupyter note book by this:

 import tensorflow as tf

I don't know if this is right way to call Keras but in second cell i tried:

from keras.models import Sequential

Error:

    ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-10-9c5e0a19b646> in <module>
----> 1 from keras.models import Sequential

ModuleNotFoundError: No module named 'keras'

Absolutely Keras is not a module in Tensorflow library 😂, If cant get it with Tensorflow how should I call it?

like image 341
Pooya Avatar asked Jul 06 '26 02:07

Pooya


2 Answers

You have to do !pip install keras within your jupyter notebook to install the keras package before you can import keras. Keras uses tensorflow backend, so when you install keras it installs tensorflow as part of the requirements.

like image 76
Kehinde Richard Ogunyale Avatar answered Jul 08 '26 16:07

Kehinde Richard Ogunyale


When you install tensorflow 2.x, keras is installed along with it. Thus you can import keras from tensorflow:

from tensorflow.keras import Sequential
like image 31
Nishant Avatar answered Jul 08 '26 16:07

Nishant