0

I am using Gradio as GUI to test a machine learning algorithm, specifically the classic problem of reading a 28 by 28 pixel image of a handwritten digit. I want the GUI to be able to draw and take an input and then determine the digit. So, I have the following code (machine learning model not shown):

import gradio
import gradio as gr
import tensorflow as tf
import numpy as np

new_model = tf.keras.models.load_model('digits.model')


def classify(input):
    input = np.reshape(input, (1, 28, 28))
    prediction = new_model.predict(input).tolist()[0]
    return {str(i): prediction[i] for i in range(10)}

label = gr.outputs.Label(num_top_classes=10)

interface = gr.Interface(fn=classify, inputs="sketchpad", outputs=label,
live=True)
interface.launch()

However, I run into two issues:

  1. The interface is always claims to be 100% sure about its answer, and I want it to show percentages for all of the digits.

  2. When I draw the digit to fill up the canvas, it does not work. When I draw it smaller to fill up only the middle portion, it works.

    drawn small in the middle, works correctly

    Drawn to fill up the canvas, doesn't work

I tried to look through the Gradio documentation and reshape the canvas to be default 28 by 28 pixel and not have to deal with reshaping the images, but I had no luck.

desertnaut
  • 57,590
  • 26
  • 140
  • 166

0 Answers0