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. ...
随机推荐
- 你必须知道的容器监控 (3) Prometheus
本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章.上一篇介绍了Google开发的容器监控工具cAdvisor,但是其提供的操作界面 ...
- Python安装pyinstaller方法,以及将项目生成可执行程序的步骤
pyinstaller安装方法 前提:确保计算机安装了Python语言环境,并且正确配置了环境变量. 方法一:联网在线自动安装 选择一 Windows OS下进入cmd(命令行窗口) 输入:pip i ...
- egg-mongoose --- nodejs
项目 egg + mongoose 项目结构 配置 egg 安装模块 npm i egg-mongoose --save config/pulgin.js exports.mongoose = { e ...
- 微服务架构案例(05):SpringCloud 基础组件应用设计
本文源码:GitHub·点这里 || GitEE·点这里 更新进度(共6节): 01:项目技术选型简介,架构图解说明 02:业务架构设计,系统分层管理 03:数据库选型,业务数据设计规划 04:中间件 ...
- web中间件常见漏洞总结笔记
之前看吐司别人发的个文档,简单记的笔记 ----- IIS 解析漏洞 IIS 6 *.asp;.jpg会被当作asp解析 *.asp/ ...
- CSP-S:追忆
Warning:这一篇极其中二,开了那个大会莫名有感而发. 模拟测试17那套题啊... 开的这个大会为什么弄得我退役感如此强烈... 早就想收藏了,还是记下来吧 <入阵曲> 丹青千秋酿, ...
- Scrapy爬取豆瓣图书数据并写入MySQL
项目地址 BookSpider 介绍 本篇涉及的内容主要是获取分类下的所有图书数据,并写入MySQL 准备 Python3.6.Scrapy.Twisted.MySQLdb等 演示 代码 一.创建项目 ...
- NOIP模拟测试33
这次考试很失败. T1sb题,40分钟切了,当我打完对拍全过去上厕所的时候,碰到了yxm. yxm:我又自闭了,没有一点进展. 我:…… yxm:你会做几个? 我(思考再三):T1只会暴力. (我这么 ...
- 「Luogu 1821」[USACO07FEB]银牛派对Silver Cow Party
更好的阅读体验 Portal Portal1: Luogu Portal2: POJ Description One cow from each of N farms \((1 \le N \le 1 ...
- win7/win10系列的office安装与激活
Windows系列电脑安装office傻瓜式教程 一. 下载与安装 下载 (1).所需工具:迅雷 下载链接:http://xl9.xunlei.com/ 显示界面如下,点击“立即下载”即可,然后 ...