深度学习之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 分布式并 ...
随机推荐
- asp.net web core 部署问题汇总
记录所有部署时遇到的问题. 微软官网部署说明 转载自:.NET Core 3.0 构建和部署(测试过可以使用) A 单文件可执行文件(文件体积较大,合并所有依赖) asp. ...
- EL表达式无法获取boolean类型变量值
今天调试个程序, 有个名为isAdmin的boolean类型的变量在jsp页面获取到的值为空, 这根本就是没获取到或者变量不存在的状况啊,但是在Action中明明是赋值成false了. 上网查了一下有 ...
- python3练习100题——034
题目:练习函数调用. 这个很容易了. def hello_world(): return "hello, world!" def fun(): print(hello_world( ...
- 项目转移时发生的错误<springboot+mybatis(xml逆向工程自动生成)>
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'app ...
- OpenCV-Mat结构详解
前面博客中Mat函数谈到一些理解,但是理解的比较浅显,下面谈谈通道,行列等意义: Mat的常见属性 opencv中type类型· CV_<bit_depth>(S|U|F)C<num ...
- day30 NFS服务器概述
02. NFS存储服务概念介绍 NFS是Network File System的缩写,中文意思是网络文件共享系统, 它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录 存储服 ...
- TC基础与自动化
前言 互联网产品的测试常常要覆盖在不同网络下的表现,例如丢包,带宽受限,时延及抖动等网络较差的情况,为了测试场景的网络情况可定义及复现,就需要有个工具对弱网进行模拟.业界一些通用的弱网模拟工具,如NE ...
- numpy基础知识练习
# 1.导入numpy模块 # 2.创建一个大小为10的空向量 # 3.创建一个大小为10的空向量,但是第五个值为1 # 4.创建一个10-49的ndarray数组 # 5.创建一个3x3的矩阵,其值 ...
- oracle dataguard配置
1.archivelog设置:(存档模式) 2.standy controlfile 设置: alter database create standby controlfile as '/data/o ...
- 在 linux 中连接 mysql 数据库
命令格式 mysql -h主机地址 -u用户名 -p用户密码 登录本机 mysql mysql -u用户名 -p用户密码 实例 TD - X1数据库:/opt/lampp/bin/mysql -u r ...