Home > Software design >  Tensorflow: how can I detect handwriting numbers in an image if I have a trained MNIST model?
Tensorflow: how can I detect handwriting numbers in an image if I have a trained MNIST model?

Time:12-17

I have trained a model using MNIST dataset by the example code from https://keras.io/examples/vision/mnist_convnet/

I have an image containing several handwriting numbers and other characters, in different sizes, and in different colors.

I want to detect the handwriting numbers (0-9) using the trained model, and draw a bound rectangle around each number.

Is it possible? any advice is appreciated. My environment: tensorflow 2.7 python 3. Keras is used.

CodePudding user response:

Because your output layer looks like this: (Dense) (None, 10) 16010
And you defined your classes with: num_classes = 10

you use pred = model.predict(image) where image is your image.

Be aware that your image needs the shape = (28, 28, 1) so its x value is 28, y value is 28 and the color channel is 1 = (Grayscale). You need to convert your image to a numpy array.

It will give you an array where the highest number is the outcome of your digit.

Like: [0.2, 0.4, 0.9, 0.1, 0.3, 0.3, 0.5, 0.6, 0.6, 0.2]

So in this case the number would be a 2

If you really want to draw a box around it, you need an object detector which is way more complex and time consuming.

  • Related