4

I've been tearing my hair out trying to figure this out for days. I'm using tensorflow-gpu v1.13.1 and I could only find 2 other threads even mentioning a similar error.

Recreated error:

import numpy as np
import tensorflow as tf
from tensorflow import keras
def createModel():
    model = tf.keras.models.Sequential()
    model.add(tf.keras.layers.Dense(5, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dense(5, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dense(1, activation=tf.nn.sigmoid))
    model.compile(optimizer='sgd',
                  loss='mean_squared_error')
    return model

def array_generator():
    yield np.array([0.1,0.2,0.3,0.4,0.5]), np.array([1])

model=createModel()
model.fit_generator(array_generator(), epochs=5, steps_per_epoch=5)

I'm trying to make a neural net to classify a file as malicious or nonmalicious. Original source code, the X_train, y_train, X_test, and y_test are all numpy arrays.

import tensorflow as tf
import numpy as np
import ember
import random
X_train, y_train, X_test, y_test = ember.read_vectorized_features("C:\\Users\Cody\Desktop\synopsys\data\ember")
metadata_dataframe = ember.read_metadata("C:\\Users\Cody\Desktop\synopsys\data\ember")


#load testing set
def loadTestSet():
    X_test_tf = tf.convert_to_tensor(X_test, np.float32)
    y_test_tf = tf.convert_to_tensor(y_test, np.float32)
    return X_test_tf, y_test_tf

#create compiled keras model
def createModel():
    model = tf.keras.models.Sequential()
    #ADD L2 REGULARIZATION LATER
    model.add(tf.keras.layers.Dense(7351, activation=tf.nn.relu))
    '''model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(4096, activation=tf.nn.relu))'''
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(4096, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(4096, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(2048, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(2048, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(2048, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(1024, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(1024, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(1024, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(1024, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(1, activation=tf.nn.sigmoid))
    #adam metrhod for stochastic gradient descent
    model.compile(optimizer='adam',
                  loss='categorical_crossentropy',
                  metrics=['accuracy'])
    return model

def generate_arrays(features, labels, batch_size):
    batch_features=np.zeros((batch_size, 7351), dtype=np.float32)
    batch_labels=np.zeros((batch_size, 1), dtype=np.float32)
    while True:
        for i in range(batch_size):
            index=random.choice(900000,1)
            batch_features=X_train[index]
            batch_labels=y_train[index]
        yield batch_features, batch_labels

print('creating model')
model=createModel()
print('training model')
model.fit_generator(generate_arrays(X_train, y_train, 500), epochs=10, steps_per_epoch=1800)
print('testing model')
X_test_tf, y_test_tf = loadTestSet()
model.evaluate(X_test_tf, y_test_tf)

This is my error:

Traceback (most recent call last): File "C:/Users/Cody/Desktop/synopsys/train.py", line 76, in model.fit_generator(generate_arrays(X_train, y_train, 500), epochs=10, steps_per_epoch=1800) File "C:\Users\Cody\AppData\Local\conda\conda\envs\emberenv\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1426, in fit_generator initial_epoch=initial_epoch) File "C:\Users\Cody\AppData\Local\conda\conda\envs\emberenv\lib\site-packages\tensorflow\python\keras\engine\training_generator.py", line 125, in model_iteration model, mode, class_weight=class_weight) File "C:\Users\Cody\AppData\Local\conda\conda\envs\emberenv\lib\site-packages\tensorflow\python\keras\engine\training_generator.py", line 427, in _make_execution_function model._make_fit_function() File "C:\Users\Cody\AppData\Local\conda\conda\envs\emberenv\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1926, in _make_fit_function '_fit_function', [self.total_loss] + metrics_tensors) AttributeError: 'Sequential' object has no attribute 'total_loss'

Any help is greatly appreciated, I've been stuck on this for way too long.

2 Answers 2

2

I was helping a friend out with a similar problem (AttributeError: 'Sequential' object has no attribute 'total_loss'). After several hours of troubleshooting, we got past it by upgrading tensorflow to 2.0.0-alpha0. We also had to do a "pip install pillow".

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

Comments

1

This looks like a known issue for an outdated version of Keras/Tensorflow https://github.com/keras-team/keras/issues/10323

Please upgrade to the latest version for both.

6 Comments

Thank you for your response. I have already seen that thread; I am currently using tensorflow-gpu 1.13.1 and keras 2.2.4, both of which are the latest versions. I also recreated this error in a much smaller file, if that would be helpful.
Are u absolutely sure your conda environment is using these versions, because it seems like keras is calling tensorflow for an api that does not exist
Yes, I am absolutely sure I am using those versions. I have verified it in anaconda, my IDE, and by printing tensorflow/keras version. Also, that github issue is different from my issue, it's saying it's missing the "model" attribute, not the "total_loss" attribute. I already knew that model.model was deprecated and removed.
Total_loss attribute is probably used by the accuracy metric, can u remove the accuracy metric to confirm if that issue still exists, I’m trying to narrow it down
Removing accuracy did nothing. Also, thanks for spending the time to help me with this, it really is appreciated.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.