Tensorflow 神经网络模型架构

  • Tensorflow 神经网络模型架构
    • 神经网络模型

Tensorflow 神经网络模型架构

import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
print ("packs loaded")
packs loaded
mnist = input_data.read_data_sets('data/', one_hot=True)
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
tf.compat.v1.disable_eager_execution()

神经网络模型

# NETWORK TOPOLOGIES
n_hidden_1 = 256   # 第一层神经元个数
n_hidden_2 = 128   # 第二层神经元个数
n_input    = 784   # 输入像素点个数
n_classes  = 10    # 分类类别# INPUTS AND OUTPUTS
x = tf.compat.v1.placeholder("float", [None, n_input])
y = tf.compat.v1.placeholder("float", [None, n_classes])# NETWORK PARAMETERS
stddev = 0.1
weights = {'w1': tf.Variable(tf.random.normal([n_input, n_hidden_1], stddev=stddev)),'w2': tf.Variable(tf.random.normal([n_hidden_1, n_hidden_2], stddev=stddev)),'out': tf.Variable(tf.random.normal([n_hidden_2, n_classes], stddev=stddev))
}
biases = {'b1': tf.Variable(tf.random.normal([n_hidden_1])),'b2': tf.Variable(tf.random.normal([n_hidden_2])),'out': tf.Variable(tf.random.normal([n_classes]))
}
print ("NETWORK READY")
NETWORK READY
def multilayer_perceptron(_X, _weights, _biases):layer_1 = tf.nn.sigmoid(tf.add(tf.matmul(_X, _weights['w1']), _biases['b1'])) layer_2 = tf.nn.sigmoid(tf.add(tf.matmul(layer_1, _weights['w2']), _biases['b2']))return tf.add(tf.matmul(layer_2, _weights['out']),  _biases['out'])
# PREDICTION
pred = multilayer_perceptron(x, weights, biases)# LOSS AND OPTIMIZER
# 损失函数:交叉熵函数 - tf.nn.softmax_cross_entropy_with_logits()
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y)) # 梯度下降优化器
optm = tf.compat.v1.train.GradientDescentOptimizer(learning_rate=0.01).minimize(cost) # 精确度
corr = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))    # 精确值
accr = tf.reduce_mean(tf.cast(corr, "float"))# INITIALIZER
init = tf.compat.v1.global_variables_initializer()
print ("FUNCTIONS READY")
FUNCTIONS READY
training_epochs = 20
batch_size      = 100
display_step    = 4# LAUNCH THE GRAPH
sess = tf.compat.v1.Session()
sess.run(init)# OPTIMIZE
for epoch in range(training_epochs):avg_cost = 0.total_batch = int(mnist.train.num_examples/batch_size)# ITERATIONfor i in range(total_batch):batch_xs, batch_ys = mnist.train.next_batch(batch_size)feeds = {x: batch_xs, y: batch_ys}# 梯度下降求解; feed_dict:填充数据sess.run(optm, feed_dict=feeds)# 计算损失值avg_cost += sess.run(cost, feed_dict=feeds)avg_cost = avg_cost / total_batch# DISPLAYif (epoch+1) % display_step == 0:print ("Epoch: %03d/%03d cost: %.9f" % (epoch, training_epochs, avg_cost))feeds = {x: batch_xs, y: batch_ys}train_acc = sess.run(accr, feed_dict=feeds)print ("TRAIN ACCURACY: %.3f" % (train_acc))feeds = {x: mnist.test.images, y: mnist.test.labels}test_acc = sess.run(accr, feed_dict=feeds)print ("TEST ACCURACY: %.3f" % (test_acc))print ("OPTIMIZATION FINISHED")
Epoch: 003/020 cost: -137763.534588068
TRAIN ACCURACY: 0.100
TEST ACCURACY: 0.113
Epoch: 007/020 cost: -295983.534829545
TRAIN ACCURACY: 0.110
TEST ACCURACY: 0.113
Epoch: 011/020 cost: -454205.143522727
TRAIN ACCURACY: 0.100
TEST ACCURACY: 0.113
Epoch: 015/020 cost: -612429.083977273
TRAIN ACCURACY: 0.130
TEST ACCURACY: 0.113
Epoch: 019/020 cost: -770653.138977273
TRAIN ACCURACY: 0.170
TEST ACCURACY: 0.113
OPTIMIZATION FINISHED

30
TEST ACCURACY: 0.113
Epoch: 019/020 cost: -770653.138977273
TRAIN ACCURACY: 0.170
TEST ACCURACY: 0.113
OPTIMIZATION FINISHED

