AttributeError: 'Sequential' object has no attribute '_get_distribution_strategy'

python attributeerror: object has no attribute
raise attributeerror
attributeerror django
except attributeerror
how to fix attribute error in python
attributeerror pplayoutblank
attributeerror meaning
how to remove attribute error in python

I am following an online course through linkedin regrading the Building of models through Keras.

This is my code. (This is claimed to work)

import pandas as pd
import keras
from keras.models import Sequential
from keras.layers import *

training_data_df = pd.read_csv("sales_data_training_scaled.csv")

X = training_data_df.drop('total_earnings', axis=1).values
Y = training_data_df[['total_earnings']].values

# Define the model
model = Sequential()
model.add(Dense(50, input_dim=9, activation='relu', name='layer_1'))
model.add(Dense(100, activation='relu', name='layer_2'))
model.add(Dense(50, activation='relu', name='layer_3'))
model.add(Dense(1, activation='linear', name='output_layer'))
model.compile(loss='mean_squared_error', optimizer='adam')


# Create a TensorBoard logger
logger = keras.callbacks.TensorBoard(
    log_dir='logs',
    write_graph=True,
    histogram_freq=5
)


# Train the model
model.fit(
    X,
    Y,
    epochs=50,
    shuffle=True,
    verbose=2,
    callbacks=[logger]
)

# Load the separate test data set
test_data_df = pd.read_csv("sales_data_test_scaled.csv")

X_test = test_data_df.drop('total_earnings', axis=1).values
Y_test = test_data_df[['total_earnings']].values

test_error_rate = model.evaluate(X_test, Y_test, verbose=0)
print("The mean squared error (MSE) for the test data set is: {}".format(test_error_rate))

I get the following error when the following code was executed.

Using TensorFlow backend.
2020-01-16 13:58:14.024374: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-01-16 13:58:14.037202: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fc47b436390 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-01-16 13:58:14.037211: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
  File "/Users/himsaragallage/Documents/Building_Deep_Learning_apps/06/model_logging final.py", line 35, in <module>
    callbacks=[logger]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/engine/training.py", line 1239, in fit
    validation_freq=validation_freq)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/engine/training_arrays.py", line 119, in fit_loop
    callbacks.set_model(callback_model)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/callbacks/callbacks.py", line 68, in set_model
    callback.set_model(model)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keras/callbacks/tensorboard_v2.py", line 116, in set_model
    super(TensorBoard, self).set_model(model)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/keras/callbacks.py", line 1532, in set_model
    self.log_dir, self.model._get_distribution_strategy())  # pylint: disable=protected-access
AttributeError: 'Sequential' object has no attribute '_get_distribution_strategy'

Process finished with exit code 1

While I was trying to Debug

I found out that this error was caused because I am trying to use a tensorboard logger. More accurately. When I add callbacks=[logger]. Without that line of code the program runs without any errors. But Tensorboard won't be used.

Please suggest me a method in which I can eliminate the error successfully run the above mentioned python script.

Hope you are referring to this LinkedIn Keras Course.

Even I faced the Same Error when I have used Tensorflow Version 2.1. However, after downgrading the Tensorflow Version and with slight modifications in the code, I could invoke Tensorboard.

Working Code is shown below:

import pandas as pd
import keras
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import *

training_data_df = pd.read_csv("sales_data_training_scaled.csv")

X = training_data_df.drop('total_earnings', axis=1).values
Y = training_data_df[['total_earnings']].values

# Define the model
model = Sequential()
model.add(Dense(50, input_dim=9, activation='relu', name='layer_1'))
model.add(Dense(100, activation='relu', name='layer_2'))
model.add(Dense(50, activation='relu', name='layer_3'))
model.add(Dense(1, activation='linear', name='output_layer'))
model.compile(loss='mean_squared_error', optimizer='adam')

# Create a TensorBoard logger
logger = tf.keras.callbacks.TensorBoard(
    log_dir='logs',
    write_graph=True,
    histogram_freq=5
)

