Tnsorflow学习-day5

这篇博客介绍了TensorFlow中的dropout方法,讲解了tf.nn.dropout函数的使用,包括参数含义,并通过实例展示了如何在训练Mnist手写体数字识别模型中应用dropout技术。
摘要由CSDN通过智能技术生成

方法
tf.nn.dropout(x,keep_prob,noise_shape,seed,name)
x代表要删除的数据
keep_prob是float类型的值,代表x中每个数据被保留下来的概率
被保留下来的元素会乘以 1/keep_prob,没有被保留下来的元素乘以0
代码

  • 1、演示tf.nn.dropout()函数
x = tf.Variable(tf.ones([10,10]))
drop_keep = tf.placeholder(tf.float32,name='keep')

y  = tf.nn.dropout(x,drop_keep)

init_op = tf.initialize_all_variables()

with tf.Session() as sess:
    # print(sess.run(x))
    # print(x.eval())
    sess.run(init_op)
    print(sess.run(y,feed_dict={
   drop_keep:0.5}))
#一般输入层keep_prob为0.8,隐藏单元设置为0.5
  • 2、单隐藏层训练经典数据集Mnist手写体数字的识别
#经典数据集mnist下载

from tensorflow.examples.tutorials.mnist import input_data

mnist = input_data.read_data_sets(r'C://Users//ays//Desktop//GIThub类//mnist',one_hot=True)

#print("Training data and label size: ")
#print(mnist.train.images.shape,mnist.train.labels.shape)
#print("Testing data and label size: ")
#print(mnist.test.images.shape,mnist.test.labels.shape)
#print("Validating data and label size: ")
#print(mnist.validation.images.shape,mnist.validation.labels.shape)


#实现一个前馈神经网络识别手写字体的经典模型

#epoch:1次epoch代表跑完一次全部的数据
#batch_size:表示一次epoch中每次取batch_size大小的数据去训练,直至取完则完成本次#epoch
'''适量增大batch_size优势
1、跑完一次 epoch(全数据集)所需的迭代次数减少
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值