mnist 图像识别,一维算法,非卷积神经网络
2022/2/20 9:26:24
本文主要是介绍mnist 图像识别,一维算法,非卷积神经网络,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
# author: Roy.G # author: Roy.G # author: Roy.G from keras.datasets import mnist import matplotlib.pyplot as plt from keras.utils.np_utils import to_categorical #import to_categorical import numpy as np from keras.models import Sequential as sq from keras.layers import Dense as dn import tensorflow as tf import os # os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" # os.environ["CUDA_VISIBLE_DEVICES"]="0" (x_train,y_train),(xt,yt)=mnist.load_data() # plt.imshow(x_train[9,:,:],cmap='gray') #绘制图片 # plt.show() # print(y_train[9]) x_train=x_train.reshape(60000,784)/255 xt=xt.reshape(10000,784)/255 y_train=to_categorical(y_train,10) # 将输入转换为one hot 格式的数据 yt=to_categorical(yt,10) print(yt,type(yt)) # 1. 建立模型 model = sq() # 2.建立神经元 # dense = dn(units=2,activation='sigmoid',input_dim=1) # 3.将神经元加入模型 model.add(dn(units=256,activation='relu',input_dim=784)) model.add(dn(units=256,activation='relu')) model.add(dn(units=256,activation='relu')) model.add(dn(units=10,activation='softmax')) #softmax,是一种分类器 # 4. 编译模型 model.compile(loss='categorical_crossentropy',optimizer=tf.keras.optimizers.SGD(0.05),metrics=['accuracy']) # loss=代价函数,sgd=随机梯度下降算法,metrics=['accuracy],categorical_crossentropy'=交叉商函数 # model.fit(x_train,y_train,epochs=50,batch_size=1024) #batch_size=每次训练所使用的样本数量 #5. 验证模型 loss,accuracy=model.evaluate(xt,yt) # 6.训练模型 pres=model.predict(x_train) # plot_utils.show_scatter_surface(x,y,model) mg=model.get_weights() print(mg) print('envaluate',loss,accuracy)
这篇关于mnist 图像识别,一维算法,非卷积神经网络的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-28smol ai
- 2024-03-27探索小浣熊家族:商汤科技的AI智能助手革新编程与办公
- 2024-03-22dns_probe_finished_nxdomain 解决
- 2024-03-18rails time zone
- 2024-03-11ai入门
- 2024-03-07gpg failed to sign the data
- 2024-03-04retool vs airtable
- 2024-02-22hexo ai
- 2024-02-20name 'train_test_split' is not defined
- 2024-02-07史上最全知识图谱建模实践(下):多元关系架构