1 Replies - 472 Views - Last Post: 03 July 2019 - 04:20 AM Rate Topic: -----

#1 RushabhVerma   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 13
  • Joined: 23-April 19

Does my test image needs to be pre-processed too?

Posted 03 July 2019 - 01:23 AM

I tried to test my trained model with an input image to predict but it was always inaccurate.

from __future__ import absolute_import, division, print_function
import tensorflow as tf

mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([

tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(100, activation=tf.nn.relu),
tf.keras.layers.Dropout(0.10),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])

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

history = model.fit(x_train, y_train, epochs=1)
model.evaluate(x_test, y_test)

import numpy as np
from keras.preprocessing import image
import PIL
test_image = image.load_img('Number 8_resized.jpg', target_size=(28, 28))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis=0)
result = model.predict(test_image.reshape(-1, 28, 28))
print("The predicited number is:")
print(np.argmax(result[0]))


Do I need to pre-process the above code? If yes how would I do it? Thanks.

This post has been edited by andrewsw: 03 July 2019 - 04:19 AM
Reason for edit:: added missing [code][/code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: Does my test image needs to be pre-processed too?

#2 andrewsw   User is online

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,229
  • Joined: 12-December 12

Re: Does my test image needs to be pre-processed too?

Posted 03 July 2019 - 04:20 AM

Why are you posting Python code in the C# forum? Topic moved.

Why aren't you wrapping your code in code tags? I have added them for you this time, but please include them next time. It isn't difficult, there are instructions directly in the box where you type your post(s).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1