经典设计网站,网站seo平台,如何创建一个和淘宝一样的网站,市场调研报告500字文章目录 0 前言1 项目运行效果2 深度学习手写字符识别原理2.1 结构解析2.2 C1层2.3 S2层S2层和C3层连接 2.4 F6与C5层 3 写数字识别算法模型的构建3.1 输入层设计3.2 激活函数的选取3.3 卷积层设计3.4 降采样层3.5 输出层设计 4 网络模型的总体结构5 部分实现代码6 最后 0 前言…文章目录0 前言1 项目运行效果2 深度学习手写字符识别原理2.1 结构解析2.2 C1层2.3 S2层S2层和C3层连接2.4 F6与C5层3 写数字识别算法模型的构建3.1 输入层设计3.2 激活函数的选取3.3 卷积层设计3.4 降采样层3.5 输出层设计4 网络模型的总体结构5 部分实现代码6 最后0 前言这两年开始毕业设计和毕业答辩的要求和难度不断提升传统的毕设题目缺少创新和亮点往往达不到毕业答辩的要求这两年不断有学弟学妹告诉学长自己做的项目系统达不到老师的要求。并且很难找到完整的毕设参考学习资料。为了大家能够顺利以及最少的精力通过毕设学长分享优质毕业设计项目提供大家参考学习今天要分享的是毕业设计 基于深度学习的新闻文本分类算法系统(源码论文)学长这里给一个题目综合评分(每项满分5分)难度系数3分工作量3分创新点4分 项目分享:见文末!1 项目运行效果视频效果毕业设计 深度学习手写数字识别2 深度学习手写字符识别原理这里以LeNet-5为例进行深度学习字符识别的大致讲解。2.1 结构解析这是原始的应用于手写数字识别的网络我认为这也是最简单的深度网络。LeNet-5不包括输入一共7层较低层由卷积层和最大池化层交替构成更高层则是全连接和高斯连接。LeNet-5的输入与BP神经网路的不一样。这里假设图像是黑白的那么LeNet-5的输入是一个32*32的二维矩阵。同时输入与下一层并不是全连接的而是进行稀疏连接。本层每个神经元的输入来自于前一层神经元的局部区域(5×5)卷积核对原始图像卷积的结果加上相应的阈值得出的结果再经过激活函数处理输出即形成卷积层C层。卷积层中的每个特征映射都各自共享权重和阈值这样能大大减少训练开销。降采样层S层为减少数据量同时保存有用信息进行亚抽样。2.2 C1层第一个卷积层C1层由6个特征映射构成每个特征映射是一个28×28的神经元阵列其中每个神经元负责从5×5的区域通过卷积滤波器提取局部特征。一般情况下滤波器数量越多就会得出越多的特征映射反映越多的原始图像的特征。本层训练参数共6×(5×51)156个每个像素点都是由上层5×525个像素点和1个阈值连接计算所得共28×28×156122304个连接。2.3 S2层S2层是对应上述6个特征映射的降采样层pooling层。pooling层的实现方法有两种分别是max-pooling和mean-poolingLeNet-5采用的是mean-pooling即取n×n区域内像素的均值。C1通过2×2的窗口区域像素求均值再加上本层的阈值然后经过激活函数的处理得到S2层。pooling的实现在保存图片信息的基础上减少了权重参数降低了计算成本还能控制过拟合。本层学习参数共有1*6612个S2中的每个像素都与C1层中的2×2个像素和1个阈值相连共6×(2×21)×14×145880个连接。S2层和C3层连接S2层和C3层的连接比较复杂。C3卷积层是由16个大小为10×10的特征映射组成的当中的每个特征映射与S2层的若干个特征映射的局部感受野大小为5×5相连。其中前6个特征映射与S2层连续3个特征映射相连后面接着的6个映射与S2层的连续的4个特征映射相连然后的3个特征映射与S2层不连续的4个特征映射相连最后一个映射与S2层的所有特征映射相连。此处卷积核大小为5×5所以学习参数共有6×(3×5×51)9×(4×5×51)1×(6×5×51)1516个参数。而图像大小为28×28因此共有151600个连接。S4层是对C3层进行的降采样与S2同理学习参数有16×11632个同时共有16×(2×21)×5×52000个连接。C5层是由120个大小为1×1的特征映射组成的卷积层而且S4层与C5层是全连接的因此学习参数总个数为120×(16×251)48120个。2.4 F6与C5层F6是与C5全连接的84个神经元所以共有84×(1201)10164个学习参数。卷积神经网络通过通过稀疏连接和共享权重和阈值大大减少了计算的开销同时pooling的实现一定程度上减少了过拟合问题的出现非常适合用于图像的处理和识别。3 写数字识别算法模型的构建3.1 输入层设计输入为28×28的矩阵而不是向量。3.2 激活函数的选取Sigmoid函数具有光滑性、鲁棒性和其导数可用自身表示的优点但其运算涉及指数运算反向传播求误差梯度时求导又涉及乘除运算计算量相对较大。同时针对本文构建的含有两层卷积层和降采样层由于sgmoid函数自身的特性在反向传播时很容易出现梯度消失的情况从而难以完成网络的训练。因此本文设计的网络使用ReLU函数作为激活函数。3.3 卷积层设计学长设计卷积神经网络采取的是离散卷积卷积步长为1即水平和垂直方向每次运算完移动一个像素。卷积核大小为5×5。3.4 降采样层学长设计的降采样层的pooling方式是max-pooling大小为2×2。3.5 输出层设计输出层设置为10个神经网络节点。数字0~9的目标向量如下表所示4 网络模型的总体结构5 部分实现代码使用Python调用TensorFlow的api完成手写数字识别的算法。注我的程序运行环境是Win10,python3.。当然也可以在Linux下运行由于TensorFlow对py2和py3兼容得比较好在Linux下可以在python2.7中运行。#!/usr/bin/env python2# -*- coding: utf-8 -*-#import modulesimportnumpyasnpimportmatplotlib.pyplotasplt#from sklearn.metrics import confusion_matriximporttensorflowastfimporttimefromdatetimeimporttimedeltaimportmathfromtensorflow.examples.tutorials.mnistimportinput_datadefnew_weights(shape):returntf.Variable(tf.truncated_normal(shape,stddev0.05))defnew_biases(length):returntf.Variable(tf.constant(0.1,shapelength))defconv2d(x,W):returntf.nn.conv2d(x,W,strides[1,1,1,1],paddingSAME)defmax_pool_2x2(inputx):returntf.nn.max_pool(inputx,ksize[1,2,2,1],strides[1,2,2,1],paddingSAME)#import datadatainput_data.read_data_sets(./data,one_hotTrue)# one_hot means [0 0 1 0 0 0 0 0 0 0] stands for 2print(Size of:)print(--Training-set:\t\t{}.format(len(data.train.labels)))print(--Testing-set:\t\t{}.format(len(data.test.labels)))print(--Validation-set:\t\t{}.format(len(data.validation.labels)))data.test.clsnp.argmax(data.test.labels,axis1)# show the real test labels: [7 2 1 ..., 4 5 6], 10000valuesxtf.placeholder(float,shape[None,784],namex)x_imagetf.reshape(x,[-1,28,28,1])y_truetf.placeholder(float,shape[None,10],namey_true)y_true_clstf.argmax(y_true,dimension1)# Conv 1layer_conv1{weights:new_weights([5,5,1,32]),biases:new_biases([32])}h_conv1tf.nn.relu(conv2d(x_image,layer_conv1[weights])layer_conv1[biases])h_pool1max_pool_2x2(h_conv1)# Conv 2layer_conv2{weights:new_weights([5,5,32,64]),biases:new_biases([64])}h_conv2tf.nn.relu(conv2d(h_pool1,layer_conv2[weights])layer_conv2[biases])h_pool2max_pool_2x2(h_conv2)# Full-connected layer 1fc1_layer{weights:new_weights([7*7*64,1024]),biases:new_biases([1024])}h_pool2_flattf.reshape(h_pool2,[-1,7*7*64])h_fc1tf.nn.relu(tf.matmul(h_pool2_flat,fc1_layer[weights])fc1_layer[biases])# Droupout Layerkeep_probtf.placeholder(float)h_fc1_droptf.nn.dropout(h_fc1,keep_prob)# Full-connected layer 2fc2_layer{weights:new_weights([1024,10]),biases:new_weights([10])}# Predicted classy_predtf.nn.softmax(tf.matmul(h_fc1_drop,fc2_layer[weights])fc2_layer[biases])# The output is like [0 0 1 0 0 0 0 0 0 0]y_pred_clstf.argmax(y_pred,dimension1)# Show the real predict number like 2# cost function to be optimizedcross_entropy-tf.reduce_mean(y_true*tf.log(y_pred))optimizertf.train.AdamOptimizer(learning_rate1e-4).minimize(cross_entropy)# Performance Measurescorrect_predictiontf.equal(y_pred_cls,y_true_cls)accuracytf.reduce_mean(tf.cast(correct_prediction,float))withtf.Session()assess:inittf.global_variables_initializer()sess.run(init)train_batch_size50defoptimize(num_iterations):total_iterations0start_timetime.time()foriinrange(total_iterations,total_iterationsnum_iterations):x_batch,y_true_batchdata.train.next_batch(train_batch_size)feed_dict_train_op{x:x_batch,y_true:y_true_batch,keep_prob:0.5}feed_dict_train{x:x_batch,y_true:y_true_batch,keep_prob:1.0}sess.run(optimizer,feed_dictfeed_dict_train_op)# Print status every 100 iterations.ifi%1000:# Calculate the accuracy on the training-set.accsess.run(accuracy,feed_dictfeed_dict_train)# Message for printing.msgOptimization Iteration:{0:6}, Training Accuracy: {1:6.1%}# Print it.print(msg.format(i1,acc))# Update the total number of iterations performedtotal_iterationsnum_iterations# Ending timeend_timetime.time()# Difference between start and end_times.time_difend_time-start_time# Print the time-usageprint(Time usage:str(timedelta(secondsint(round(time_dif)))))test_batch_size256defprint_test_accuracy():# Number of images in the test-set.num_testlen(data.test.images)cls_prednp.zeros(shapenum_test,dtypenp.int)i0whileinum_test:# The ending index for the next batch is denoted j.jmin(itest_batch_size,num_test)# Get the images from the test-set between index i and jimagesdata.test.images[i:j,:]# Get the associated labelslabelsdata.test.labels[i:j,:]# Create a feed-dict with these images and labels.feed_dict{x:images,y_true:labels,keep_prob:1.0}# Calculate the predicted class using Tensorflow.cls_pred[i:j]sess.run(y_pred_cls,feed_dictfeed_dict)# Set the start-index for the next batch to the# end-index of the current batchij cls_truedata.test.cls correct(cls_truecls_pred)correct_sumcorrect.sum()accfloat(correct_sum)/num_test# Print the accuracymsgAccuracy on Test-Set: {0:.1%} ({1}/{2})print(msg.format(acc,correct_sum,num_test))# Performance after 10000 optimization iterationsoptimize(num_iterations10000)print_test_accuracy()savew_hl1layer_conv1[weights].eval()saveb_hl1layer_conv1[biases].eval()savew_hl2layer_conv2[weights].eval()saveb_hl2layer_conv2[biases].eval()savew_fc1fc1_layer[weights].eval()saveb_fc1fc1_layer[biases].eval()savew_opfc2_layer[weights].eval()saveb_opfc2_layer[biases].eval()np.save(savew_hl1.npy,savew_hl1)np.save(saveb_hl1.npy,saveb_hl1)np.save(savew_hl2.npy,savew_hl2)np.save(saveb_hl2.npy,saveb_hl2)np.save(savew_hl3.npy,savew_fc1)np.save(saveb_hl3.npy,saveb_fc1)np.save(savew_op.npy,savew_op)np.save(saveb_op.npy,saveb_op)运行结果显示测试集中准确率大概为99.2%。查看混淆矩阵篇幅有限更多详细设计见设计论文6 最后项目包含内容完整详细设计论文 项目分享:见文末!