Tensorflow 神经网络模型架构相关推荐

  1. TensorFlow神经网络模型训练

    TensorFlow神经网络模型训练 fashion_MNIST数据集的模型识别训练 fashion_mnist数据加载 图片保存 fashion_mnist可视化 神经网络模型训练,预测 模型保存 ...

  2. 神经网络模型架构教程pdf,如何搭建神经网络模型

    利用人工神经网络建立模型的步骤 人工神经网络有很多种,我只会最常用的BP神经网络.不同的网络有不同的结构和不同的学习算法.简单点说,人工神经网络就是一个函数.只是这个函数有别于一般的函数.它比普通的函 ...

  3. Python人脸微笑识别2-----Ubuntu16.04基于Tensorflow卷积神经网络模型训练的Python3+Dlib+Opencv实现摄像头人脸微笑检测

    Python人脸微笑识别2--卷积神经网络进行模型训练目录 一.微笑数据集下载 1.微笑数据集下载 2.创建人脸微笑识别项目 3.数据集上传至Ubuntu人脸微笑识别项目文件夹 二.Python代码实 ...

  4. 基于tensorflow的MNIST手写字识别(一)--白话卷积神经网络模型

    一.卷积神经网络模型知识要点卷积卷积 1.卷积 2.池化 3.全连接 4.梯度下降法 5.softmax 本次就是用最简单的方法给大家讲解这些概念,因为具体的各种论文网上都有,连推导都有,所以本文主要 ...

  5. 在Android上将ONNX神经网络模型与TensorFlow Lite结合使用

    目录 下一步 在这里,我们从预先训练的模型中制作TensorFlow Lite模型. 这是有关在Android上使用TensorFlow Lite的系列文章中的第二篇.在上一节中,设置了开发环境以使用 ...

  6. TensorFlow精进之路(三):两层卷积神经网络模型将MNIST未识别对的图片筛选出来

    1.概述 自从开了专栏<TensorFlow精进之路>关于对TensorFlow的整理思路更加清晰.上两篇讲到Softmax回归模型和两层卷积神经网络模型训练MNIST,虽然使用神经网络能 ...

  7. Tensorflow实现简单的手写数字神经网络模型

    1.全连接层直接实现手写数字神经网络 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...

  8. Tensorflow中基本概念及神经网络模型的介绍

    这篇文章主要介绍TF中张量,图,变量,会话以及神经网络模型. 张量(tensor) Tensor可以说是Tensor flow中最重要的概念之一,毕竟Tensor flow翻译过来就是张量流. 张量是 ...

  9. Tensorflow深度学习实战之(七)--MP神经元与BP神经网络模型

    本文是在GPU版本的Tensorflow = 2.6.2 , 英伟达显卡驱动CUDA版本 =11.6,Python版本 = 3.6, 显卡为3060的环境下进行验证实验的!!! 文章目录 一.M-P神 ...

最新文章

  1. 新能源关键技术预见的研究
  2. 连影--影子007的回忆
  3. 干货 | 算法工程师入门第三期——黄李超讲物体检测
  4. SAP 电商云 Spartacus UI shipping method 切换时的 spinner 显示
  5. SAP UI5 OData Json model name
  6. how is value displayed in BSP UI from model node data binding
  7. html扩展xhtml在线,告别html,迎来xhtml
  8. springboot整合activemq加入会签,自动重发机制,持久化
  9. Shell学习笔记---变量赋值与运算(原创)
  10. Python入门--python中的global
  11. 怪兽星座欲并购,运动饮料成为新战场?
  12. 有效缓解腰部不适,十星小双鱼腰部按摩器上手体验
  13. php的命名空间和自动加载实现
  14. 原函数的导数与反函数的导数互为倒数
  15. MyBatisPuls入门案例
  16. mac 阿里云ecs配置php,在Mac OS下配置PHP开发环境
  17. electron中引入iohook来监听系统级鼠标键盘事件
  18. 爬取堆糖蜜桃猫图片并下载到本地
  19. Java压缩文件和文件夹为zip格式
  20. Windows 8.1新型启动方式“WIMBoot”基础简介以及初步探索

热门文章

  1. 幸福工厂超级计算机有什么用,幸福工厂全替换配方简评
  2. Android Studio快速集成讯飞SDK实现文字朗读功能
  3. 深度解析——图片加载到内存中的大小计算内存优化
  4. 37 | 什么是SLI、SLO、SLA
  5. CMD 窗口的 基本命令
  6. 什么是UML(UML总结)
  7. MATLAB中均值、方差、均方差的计算方法
  8. 大数据中数据挖掘技术的挑战
  9. 财经数据----同花顺技术选股,附代码
  10. 阿里云短信验证码提示“Message“:“模板变量缺少对应参数值“