S
S
SKEPTIC2019-05-22 16:21:20
Python
SKEPTIC, 2019-05-22 16:21:20

Why does a neural network give correct results only on a test dataset?

There is a neural network. She is trained on the FASHION_MNIST dataset. Recognition of test datasets works great, the neural network almost always guesses. But here I decided to download the image of T-shirts and boots from the Internet and submit it to the input of the neural network.
She mistook her boots for a bag, she mistook the first T-shirt for pants, and she mistook the second T-shirt for a bag. It seems to me that somehow I'm converting the image into an array of data incorrectly.

from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
from tensorflow import keras
from keras.preprocessing.image import ImageDataGenerator
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image

class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)

model = tf.keras.models.load_model('deeplearn.h5')

train_images = Image.open('1.jpg')
arr = np.asarray(train_images, dtype='uint8')
arr = arr.reshape(28, 28)
predictions = model.predict(arr.reshape(1, 28, 28))
answer = np.argmax(predictions[0])
print(class_names[answer])

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Arseny Kravchenko, 2019-05-22
@Arseny_Info

Either an overfit to the dataset, or the preprocessing of images during training and on the test of images from the Internet is different.

B
badproger12years, 2019-05-22
@badproger12years

For fashion_mnist, the best solution would be a convolutional neural network of 8-9 layers.
You either have overfitting (solution: add to fit, the parameter validation_split = 0.2 or 0.1, and look at what epoch the error on the test sample increases and set this epoch to fit),
or you should not hope that the neuron is trained on black and white photos, will be able to give the correct answer on a completely different T-shirt that is not even included in the sample (which is even more so from the Internet).
PS This guy will tell you everything about neurons, from head to toe
https://youtu.be/GKpVjx_b1Z4
PSS Use a sigmoid neural network that trains on one photo and gives an answer either similar (1) or not (0).

I
ivodopyanov, 2019-05-23
@ivodopyanov

Another possibility is that your model is somehow loaded incorrectly from a file, and when predicting there are random weights. But this is easy to check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question