Module 'keras.optimizers' has no attribute 'SGD'. Google Collab

I have notebook created on Google Collab. For work I need some functions of keras library.

I imported them

from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.callbacks import Callback
from keras import regularizers
from keras import optimizers

After running occurred this problem.

     54     model.compile(
---> 55      optimizer = optimizers.SGD(lr=lr),
     56      loss = loss_func,
     57      metrics = ["acc"]

AttributeError: module 'keras.optimizers' has no attribute 'SGD'

I tried this way

model.compile(
     optimizer = tf.keras.optimizers.SGD(lr=lr),
     loss = loss_func,
     metrics = ["accuracy"]
    )

I haven't issues with SGD but I have the same issue with Sequential.

What will be the right solution in this case? Why doesn't first way work?


Use tf.keras.optimizers.SGD instaed of optimizers.SGD