tensorflow的函数
1.
if __name__=="__main__":
tf.app.run()#运行之前定义的main函数
#将传进来的参数,以及flags.FLAGS定义的参数传入到main函数中
2.
#flags的定义
flags=tf.app.flags
flags.DEFINE_string("save_path",None,"Directory to write the model and training summaries.")
FLAGS=flags.FLAGS
3.
tf.random_uniform((2,2),minval=-0.5,maxval=0.5,dtype=tf.float32)
tf.random_uniform([2,2],minval=-0.5,maxval=0.5,dtype=tf.float32)
#是相同的
4.
tf.nn.uniform_candidate_sampler()#均匀地采样出类别子集
tf.nn.log_uniform_candidate_sampler()
tf.nn.fixed_unigram_candidate_sampler()#按照用户提供的概率分布进行采样
tf.nn.uniform_candidate_sampler(true_classes=,num_true=,num_sampled=,unique=,range_max=,)
#目标的类别,size为[batch_size,num_true]
# num_true 每个训练例子目标类别的数量
#num_sampled 每个批次抽样的类别的数量
#unique 被抽样的类别是否是unique的
#range_max 可能类别的数量
5.
tf.nn.embedding_lookup(params=,ids=,)
#在params中查找ids元素的表示、
#抽取出ids元素行号的数据,列的维度是相同的
tf.reduce_mean(-tf.reduce_sum(y*tf.log(a),reduction_indices=[1]))
#0是按照列向量求均值,1是按照行向量求均值,得到的都是行向量
6.最简单的mnist识别代码
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
import numpy as np
import math
import gzip
import os
import tempfile
from tensorflow.examples.tutorials.mnist import input_data
flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_string('data_dir', '/Users/guoym/Desktop/models-master', 'Directory for storing data')
mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True)
x = tf.placeholder(tf.float32, [None, 784]) # 占位符
y = tf.placeholder(tf.float32, [None, 10])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
a = tf.nn.softmax(tf.matmul(x, W) + b)
cross_entropy=tf.reduce_mean(-tf.reduce_sum(y*tf.log(a),reduction_indices=[1]))
#注意区分矩阵乘法和一一对应的乘法
optimizer=tf.train.GradientDescentOptimizer(0.5)
train=optimizer.minimize(cross_entropy) correct_prediction=tf.equal(tf.argmax(a,1),tf.argmax(y,1))
accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32)) sess=tf.InteractiveSession()
tf.initialize_all_variables().run()
for i in range(1000):
batch_xs,batch_ys=mnist.train.next_batch(100)
train.run({x:batch_xs,y:batch_ys})
print (sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels}))
tensorflow的函数的更多相关文章
- tf.nn.embedding_lookup TensorFlow embedding_lookup 函数最简单实例
tf.nn.embedding_lookup TensorFlow embedding_lookup 函数最简单实例 #!/usr/bin/env python # -*- coding: utf-8 ...
- 深度学习TensorFlow常用函数
tensorflow常用函数 TensorFlow 将图形定义转换成分布式执行的操作, 以充分利用可用的计算资源(如 CPU 或 GPU.一般你不需要显式指定使用 CPU 还是 GPU, Tensor ...
- tensorflow softmax_cross_entropy_with_logits函数
1.softmax_cross_entropy_with_logits tf.nn.softmax_cross_entropy_with_logits(logits, labels, name=Non ...
- tensorflow l2_loss函数
1.l2_loss函数 tf.nn.l2_loss(t, name=None) 解释:这个函数的作用是利用 L2 范数来计算张量的误差值,但是没有开方并且只取 L2 范数的值的一半,具体如下: out ...
- tensorflow l2_normalize函数
1.l2_normalize函数 tf.nn.l2_normalize(x, dim, epsilon=1e-12, name=None) 解释:这个函数的作用是利用 L2 范数对指定维度 dim 进 ...
- tensorflow softsign函数应用
1.softsign函数 图像 2.tensorflow softsign应用 import tensorflow as tf input=tf.constant([0,-1,2,-30,30],dt ...
- tensorflow elu函数应用
1.elu函数 图像: 2.tensorflow elu应用 import tensorflow as tf input=tf.constant([0,-1,2,-3],dtype=tf.float3 ...
- TensorFlow 常用函数汇总
本文介绍了tensorflow的常用函数,源自网上整理. TensorFlow 将图形定义转换成分布式执行的操作, 以充分利用可用的计算资源(如 CPU 或 GPU.一般你不需要显式指定使用 CPU ...
- TensorFlow 常用函数与方法
摘要:本文主要对tf的一些常用概念与方法进行描述. tf函数 TensorFlow 将图形定义转换成分布式执行的操作, 以充分利用可用的计算资源(如 CPU 或 GPU.一般你不需要显式指定使用 CP ...
- 『TensorFlow』函数查询列表_神经网络相关
tf.Graph 操作 描述 class tf.Graph tensorflow中的计算以图数据流的方式表示一个图包含一系列表示计算单元的操作对象以及在图中流动的数据单元以tensor对象表现 tf. ...
随机推荐
- Golang的安装和编译
一.下载安装(Ubuntu16.04) 1.下载地址:https://golang.google.cn/dl/ 2.下载Linux版本的安装包go1.10.3.linux-amd64.tar.gz并复 ...
- markdown 入门教程(完整版)
Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式. 1. 标题 Markdown支持6种级别的标题,对应html标签 h1 ~ h6 ...
- 汇编窥探Swift String的底层
String(字符串),是所有编程语言中非常重要的成员,因此非常值得去深入研究.众所周知,字符串的本质是字符序列,由若干个字符组成.比如字符串 "iOS" 由 'i'.'O'.'S ...
- Chrome插件开发(三)
在日常工作中,我们可能经常需要在手机端测试我们所做的页面,如果每次在手机端测试都手输网址,网址短的还好,如果长的网址也需要一个字母一个字母去敲,那无疑是一场噩梦,试想我们有一个工具只需要点击一个按钮就 ...
- 使用asp.net core 3.0 搭建智能小车2
上一篇中我们把基本的运行环境搭建完成了,这一篇中,我们实战通过树莓派B+连接HC-SR04超声波测距传感器,用c# GPIO控制传感器完成距离测定,并将距离显示在网页上. 1.HC-SR04接线 传感 ...
- CVE-2019-0708: Windows RDP远程漏洞无损检测工具下载
CVE-2019-0708: Windows RDP远程漏洞无损检测工具下载 0x00下载链接 https://free.360totalsecurity.com/CVE-2019-0708/dete ...
- Redis过期--淘汰机制的解析和内存占用过高的解决方案
echo编辑整理,欢迎转载,转载请声明文章来源.欢迎添加echo微信(微信号:t2421499075)交流学习. 百战不败,依不自称常胜,百败不颓,依能奋力前行.--这才是真正的堪称强大!!! Red ...
- NOIP模拟测试14
考完19了再写14,我也是够咕的. 14的题很好,也充分暴露了我的问题. T1是个分析性质推结论的题 对于区间[L,R],不妨设a[L]!=a[R],那么两个端点对答案没有贡献,也就是[L+1,R], ...
- SSHD服务安全的连接
SSHD服务 SSH 安全的远程连接 OpenSSH 工具 centos服务端的包:openssh-server centos客户端的包:openssh-clients 主要配置文件一般安装完成后再/ ...
- 虚拟机操作系统内设置固定IP以及克隆虚拟机
以下为我自己整理的克隆虚拟机和设置固定IP的方法,记录一下,以防忘记: 桥接模式网络配置 1.配置ip地址等信息在/etc/sysconfig/network-scripts/ifcfg-ens33文 ...