(5.4.1)--5.4PracticalCase.pdf

上传人:刘静 文档编号:52839950 上传时间:2022-10-24 格式:PDF 页数:5 大小:257.38KB
返回 下载 相关 举报
(5.4.1)--5.4PracticalCase.pdf_第1页
第1页 / 共5页
(5.4.1)--5.4PracticalCase.pdf_第2页
第2页 / 共5页
点击查看更多>>
资源描述

《(5.4.1)--5.4PracticalCase.pdf》由会员分享,可在线阅读,更多相关《(5.4.1)--5.4PracticalCase.pdf(5页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、Introduction to Artificial Intelligence Image Classification with Multilayer Perceptron Nankai University Introduction to Artificial Intelligence Image classification is based on the semantic information of the image to distinguish different categories of images,which is an important basic problem i

2、n computer vision.This experiment uses a Multi-Layer Perceptron(MLP)model to predict handwritten digital pictures.1.Preparing data set 1.1 Data set description The MNIST data set contains 60,000 training sets and 10,000 test data sets.Divided into pictures and labels,the picture is a 28*28 pixel mat

3、rix,and the labels are 10 numbers from 0 to 9.1.2 Download and prepare the MINST dataset import tensorflow as tf import numpy as np(x_train,y_train),(x_test,y_test)=tf.keras.datasets.mnist.load_data()x_train=tf.keras.utils.normalize(x_train,axis=1)x_test=tf.keras.utils.normalize(x_test,axis=1)#Norma

4、lization x_train and x_test are used to obtain mnist training set and test set respectively.2.Create the MLP The following code is to define a simple MLP.There are three layers,two hidden Introduction to Artificial Intelligence layers with a size of 100 and an output layer with a size of 10.Because

5、the MNIST data set is a handwritten grayscale image of 0 to 9,number of category is 10,so the final output size is 10.The activation function of the final output layer is softmax,so the final output layer is equivalent to a classifier.With an input layer,the structure of the multi-layer perceptron i

6、s:input layer-hidden layer-hidden layer-output layer.model=tf.keras.Sequential(tf.keras.layers.Flatten(),tf.keras.layers.Dense(100,activation=relu),tf.keras.layers.Dense(100,activation=relu),tf.keras.layers.Dense(10,activation=softmax)model.build(None,784,1)model.summary()3.Compile and train the mod

7、el Introduction to Artificial Intelligence pile(optimizer=adam,#Optimizer loss=sparse_categorical_crossentropy,#Cross entropy loss function metrics=accuracy)#Label#Train model history=model.fit(x_train,y_train,validation_data=(x_test,y_test),epochs=10,verbose=1)4.Evaluate the model from matplotlib i

8、mport pyplot as plt def plot_graphs(history,string):plt.plot(history.historystring)plt.plot(history.historyval_+string)plt.xlabel(Epochs)plt.ylabel(string)plt.legend(string,val_+string)plt.show()plot_graphs(history,accuracy)plot_graphs(history,loss)Introduction to Artificial Intelligence Our simple MLP model has achieved a test accuracy of over 97%.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com