Colabtools: AttributeError: 'Model' object has no attribute '_get_distribution_strategy'

Created on 24 Dec 2019  路  7Comments  路  Source: googlecolab/colabtools

I am using Tensorflow 2.x bundle package in Google Colab But it gives me error when I am trying to train model:
AttributeError: 'Model' object has no attribute '_get_distribution_strategy'``

Please Give any suggestion what is the issue and how can solve it??

Most helpful comment

Hello,

I had the same issue and what I did is simple change my imports:

From
from keras.models import Model, load_model,Sequential
from keras.layers import Input, Dense
from keras.callbacks import ModelCheckpoint, TensorBoard
from keras import regularizers

To
from tensorflow.keras.models import Model, load_model,Sequential
from tensorflow.keras.layers import Input, Dense
from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard
from tensorflow.keras import regularizers

and it worked.

All 7 comments

Hello,

I had the same issue and what I did is simple change my imports:

From
from keras.models import Model, load_model,Sequential
from keras.layers import Input, Dense
from keras.callbacks import ModelCheckpoint, TensorBoard
from keras import regularizers

To
from tensorflow.keras.models import Model, load_model,Sequential
from tensorflow.keras.layers import Input, Dense
from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard
from tensorflow.keras import regularizers

and it worked.

Seems the error is in keras/callbacks.py with self.model._get_distribution_strategy()

In what file do I make the above changes?

same here. @georgesymeonidis does all imports from keras can be moved to tensorflow.keras?

i also think its from keras.callbacks import TensorBoard but changing to from tensorflow.keras.callbacks import TensorBoard not working

hi @georgesymeonidis i made changes but still not working

If you use Tensorflow 2.1.0, try to uninstall keras, then change the import from "keras.(...)" to "tensorflow.keras.(...)", it works for me!
Another solution is to downgrade tenforflow and keras: https://stackoverflow.com/questions/59090404/keras-that-does-not-support-tensorflow-2-0-we-recommend-using-tf-keras-or-al/59090507#59090507

same here. @georgesymeonidis does all imports from keras can be moved to tensorflow.keras?

i also think its from keras.callbacks import TensorBoard but changing to from tensorflow.keras.callbacks import TensorBoard not working

This is still an issue

had to create an virtual env with py 3.5.2, keras 2.1 and tensorflow 1.6 to get around this issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prteek picture prteek  路  4Comments

markus-weiss picture markus-weiss  路  4Comments

cornhundred picture cornhundred  路  3Comments

saurabhgayali picture saurabhgayali  路  4Comments

rtumac picture rtumac  路  4Comments