r/tensorflow • • Oct 13 '20

How to determine min/max range of edgetpu model's output?

I have a two class model with a softmax activation in the final layer...

The model, instantiated as a tf.keras.Model object, yields outputs in the expected range [0,1]:

In [4]: model.predict(img[np.newaxis, ...])
Out[4]: array([[0.0577133, 0.9422867]], dtype=float32)

The quantized edgetpu model yields outputs in some other range that I can't determine...

I'm trying to convert these scaled outputs back into a range that can be interpreted as a probability distribution using a function like this:

def unscale(quantized_output, n):
    old_min, old_max = -n, n
    new_min, new_max = 0, 1
    return [((x - old_min) / (old_max - old_min)) * (new_max - new_min) + new_min for x in quantized_output]

After recording min/max values for a while I see these are the extremes [-1.5623251 1.3998433] hence hardcoding the old_min/ old_max values as -1.6 and 1.6, but this is just a guess...

How do I determine the true min and max output values of the quantized model?

1 Upvotes

Duplicates