# Model outputting too many values

**URL:** <https://discuss.ai.google.dev/t/model-outputting-too-many-values/26356>\
**Category:** General Discussion\
**Tags:** tfcore\
**Created:** [March 28, 2023, 9:45pm UTC](https://discuss.ai.google.dev/t/model-outputting-too-many-values/26356 "2023-03-28T21:45:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MitchellWeg](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mitchellweg/32/11262_2.png) [@MitchellWeg](https://discuss.ai.google.dev/u/MitchellWeg)\
**Post date:** [March 28, 2023, 9:45pm UTC](https://discuss.ai.google.dev/t/model-outputting-too-many-values/26356/1 "2023-03-28T21:45:12Z")

</div>

I’m doing a image classification excerise, with the following model:

```auto
    _input = keras.layers.Input(shape=(IMAGE_HEIGHT, IMAGE_WIDTH, 3))
    model = keras.models.Sequential([
        _input,
        keras.layers.Conv2D(filters=64, kernel_size=(3,3), activation="relu"),
        keras.layers.MaxPool2D(),
        keras.layers.Conv2D(filters=32, kernel_size=(3,3), activation="relu"),
        keras.layers.MaxPool2D(),
        keras.layers.Flatten(),
        keras.layers.Dense(64, kernel_regularizer=keras.regularizers.l2(0.001), activation="relu"),
        keras.layers.Dropout(0.2),
        keras.layers.Dense(32, kernel_regularizer=keras.regularizers.l2(0.001), activation="relu"),
        keras.layers.Dense(16, kernel_regularizer=keras.regularizers.l2(0.001), activation="relu"),
        keras.layers.Flatten(),
        keras.layers.Dense(2, activation="softmax"),
    ])

```

Where `IMAGE_HEIGHT = 640` and `IMAGE_WIDTH = 360`

Because of the last layer, I’m expecting it to output only 2 values. However, when I call predict, it outputs:

```auto
[[9.6326274e-01 3.6737300e-02]
[9.9999464e-01 5.3239705e-06] 
[1.0000000e+00 1.4427736e-08]
[9.9398309e-01 6.0168877e-03]]      

```

It is predicting 2 labels, a 1 and a 0.

What exactly am I doing wrong?

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [March 29, 2023, 12:35am UTC](https://discuss.ai.google.dev/t/model-outputting-too-many-values/26356/2 "2023-03-29T00:35:20Z")

</div>

@MitchellWeg,

It looks like the model is working correctly and predicting 2 labels with probabilities for each of the input images.

The first value in each row represents the probability of the image belonging to the first class (label 0) and the second value represents the probability of the image belonging to the second class (label 1).

To get a final prediction for each input image, you can simply choose the class with the highest probability as shown below

```auto
predictions = model.predict(input_data)

#Get the index of the class with the highest probability for each sample
predicted_classes = np.argmax(predictions, axis=1)

```

Thank you!

---

<div class="post-metadata">

**Author:** ![MitchellWeg](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mitchellweg/32/11262_2.png) [@MitchellWeg](https://discuss.ai.google.dev/u/MitchellWeg)\
**Post date:** [March 29, 2023, 10:58am UTC](https://discuss.ai.google.dev/t/model-outputting-too-many-values/26356/4 "2023-03-29T10:58:54Z")

</div>

Ah, I didn’t know you could pass an axis to np argmax. Thank you! \

Just as a side note, why is it outputting 4 values?

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [March 30, 2023, 10:04am UTC](https://discuss.ai.google.dev/t/model-outputting-too-many-values/26356/6 "2023-03-30T10:04:10Z")

</div>

@MitchellWeg,

You are passing 4 images for the model to predict. Hence, the model returns 4\*2 metrics as output, which contains 4 rows that correspond to images and 2 columns for every image.

Please find the [gist](https://colab.sandbox.google.com/gist/chunduriv/a0e921431d0cef33e3ca7ef1730fa0dd/15756.ipynb) for reference.

Thank you!
