alasq / tensorflow-learning Goto Github PK
View Code? Open in Web Editor NEWtensorflow 学习
License: MIT License
tensorflow 学习
License: MIT License
定义张量之间如何去运算,程序会自动维护一个默认的计算图。如果定义了多个计算图,图之间的张量互不干扰。
TensorBoard是TensorFlow的可视化工具,可以形象的看到计算图。
张量其实就是一个多维数组,二维数组就是矩阵了。
会话是用来执行定义好的运算的
# 创建会话
sess=tf.Session()
# 执行会话,得到计算结果
sess.run(...)
# 结束会话,释放资源
sess.close()
https://playground.tensorflow.org/ playground(游乐场)在浏览器中有一个最简单的神经网络模型,能够可视化训练过程,可以帮助我们理解神经网络这个概念。
使用神经网络解决分类问题,大致分为四步
在解决多分类问题,我们会设置n个输出节点,理想状态下,我们识别一个样本数据类别k,那么这个类型的节点输出是1,其他节点输出是0,整体输出应该类似[0,1,0,0,0,0,0,0]
,而实际输出应该都是0到1之间的数。
原始结果肯定有不在0到1之间的。我们通过 softmax回归层把输出变换到0到1之间
交叉熵刻画的是两个概率分布之间的距离
H((1,0,0),(0.5,0.4,0.1))=-(0*log0.5+1*log0.4+0*log0.1)≈0.3
cross_entropy= -tf.reduce_mean(y_ * tf.log(tf.clip_by_value(y,1e-10,1.0)))
tf.clip_by_value(y,1e-10,1.0) 函数y里面的值,转换成1e-10 到1.0 之间的值
tf.log(x) 将x取对数
tf.reduce_mean 相加
假如预测商品销量,预测值比实际值多的话,会损失商品的成本,预测值比实际值少的话,就是损失销量。假设成本是10元,销售利润是1元。
用tf来标识这个自定义的损失函数
loss=tf.reduce_sum(tf.where(
tf.greater(v1,v2),
(v1-v2)*a,
(v2-v1)*b
))
python的发行版,除了python,还包含了很多常用的关于科学计算的库 。
我参考这篇文章安装成功的 https://www.cnblogs.com/ljysy/p/10660885.html
我这里下载的是 Anaconda 版本是 Anaconda3-5.3.1-Windows-x86_64.exe 对应的 python3.7.0
conda create -n tensorflow python=3.7.0
创建了一个独立的tensorflow的工作空间,在这个空间内使用的python版本为3.7.0conda activate tensorflow
激活这个名为tensorflow空间pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
在空间内配置pip的镜像源pip install tensorflow
https://www.jianshu.com/p/ef1ae10ba950
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
参考这个文章解决 https://www.cnblogs.com/zhaoshizi/p/9050768.html
在项目下 .vscode/settings.json
配置python的路径以及 code-runner的执行路径,设置成全局的也行吧
{
"python.pythonPath": "F:\\ProgramData\\Anaconda3\\envs\\tensorflow",
"code-runner.executorMap": {
"python": "set PYTHONIOENCODING=utf8 && F:\\ProgramData\\Anaconda3\\envs\\tensorflow\\python.exe",
},
}
试下tensorflow官网的例子,能跑起来就是成功了。有时候下载测试数据集的时候会失败,多试几次就好了
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.