TypeError: reduce_sum() got an unexpected keyword argument 'reduction_indices'?

0

Issue

After using this function which was I wrote in tf == 1. I have updated tensorflow 2.0. I’m facing same error mentioned below

    colors = tf.constant(img, dtype=tf.float32)
    model = tf.keras.models.model_from_json(json.load(open("model.json"))["model"], custom_objects={})
    model.load_weights("model_weights.h5")
    predictions = model.predict(colors, batch_size=32, verbose=0)
    # Output is one-hot vector for 9 class:["red","green","blue","orange","yellow","pink", "purple","brown","grey"]
    predictions = tf.one_hot(np.argmax(predictions, 1), 9)
    # Sum along the column, each entry indicates no of pixels
    res = tf.reduce_sum(predictions, reduction_indices= 0 ).numpy()
    # Threshold is 0.5 (accuracy is 96%) change threshold may cause accuracy decrease
    if res[0] / (sum(res[:-1]) + 1) > 0.5:
        return "red"
    elif res[1] / (sum(res[:-1]) + 1) > 0.5:
        return "green"
    elif res[2] / (sum(res[:-1]) + 1) > 0.5:
        return "blue"
    else:
        return "other"

Error Message is below
TypeError: reduce_sum() got an unexpected keyword argument 'reduction_indices'

Solution

I think your problem is that reduction_indices is deprecated in Tensorflow 2.x, so just try doing:

tf.reduce_sum(predictions, axis= 0)

which is the equivalent.

Answered By – AloneTogether

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More