OK 400
OK 400

Reputation: 831

Using MNIST to print larger numbers

The MNIST dataset has all 10 numbers to train with. If I predict a 9, the model will give as output a 9. But, what if I want to predict the number 34.542? It will give me a wrong number, since I have only trained from 0 to 9. So, how could I predict a > 9 number?

This is my code, but I think it will not be useful here

model = tf.keras.models.Sequential()
    model.add(tf.keras.layers.Flatten())
    model.add(tf.keras.layers.Dense(units=128, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dense(units=128, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dense(units=10, activation=tf.nn.softmax))

    # Compiling and optimizing model
    model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

    # Training the model
    model.fit(X_train, y_train, epochs=3)

Upvotes: 1

Views: 339

Answers (1)

Lue Mar
Lue Mar

Reputation: 472

As said in the comments, you can't apply your model directly on an image of a large number. You have to :

  • apply a detection (localization) model to find and separate each digit. You'll get a bounding box for each digit.
  • apply your classification model on the extracted image of each bounding box, to get the prediction on the separated digits.

See this article for example.

Upvotes: 2

Related Questions