框架tensorflow2
TensorFlow 2
TensorFlow 激励函数
TensorFlow 添加层:
思考:matmul和multiply两种乘法的区别:http://www.soaringroad.com/?p=560
[root@shenzhen tensorflow]# cat tensor5.py
#!/usr/local/bin/python3
#coding:utf-8 import tensorflow as tf def add_layer(inputs,in_size, out_size, activation_function=None):
Weights = tf.Variable(tf.random_normal([in_size, out_size]))
biases = tf.Variable(tf.zeros([1,out_size]) + 0.1)
Wx_plus_b = tf.matmul(inputs, Weights) + biases
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
return outputs
[root@shenzhen tensorflow]#
TensorFlow建造神经网络:
np.linspace() 在指定的间隔内返回均匀间隔的数字 (https://blog.csdn.net/you_are_my_dream/article/details/53493752 )
np.square() 计算各元素的平方 ( https://blog.csdn.net/u014595019/article/details/49686789 )numpy添加新的维度:newaxis : https://blog.csdn.net/xtingjie/article/details/72510834
Tensorflow之神经网络nn模块详解 : https://blog.csdn.net/qq_36653505/article/details/81105894
tf.nn.relu(features, name = None) 函数的作用是计算激活函数relu,即max(features, 0)。即将矩阵中每行的非最大值置0。
#!/usr/bin/env python
# -*- coding: utf-8 -*- import tensorflow as tf a = tf.constant([-1.0, 2.0])
with tf.Session() as sess:
b = tf.nn.relu(a)
print sess.run(b)
以上程序输出的结果是:[0. 2.]
tf.placeholder(dtype, shape=None, name=None)
此函数可以理解为形参,用于定义过程,在执行的时候再赋具体的值;
dtype:数据类型。常用的是tf.float32,tf.float64等数值类型
shape:数据形状。默认是None,就是一维值,也可以是多维,比如[2,3], [None, 3]表示列是3,行不定;
name:名称。
神经网络练习:
[root@shenzhen tensorflow]# python3 tensor5.py
2018-08-22 22:11:59.038325: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
0.21489698
0.0061830464
0.004771502
0.004203358
0.0038625475
0.0036302141
0.0034819138
0.003381687
0.0032702887
0.0031953293
0.0031516913
0.0031179215
0.0030919597
0.003072145
0.003055951
0.0030398055
0.0030263881
0.0030082215
0.0029918654
0.0029769428
[root@shenzhen tensorflow]# cat tensor5.py
#!/usr/local/bin/python3
#coding:utf-8 import tensorflow as tf
import numpy as np def add_layer(inputs,in_size, out_size, activation_function=None):
Weights = tf.Variable(tf.random_normal([in_size, out_size]))
biases = tf.Variable(tf.zeros([1,out_size]) + 0.1)
Wx_plus_b = tf.matmul(inputs, Weights) + biases
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
return outputs x_data = np.linspace(-1,1,300)[:,np.newaxis]
noise = np.random.normal(0,0.05,x_data.shape)
y_data = np.square(x_data) - 0.5 + noise xs = tf.placeholder(tf.float32,[None,1])
ys = tf.placeholder(tf.float32,[None,1]) l1 = add_layer(xs,1,10,activation_function=tf.nn.relu)
prediction = add_layer(l1,10,1,activation_function=None) loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),\
reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss) init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init) for i in range(1000):
sess.run(train_step,feed_dict={xs:x_data, ys:y_data})
if i % 50 == 0:
print(sess.run(loss,feed_dict={xs:x_data, ys:y_data}))
tensorflow 优化器:
1,初级用 tf.train.GradientDescentOptimizer
2, 高级: tf.train.MomentumOptimizer 和 tf.train.RMSPropOptimizer
解决centos中"ImportError: No module named _tkinter"问题: https://blog.csdn.net/liuxingen/article/details/53907877
框架tensorflow2的更多相关文章
- Google工程师亲授 Tensorflow2.0-入门到进阶
第1章 Tensorfow简介与环境搭建 本门课程的入门章节,简要介绍了tensorflow是什么,详细介绍了Tensorflow历史版本变迁以及tensorflow的架构和强大特性.并在Tensor ...
- TensorFlow2.0(1):基本数据结构—张量
1 引言 TensorFlow2.0版本已经发布,虽然不是正式版,但预览版都发布了,正式版还会远吗?相比于1.X,2.0版的TensorFlow修改的不是一点半点,这些修改极大的弥补了1.X版本的反人 ...
- 『TensorFlow2.0正式版教程』极简安装TF2.0正式版(CPU&GPU)教程
0 前言 TensorFlow 2.0,今天凌晨,正式放出了2.0版本. 不少网友表示,TensorFlow 2.0比PyTorch更好用,已经准备全面转向这个新升级的深度学习框架了. 本篇文章就 ...
- 『TensorFlow2.0正式版』TF2.0+Keras速成教程·零:开篇简介与环境准备
此篇教程参考自TensorFlow 2.0 + Keras Crash Course,在原文的基础上进行了适当的总结与改编,以适应于国内开发者的理解与使用,水平有限,如果写的不对的地方欢迎大家评论指出 ...
- Google老师亲授 TensorFlow2.0实战: 入门到进阶
Google老师亲授 TensorFlow2.0 入门到进阶 课程以Tensorflow2.0框架为主体,以图像分类.房价预测.文本分类等项目为依托,讲解Tensorflow框架的使用方法,同时学习到 ...
- 一文上手TensorFlow2.0(一)
目录: Tensorflow2.0 介绍 Tensorflow 常见基本概念 从1.x 到2.0 的变化 Tensorflow2.0 的架构 Tensorflow2.0 的安装(CPU和GPU) Te ...
- 【实践】如何利用tensorflow的object_detection api开源框架训练基于自己数据集的模型(Windows10系统)
如何利用tensorflow的object_detection api开源框架训练基于自己数据集的模型(Windows10系统) 一.环境配置 1. Python3.7.x(注:我用的是3.7.3.安 ...
- 手把手教你安装TensorFlow2 GPU 版本
参考博客:https://blog.csdn.net/weixin_44170512/article/details/103990592 (本文中部分内容引自参考博客,请大家支持原作者!) 感谢大佬的 ...
- 推荐模型NeuralCF:原理介绍与TensorFlow2.0实现
1. 简介 NCF是协同过滤在神经网络上的实现--神经网络协同过滤.由新加坡国立大学与2017年提出. 我们知道,在协同过滤的基础上发展来的矩阵分解取得了巨大的成就,但是矩阵分解得到低维隐向量求内积是 ...
随机推荐
- 谷歌技术"三宝"之MapReduce
江湖传说永流传:谷歌技术有"三宝",GFS.MapReduce和大表(BigTable)! 谷歌在03到06年间连续发表了三篇很有影响力的文章,分别是03年SOSP的GFS,04年 ...
- Python3 tkinter基础 Menu 添加菜单栏
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- WinForm动态查询
WinForm 动态查询 1. 使用场景 在对数据进行筛选, 包含多个筛选字段时适用. 2. 接口设计 /// <summary> /// 定义可作为追加到 WHERE 子句的控件接口 / ...
- 理解 Python 装饰器看这一篇就够了
讲 Python 装饰器前,我想先举个例子,虽有点污,但跟装饰器这个话题很贴切. 每个人都有的内裤主要功能是用来遮羞,但是到了冬天它没法为我们防风御寒,咋办?我们想到的一个办法就是把内裤改造一下,让它 ...
- R语言-默认镜像设置
问题1:如何设置默认镜像 你希望下载某些R包,因此希望设定默认的CRAN网站镜像,这样R每次下载时不需要你选择镜像. 解决方案 该方案要求用户R系统中包含一个.Rprofile文件,如方法3.16描述 ...
- 在客户端先通过JS验证后再将表单提交到服务器
问题:想要在客户端先通过JS验证后再将表单提交到服务器 参考资料: jQuery 事件 - submit() 方法 试验过程: 服务器端使用PHP <html> <head> ...
- css3 向上淡入 小图标翻转 360度旋转
代码 <!DOCTYPE HTML> <html> <style type="text/css"> div { border: 1px soli ...
- Vnpy二次开发应用所需图标
在针对Vnpy二次开发时,很多窗口中需要使用到“小图标” 给大家分享一个UI的专业图标网,上面资源齐全. https://www.iconfont.cn/collections?personal=1
- StrokePlus常用脚本
1.按照时间创建文本文件并打开 文本文件并没有什么快捷方式,每次都要右键,找新建,找文本文档,临时写点什么还要保存,写名字,懒得写就打aa,bb的,挺烦的. 难点在于用lua没法知道当前鼠标所在的文件 ...
- redis特性,使用场景
redis特性: 1.redis保存在内存中,读写速度快. 2.redis--持久化(断电数据不丢失:对数据的更新将异步保存到磁盘上). 3.redis数据结构丰富 4.redis功能丰富 5.简单( ...