OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Unable to import SGD and Adam from 'tensorflow.python.keras.optimizers'

  • Thread starter Thread starter 초록옷
  • Start date Start date

초록옷

Guest
Trying to run---

Code:
import tensorflow as tf
from tensorflow import keras

from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Flatten, Dense
from tensorflow.python.keras.optimizers import SGD, Adam

import numpy as np

print(tf.__version__)

I get this error---

Code:
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-8-f05f8f753c47> in <module>()
      4 from tensorflow.python.keras.models import Sequential
      5 from tensorflow.python.keras.layers import Flatten, Dense
----> 6 from tensorflow.python.keras.optimizers import SGD, Adam
      7 
      8 import numpy as np

ImportError: cannot import name 'SGD' from 'tensorflow.python.keras.optimizers' (/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/optimizers.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

---------------------------------------------------------------------------

I'm studying machine learning in Google Colab. I pasted the example code and run it, and get error message.

I could find similar errors in Google, but I couldn't find anything to solve this problem.

I tried 'from tensorflow.keras.optimizers import SGD, Adam', 'from tf.keras.optimizers import SGD, Adam', and 'from keras.optimizers import SGD, Adam'. But everything didn't work.
<p><strong>Trying to run---</strong></p>
<pre><code>import tensorflow as tf
from tensorflow import keras

from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Flatten, Dense
from tensorflow.python.keras.optimizers import SGD, Adam

import numpy as np

print(tf.__version__)
</code></pre>
<p><strong>I get this error---</strong></p>
<pre><code>---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-8-f05f8f753c47> in <module>()
4 from tensorflow.python.keras.models import Sequential
5 from tensorflow.python.keras.layers import Flatten, Dense
----> 6 from tensorflow.python.keras.optimizers import SGD, Adam
7
8 import numpy as np

ImportError: cannot import name 'SGD' from 'tensorflow.python.keras.optimizers' (/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/optimizers.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

---------------------------------------------------------------------------
</code></pre>
<p>I'm studying machine learning in Google Colab.
I pasted the example code and run it, and get error message.</p>
<p>I could find similar errors in Google, but I couldn't find anything to solve this problem.</p>
<p>I tried 'from tensorflow.keras.optimizers import SGD, Adam', 'from tf.keras.optimizers import SGD, Adam', and 'from keras.optimizers import SGD, Adam'.
But everything didn't work.</p>
 

Latest posts

Top