1

I am working with python 3.9, tensorflow 2.7.0 with a modified version of Mask RCNN https://github.com/leekunhee/Mask_RCNN/blob/tensorflow2.0/mrcnn). I am working with tensorflow .keras and specifically import

import tensorflow as tf
from tensorflow.python import keras 
from tensorflow.python.keras import backend as K
from tensorflow.python.keras import layers as KL
from tensorflow.python.keras import utils as KU
from tensorflow.python.eager import context
from tensorflow.python.keras import initializers as KI#nuevo
from tensorflow.python.keras import engine as KE
from tensorflow.python.keras import models as KM
from tensorflow.keras.optimizers import SGD

I call this module in this code

`optimizer = SGD(lr=learning_rate, momentum=momentum, clipnorm=self.config.GRADIENT_CLIP_NORM)`

and get this error

~/work/model.py in compile(self, learning_rate, momentum)
   2234         """
   2235 
-> 2236         # Optimizer object
   2237         optimizer = SGD(
   2238             lr=learning_rate, momentum=momentum,
AttributeError: module 'tensorflow.python.keras.optimizers' has no attribute 'SGD' 

I have tried calling tensforflow.keras.optimizers.SGD or tensorflow.python.keras.optimizers.SGD instead but nothing seems to work.

I am working on a jupyter notebook in IBM Watson Studio

Thanks!

1
  • I would follow this answer stackoverflow.com/a/2055165/3765034 - for how to look for the source code to see what is there. if installed correctly you should have it there. I would say that repo you are forking is requiring >= 2.2 tf so things could have changed from then to 2.9 Commented Apr 27, 2022 at 22:57

1 Answer 1

0

I ran into this issue and came across your post. I'm running python v3.9.7 on a MacBook Pro with an M1 processor. (I'm not quite sure how to check my tensor flow version, as I'm still learning).

To better understand what was happening, I ran specifically:

from tensorflow.python.keras.optimizers import SGD

did not work.

However, it did work when I ran:

from tensorflow.keras.optimizers import SGD

from tensorflow.keras.optimizers import SGD

It seems as if the tensorflow.python.keras.optimizers has different optimisers than tensorflow.keras.optimizers. However, I can't find any documentation on this and am surprised as something as fundamental as stochastic gradient descent (SGD) would be missing?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.