Theano2.1.5-基础知识之打印出theano的图
来自:http://deeplearning.net/software/theano/tutorial/printing_drawing.html
Printing/Drawing Theano graphs
Theano提供的函数theano.printing.pprint() 和 theano.printing.debugprint() 可以用来在编译前和后打印一个graph到终端上。 pprint() 该函数更紧凑而且更偏向于数学形式, debugprint() 更为的详细。 Theano同样提供pydotprint() 来生成一张有关该函数的图片。更详细的可以看看 printing – Graph Printing and Symbolic Print Statement.
note:当打印theano函数的时候,有时候会比较难读懂。为了简化过程,可以禁止一些theano优化,只要使用theano的flag: optimizer_excluding=fusion:inplace. 不要在工作执行的时候使用这个flag,这会使得graph更慢而且使用更多的内存。
考虑逻辑回归的例子:
>>> import numpy
>>> import theano
>>> import theano.tensor as T
>>> rng = numpy.random
>>> # Training data
>>> N = 400
>>> feats = 784
>>> D = (rng.randn(N, feats).astype(theano.config.floatX), rng.randint(size=N,low=0, high=2).astype(theano.config.floatX))
>>> training_steps = 10000
>>> # Declare Theano symbolic variables
>>> x = T.matrix("x")
>>> y = T.vector("y")
>>> w = theano.shared(rng.randn(feats).astype(theano.config.floatX), name="w")
>>> b = theano.shared(numpy.asarray(0., dtype=theano.config.floatX), name="b")
>>> x.tag.test_value = D[0]
>>> y.tag.test_value = D[1]
>>> # Construct Theano expression graph
>>> p_1 = 1 / (1 + T.exp(-T.dot(x, w)-b)) # Probability of having a one
>>> prediction = p_1 > 0.5 # The prediction that is done: 0 or 1
>>> # Compute gradients
>>> xent = -y*T.log(p_1) - (1-y)*T.log(1-p_1) # Cross-entropy
>>> cost = xent.mean() + 0.01*(w**2).sum() # The cost to optimize
>>> gw,gb = T.grad(cost, [w,b])
>>> # Training and prediction function
>>> train = theano.function(inputs=[x,y], outputs=[prediction, xent], updates=[[w, w-0.01*gw], [b, b-0.01*gb]], name = "train")
>>> predict = theano.function(inputs=[x], outputs=prediction, name = "predict")
友好的打印结果:
>>> theano.printing.pprint(prediction)
'gt((TensorConstant{1} / (TensorConstant{1} + exp(((-(x \\dot w)) - b)))),
TensorConstant{0.5})'
调试打印
预编译图:
>>> theano.printing.debugprint(prediction) Elemwise{gt,no_inplace} [@A] ''|Elemwise{true_div,no_inplace} [@B] ''| |DimShuffle{x} [@C] ''| | |TensorConstant{1} [@D]| |Elemwise{add,no_inplace} [@E] ''| |DimShuffle{x} [@F] ''| | |TensorConstant{1} [@D]| |Elemwise{exp,no_inplace} [@G] ''| |Elemwise{sub,no_inplace} [@H] ''| |Elemwise{neg,no_inplace} [@I] ''| | |dot [@J] ''| | |x [@K]| | |w [@L]| |DimShuffle{x} [@M] ''| |b [@N]|DimShuffle{x} [@O] ''|TensorConstant{0.5} [@P]
编译后的图:
>>> theano.printing.debugprint(predict) Elemwise{Composite{GT(scalar_sigmoid((-((-i0) - i1))), i2)}} [@A] '' 4|CGemv{inplace} [@B] '' 3| |Alloc [@C] '' 2| | |TensorConstant{0.0} [@D]| | |Shape_i{0} [@E] '' 1| | |x [@F]| |TensorConstant{1.0} [@G]| |x [@F]| |w [@H]| |TensorConstant{0.0} [@D]|InplaceDimShuffle{x} [@I] '' 0| |b [@J]|TensorConstant{(1,) of 0.5} [@K]
graph的图片打印
预编译图
>>> theano.printing.pydotprint(prediction, outfile="pics/logreg_pydotprint_prediction.png", var_with_name_simple=True)
The output file is available at pics/logreg_pydotprint_prediction.png
编译后的图
>>> theano.printing.pydotprint(predict, outfile="pics/logreg_pydotprint_predict.png", var_with_name_simple=True)
The output file is available at pics/logreg_pydotprint_predict.png
优化后的训练图:
>>> theano.printing.pydotprint(train, outfile="pics/logreg_pydotprint_train.png", var_with_name_simple=True)
The output file is available at pics/logreg_pydotprint_train.png
Theano2.1.5-基础知识之打印出theano的图相关推荐
- IP 基础知识“全家桶”,45 张图一套带走!
转载自: https://mp.weixin.qq.com/s/kPjFeefB1Xsbc2bHz_Or1Q 前言 前段时间,有读者希望我写一篇关于 IP 分类地址.子网划分等的文章,他反馈常常混淆, ...
- IP 基础知识“全家桶”,45 张图一套带走
目录 前言 正文 前菜 -- IP 基本认识 网络层与数据链路层有什么关系呢? 主菜 -- IP 地址的基础知识 IP 地址的分类 无分类地址 CIDR 公有 IP 地址与私有 IP 地址 IP 地址 ...
- IP 基础知识全家桶,45 张图一套带走
转:图解IP 基础知识,非常用心的图解教程 感谢作者小林coding 版权 前言 图解关于 IP 分类地址.子网划分等的文章, IP 基础知识,作者分为三道菜: 首先是前菜 「 IP 基本认识 」 其 ...
- 进程和线程基础知识全家桶,30 张图一套带走
前言 先来看看一则小故事 我们写好的一行行代码,为了让其工作起来,我们还得把它送进城(进程)里,那既然进了城里,那肯定不能胡作非为了. 城里人有城里人的规矩,城中有个专门管辖你们的城管(操作系统),人 ...
- Java并发基础知识,我用思维导图整理好了
文章目录 1.基本概念 2.线程创建和运行 3.常用方法 3.1.线程等待与通知 3.2.线程休眠 3.3.让出优先权 3.4.线程中断 4.线程状态 5.线程上下文切换 6.线程死锁 7.线程分类 ...
- 进程、线程基础知识全家桶,30 张图一套带走
前言 先来看看一则小故事 我们写好的一行行代码,为了让其工作起来,我们还得把它送进城(进程)里,那既然进了城里,那肯定不能胡作非为了. 城里人有城里人的规矩,城中有个专门管辖你们的城管(操作系统),人 ...
- mysql数据库基础知识整理大全(思维导图)
- C什么k什么_K线图基础知识丨什么是K线散兵坑形态?K线散兵坑形态的操作与案例详解...
本文总共999字,预计阅读需要3分钟 今天我们给大家带来的是K线散兵坑形态,那么K线散兵坑形态应该怎么来操作呢?今天我们就结合相应的实战案例来为大家讲解一下吧. K线散兵坑形态的简介 散兵坑是指在股价 ...
- pytorch基础知识+构建LeNet对Cifar10进行训练+PyTorch-OpCounter统计模型大小和参数量+模型存储与调用
整个环境的配置请参考我另一篇博客.ubuntu安装python3.5+pycharm+anaconda+opencv+docker+nvidia-docker+tensorflow+pytorch+C ...
最新文章
- iOS点击空白收回键盘
- java中的保留字_Java中的保留字是哪些呢?
- Java源码详解六:ConcurrentHashMap源码分析--openjdk java 11源码
- PyPI又双叒叕发现恶意软件,能盗取信用卡还有后门程序
- thymeleaf依赖_玩转SpringBoot集成 Thymeleaf 模版引擎
- 计算机二级一年几次湖南省,湖南省计算机二级多少分可以通过
- ML之RS之CF:基于用户的CF算法—利用大量用户的电影及其评分数据集对一个新用户Jason进行推荐电影+(已知Jason曾观看几十部电影及其评分)
- 禁止linux使用密码ssh,linux centos7服务器使用密钥登录ssh同时禁止root密码登录
- Caffe+Kubuntu16.04_X64+CUDA 8.0配置
- MySQL实现差集(Minus)和交集(Intersect)
- Win10上VMware的问题汇总
- Linux(debian7)错误集锦(二)之安装Gnome报错Failed to start unit user@1000.service
- Matlab中用到的bsxfun函数
- python处理word_python操作word,自动化办公
- 理解Virtual方法。
- OpenCV4.5.1 | 使用一行代码将图像匹配性能提高14%
- php环境下cache失效,cache缓存失效高并发读数据库的问题
- 2018阿里菜鸟无人仓一面面经
- [已解决]The server cannot or will not process the request due to something that is perceived to be
- 移动电影院新版本新功能新体验
热门文章
- python教程三角函数_Python入门之三角函数tan()函数实例详解
- 华为云计算之ebackup了解
- 计算机网络:TCP滑动窗口的流量控制和拥塞控制
- Zookeeper分布式一致性原理(一):分布式架构
- 计算机二级7月考试,2020年计算机二级MS Office考试每日一练(7月27日)
- linux安装的mysql没有密码_linux系统安装的mysql数据库root帐户密码忘记的两种处理方法...
- No changes detected
- Ubuntu 16.04 和 Ubuntu 18.04 启用 点击Launcher图标,窗口实现最小化 功能
- MAC安装mysql8.0.11以及修改root密码
- 笔记--待解决,整理