# Train the model
model.fit(
    X,
    Y,
    epochs=50,
    shuffle=True,
    verbose=2,
    callbacks=[logger]
)

# Load the separate test data set
test_data_df = pd.read_csv("sales_data_test_scaled.csv")

X_test = test_data_df.drop('total_earnings', axis=1).values
Y_test = test_data_df[['total_earnings']].values

test_error_rate = model.evaluate(X_test, Y_test, verbose=0)
print("The mean squared error (MSE) for the test data set is: {}".format(test_error_rate))

6. Built-in Exceptions — Python 2.7.18 documentation, exception AttributeError �. Raised when an attribute reference (see Attribute references) or assignment fails. (When an object does not support� A close look at the AttributeError in Python, including a functional code sample showing how to manually override attribute access in your classes.

You may find this post useful.

So instead of importing from keras (i.e.)

from keras.models import Sequential

import from tensorflow:

from tensorflow.keras.models import Sequential

And this of course applies to most other imports as well.

This is just a lucky guess because I can't run your code, but hope it helps!

Python: AttributeError, These errors yields to the program not executed. One of the error in Python mostly occurs is “ AttributeError “. AttributeError can be defined as an� AttributeError: module 'asyncio' has no attribute 'coroutine' (Python 3.6.4) -1 AttributeError: Why does the module first imported not register as an attribute?

I would recommend not mixing keras and tf.keras. Those are different projects as keras is the original, multi-backend project and tf.keras is the version integrated into tensorflow. Keras will stop supporting other backends but tensorflow so it's adviced to switch to it. Check https://keras.io/#multi-backend-keras-and-tfkeras

An easy way to do that is importing keras from tensorflow:

import tensorflow as tf
import tensorflow.keras as keras
#import keras
import keras.backend as K
from keras.models import Model, Sequential, load_model
from keras.layers import Dense, Embedding, Dropout, Input, Concatenate

print("Python: "+str(sys.version))
print("Tensorflow version: "+tf.__version__)
print("Keras version: "+keras.__version__)
Python: 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0]
Tensorflow version: 2.1.0
Keras version: 2.2.4-tf

Python Exception Handling - AttributeError, The AttributeError in Python is raised when an invalid attribute reference is made, or when an attribute assignment fails. While most objects� exception Exception¶. All built-in, non-system-exiting exceptions are derived from this class. All user-defined exceptions should also be derived from this class.

It seems that your python environment is mixing imports from keras and tensorflow.keras. Try to use Sequential module like this:

model = tensorflow.keras.Sequential()

Error Encyclopedia, Attribute errors in Python are generally raised when you try to access or call an attribute that a particular object type doesn't possess. Using our prior example, we� AttributeError: module 'matplotlib' has no attribute 'scatter' 0 votes. Hi Guys, I have my Machine Learning model. I want to draw one scatter plot using matplotlib

Why does this AttributeError in python occur?, This happens because the scipy module doesn't have any attribute named sparse . That attribute only gets defined when you import� Your indentation is wrong. The line elif event.key == pygame.K_s and the like should be at the same level as if event.key == pygame.K_w. – StardustGogeta Aug 9 '19 at 14:42

Python AttributeError — What is it and how do you fix it?, When does it happen? All these questions are answered in this video! The attribute error in Duration: 5:14 Posted: Jul 27, 2018 AttributeError: module 'tensorflow' has no attribute 'Summary' #9. Open palunel opened this issue Apr 23, 2019 · 2 comments Open AttributeError: module 'tensorflow'

How to resolve an attribute error in Python, Import the module. * If above step is successful. Try the command dir(ngram) and see all the objects and classes in the module and find what you want. 🐛 Bug I get the error: AttributeError: module 'torch.distributed' has no attribute 'init_process_group' when running the following code (see reproduce). I am using the Jetson Nano and have installed torch through the PyTorchv1.3.0 pip wh