深度学习之tensorflow框架(下)
def tensor_demo():
"""
张量的演示
:return:
"""
tensor1 = tf.constant(4.0)
tensor2 = tf.constant([1, 2, 3, 4])
linear_squares = tf.constant([[4], [9], [16], [25]], dtype=tf.int32)
print("tensor1:\n", tensor1)
print("tensor2:\n", tensor2)
print("linear_squares:\n", linear_squares) # 生成常用张量
tensor3 = tf.zeros(shape=(3, 4))
print("tensor3:\n", tensor3)
tensor4 = tf.ones(shape=(2, 3, 4))
print("tensor4:\n", tensor4)
tensor5 = tf.random_normal(shape=(2, 3), mean=1.75, stddev=0.2)
print("tensor5:\n", tensor5) with tf.compat.v1.Session() as sess:
print("tensor3_value:\n", tensor3.eval())
print("tensor4_value:\n", tensor4.eval())
print("tensor4_value:\n", tensor5.eval()) return None def tensoredit_demo():
"""
张量类型的修改
:return:
"""
linear_squares = tf.constant([[4], [9], [16], [25]], dtype=tf.int32)
print("linear_squares_before:\n", linear_squares) l_cast = tf.cast(linear_squares, dtype=tf.float32)
print("linear_squares_after:\n", linear_squares)
print("l_cast:\n", l_cast)
return None def editstaticshape_demo():
"""
更新/改变静态形状
:return:
"""
a = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, None])
b = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, 10])
c = tf.compat.v1.placeholder(dtype=tf.float32, shape=[3, 2])
print("a:\n", a)
print("b:\n", b)
print("c:\n", c) # 更新形状未确定的部分
a.set_shape([2, 3])
b.set_shape([2, 10])
print("a:\n", a)
print("b:\n", b) return None; def editshape_demo():
"""
更新/改变动态形状
不会改变原始的tensor
返回新的改变类型后的tensor
:return:
"""
a = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, None])
print("a:\n", a)
a.set_shape([2, 3])
print("a_setShape:\n", a)
# 元素个数没有变,还是2*3*1=6个
a_reshape = tf.reshape(a,shape=[2,3,1])
print("a_reshape:\n", a_reshape)
print("a:\n", a) return None; def variable_demo():
"""
变量的演示
变量需要显式初始化,才能运行值
:return:
"""
# 创建变量
# 使用命名空间可以使图的结构更加清晰
with tf.variable_scope("myscope"):
a = tf.Variable(initial_value=50)
b = tf.Variable(initial_value=40)
with tf.variable_scope("yourscope"):
c= tf.add(a,b)
print("a:\n",a)
print("b:\n",b)
print("c:\n",c) # 初始化变量
init = tf.global_variables_initializer() # 开启会话
with tf.Session() as sess:
sess.run(init)
a_value,b_value,c_value=sess.run([a,b,c])
print("a_value:\n",a_value)
print("b_value:\n",b_value)
print("c_value:\n",c_value) return None
深度学习之tensorflow框架(下)的更多相关文章
- 初学深度学习(TensorFlow框架的心得and经验总结)自用环境的总结
初学者的时间大部分浪费在了环境上了: 建议直接上Linux系统,我推荐国产的深度系统,deepin这几年一直在不断的发展,现在15.4已经很不错了 1,图形化界面很漂亮,内置正版crossover,并 ...
- 深度学习之tensorflow框架(中)
会话 开启会话 tf.Session用于完整的程序中 tf.InteractiveSession用于交互式上下文中的tensorflow 查看张量的值 都必须在会话里面 c_new_value=new ...
- 深度学习之tensorflow框架(上)
import tensorflow as tf import os os.environ[' def tensorflow_demo(): #原生python加法运算 a = 2; b=3; c=a+ ...
- 对比深度学习十大框架:TensorFlow 并非最好?
http://www.oschina.net/news/80593/deep-learning-frameworks-a-review-before-finishing-2016 TensorFlow ...
- 作为深度学习最强框架的TensorFlow如何进行时序预测!(转)
作为深度学习最强框架的TensorFlow如何进行时序预测! BigQuant 2 个月前 摘要: 2017年深度学习框架关注度排名tensorflow以绝对的优势占领榜首,本文通过一个小例子介绍了T ...
- 深度学习调用TensorFlow、PyTorch等框架
深度学习调用TensorFlow.PyTorch等框架 一.开发目标目标 提供统一接口的库,它可以从C++和Python中的多个框架中运行深度学习模型.欧米诺使研究人员能够在自己选择的框架内轻松建立模 ...
- 深度学习之 TensorFlow(一):基础库包的安装
1.TensorFlow 简介:TensorFlow 是谷歌公司开发的深度学习框架,也是目前深度学习的主流框架之一. 2.TensorFlow 环境的准备: 本人使用 macOS,Python 版本直 ...
- 深度学习之TensorFlow安装与初体验
深度学习之TensorFlow安装与初体验 学习前 搞懂一些关系和概念 首先,搞清楚一个关系:深度学习的前身是人工神经网络,深度学习只是人工智能的一种,深层次的神经网络结构就是深度学习的模型,浅层次的 ...
- [源码解析] 深度学习分布式训练框架 Horovod (1) --- 基础知识
[源码解析] 深度学习分布式训练框架 Horovod --- (1) 基础知识 目录 [源码解析] 深度学习分布式训练框架 Horovod --- (1) 基础知识 0x00 摘要 0x01 分布式并 ...
随机推荐
- itchat 爬了爬自己的微信通讯录
参考 一件有趣的事: 爬了爬自己的微信朋友 忘记从谁那里看到的了,俺也来试试 首先在annconda prompt里面安装了itchat包 pip install itchat 目前对python这里 ...
- vue 多组件路由处理方法
实现页面: 实现效果: 实现代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- centos8 apache+mysql+php
apache安装 dnf install httpd httpd-tools 开机启动 systemctl enable httpd 立即启动 systemctl start httpd 查看状态 s ...
- ansible笔记(15):循环(二)with_items/with_list/with_together/with_flattened
嵌套的列表(序列中的序列),示例如下: --- - hosts: 192.168.10.2 remote_user: root gather_facts: no tasks: - debug: msg ...
- 在myEclipse中根据图表自动生成Hibernate文件
1.新建一个Java Project项目,在scr中创建两个包:Com.hibernate.po 和com.hibernate.dao 2. 3.点击ok 4. 5.选中MyElipse Derby, ...
- jsp中引用的jstl 和fmt标签-详解
JSTL 核心标签库标签共有13个,功能上分为4类: 1.表达式控制标签:out.set.remove.catch 2.流程控制标签:if.choose.when.otherwise 3.循环标签:f ...
- Oracle 12c中CDB与PDB实例参数更改影响实验
基础知识单薄的同学,请逐字逐句阅读以下概念,来自于博客园AskScuti. 预备知识:什么是参数文件.存放位置.参数文件的分类和参数文件的命名方式.参数文件如何创建.参数文件加载顺序.参数分类.参数修 ...
- day18 sed
具体功能作用: 1) 文件中添加信息的能力 (增) ok 2) 文件中删除信息的能力 (删) ok 3) 文件中修改信息的能力 (改) 4) 文件中查询信息的能力 (查) OK sed命令的语法信息 ...
- 《深入理解Java虚拟机》读书笔记十
第十一章 晚期(运行期)优化 1.HotSpot虚拟机内的即时编译 解释器与编译器: 许多Java虚拟机的执行引擎在执行Java代码的时候都有解释执行(通过解释器执行)和编译执行(通过即时编译器产生 ...
- 题解【洛谷P6029】[JSOI2010]旅行
题面 简化版题意:给出 \(n\) 个点 \(m\) 条边的无向图,可以交换任意两条边的权值 \(k\) 次,求 \(1\) 结点到 \(n\) 结点的最短路. 考虑\(\text{DP}\). 把所 ...