通过测试 mnist 自己的测试图像,它可以正常工作,但是一旦我使用来自 mnist 外部的图像,它就会预测错误。我什至试图从 mnist 数据集中复制其中一张图像,但它仍然无法预测正确的数字(即使在 mnist 数据集中完全相同的图像是可以(预测)的)。
有人能看到我做错了什么吗?我猜图像的尺寸或形状有问题。
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense, Conv2D, Dropout, Flatten, MaxPooling2D
import cv2 as cv
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
input_shape = (28, 28, 1)
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
# Normalizing the RGB codes by dividing it to the max RGB value. …
Run Code Online (Sandbox Code Playgroud)