神经网络与深度学习 自制MNIST测试数据供神经网络测试
2017-08-05 18:55
676 查看
一、利用windows自带画图工具
画布大小为28*28,用刷子工具,颜色为黑色,写字并保存。
二、python代码将其转为灰度图
其中用到了第三方库
三、在原神经网络代码中加入自定义测试数据(详细见上一文章)
四、运行结果(准确性还有待提升)
画布大小为28*28,用刷子工具,颜色为黑色,写字并保存。
二、python代码将其转为灰度图
from PIL import Image import numpy as np class Data2: def getTestPicArray(self,filename): im = Image.open(filename) x_s = 28 y_s = 28 out = im.resize((x_s, y_s), Image.ANTIALIAS) im_arr = np.array(out.convert('L')) num0 = 0 num255 = 0 threshold = 100 for x in range(x_s): for y in range(y_s): if im_arr[x][y] > threshold: num255 = num255 + 1 else: num0 = num0 + 1 if (num255 > num0): #print("convert!") for x in range(x_s): for y in range(y_s): im_arr[x][y] = 255 - im_arr[x][y] if (im_arr[x][y] < threshold): im_arr[x][y] = 0 # if(im_arr[x][y] > threshold) : im_arr[x][y] = 0 # else : im_arr[x][y] = 255 # if(im_arr[x][y] < threshold): im_arr[x][y] = im_arr[x][y] - im_arr[x][y] / 2 out = Image.fromarray(np.uint8(im_arr)) out.save("C:\\Users\\Administrator\\Desktop\\out\\" + filename) # print im_arr nm = im_arr.reshape((1, 784)) nm = nm.astype(np.float32) nm = np.multiply(nm, 1.0 / 255.0) # print(nm.reshape((784,1)).shape) #print(nm.shape) return nm.reshape((784,1)) # return nm #getTestPicArray(r"C:\Users\Administrator\Desktop\2.png") #Data2().getTestPicArray(r"2.png")
其中用到了第三方库
三、在原神经网络代码中加入自定义测试数据(详细见上一文章)
import mnist_loader training_data, validation_data, test_data = mnist_loader.load_data_wrapper() training_data = list(training_data) import network net = network.Network([784, 30, 10]) net.SGD(training_data, 30, 10, 2.0, test_data=test_data) import image_data import test4 for i in range(0,10): file = str(i)+".png" #data = image_data.ImageData().getArrayFromImage(file) data = test4.Data2().getTestPicArray(file) print("预测:",file,"的结果为",net.cjtest(data)) print("-----------------------------------------------------------------------") for i in range(0,10): file = str(i)+".png" data = image_data.ImageData().getArrayFromImage(file) #data = test4.Data2().getTestPicArray(file) print("预测:",file,"的结果为",net.cjtest(data))
四、运行结果(准确性还有待提升)
相关文章推荐
- 神经网络与深度学习 使用Python实现基于梯度下降算法的神经网络和自制仿MNIST数据集的手写数字分类可视化程序 web版本
- 深度学习小白——神经网络3(数据预处理,dropout,正则化)
- 神经网络与深度学习 1.6 使用Python实现基于梯度下降算法的神经网络和MNIST数据集的手写数字分类程序
- 深度学习与计算机视觉系列(7)_神经网络数据预处理,正则化与损失函数
- 斯坦福大学深度学习公开课cs231n学习笔记(7)神经网络防止数据过拟合:损失函数和正则化
- tensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试
- tensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试
- 【AI速查表】神经网络、机器学习、深度学习与数据科学一览
- 深度学习与计算机视觉系列(7)_神经网络数据预处理,正则化与损失函数
- 深度学习与计算机视觉系列(7)_神经网络数据预处理,正则化与损失函数
- tensorflow 学习笔记(四) - mnist实例--用简单的神经网络来训练和测试
- 深度学习_caffe (4) 基于mnist实例搭建新的神经网络&在caffe中添加层
- Caffe深度学习入门—— caffenet 微调网络 训练自己的数据并测试训练的模型
- 数据分析、数据挖掘、机器学习、神经网络、深度学习和人工智能概念区别(入门级别)
- 深度学习与计算机视觉系列(7)_神经网络数据预处理,正则化与损失函数
- 【计算机视觉】【神经网络与深度学习】YOLO v2 detection训练自己的数据
- 【神经网络与深度学习】如何将别人训练好的model用到自己的数据上
- 深度学习与计算机视觉系列(7)_神经网络数据预处理,正则化与损失函数
- 深度学习-传统神经网络使用TensorFlow框架实现MNIST手写数字识别
- 【计算机视觉】【神经网络与深度学习】YOLO v2 detection训练自己的数据2