Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何准备MNIST格式的图像数据集_Python_Tensorflow_Neural Network_Deep Learning_Mnist - Fatal编程技术网

Python 如何准备MNIST格式的图像数据集

Python 如何准备MNIST格式的图像数据集,python,tensorflow,neural-network,deep-learning,mnist,Python,Tensorflow,Neural Network,Deep Learning,Mnist,我使用本文提供的脚本在MNIST数据集上训练了一个神经网络模型 我想在自定义数据集上测试经过训练的模型,因此我编写了一个小脚本predict.py,加载经过训练的模型并将数据提供给它。但它不起作用 我认为仅将图像大小调整为28x28是不够的,必须进行一些其他预处理,以使其与MNIST标准兼容 这是我为测试而编写的脚本 predict.py from scipy.misc import imread import tensorflow as tf import numpy as np import

我使用本文提供的脚本在
MNIST
数据集上训练了一个神经网络模型

我想在自定义数据集上测试经过训练的模型,因此我编写了一个小脚本
predict.py
,加载经过训练的模型并将数据提供给它。但它不起作用

我认为仅将图像大小调整为
28x28
是不够的,必须进行一些其他预处理,以使其与
MNIST
标准兼容

这是我为测试而编写的脚本

predict.py

from scipy.misc import imread
import tensorflow as tf
import numpy as np
import cv2 as cv
import glob

files = glob.glob('data2/*.*')

dig_cont = [cv.imread(fl, 0) for fl in files]

img_data = []
for i in range(len(dig_cont)):
    img = cv.resize(dig_cont[i], (28, 28))  
    img = img.reshape(img.shape[0], img.shape[1], 1)
    img_data.append(img)

print("Restoring Model ...")

sess = tf.Session()

tf_saver = tf.train.import_meta_graph('model/model.meta')

tf_saver.restore(sess, tf.train.latest_checkpoint('model'))

print("Model restored")

x = tf.get_default_graph().get_tensor_by_name('X:0')
print('x :', x.shape)
y = tf.get_default_graph().get_tensor_by_name('Y:0')
print('y :', y.shape)

dict_data = {x: img_data}

result = sess.run(y, feed_dict=dict_data)
print(result)

sess.close()
可以找到详细的错误报告