Skip to content Skip to sidebar Skip to footer

Attributeerror: 'nonetype' Object Has No Attribute 'dtype'

I'm trying to implement a simple neural network using tensorflow. It is a binary classification problem. Shapes of X_train: (batch_size, 70) and Y_train: (batch_size, 2). I'm readi

Solution 1:

Your compute_cost() function returns None because it has no return statement:

def compute_cost(Z5, Y):
    cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=Z5, labels=Y))

You use this function to set the cost value:

cost = compute_cost(Z5, Y)

So cost is None here, which you pass into the .minimize() method.

The fix is to use return; presumably you wanted to return the tf.reduce_mean() result:

defcompute_cost(Z5, Y):
    return tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=Z5, labels=Y))

Post a Comment for "Attributeerror: 'nonetype' Object Has No Attribute 'dtype'"