深度学习之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 分布式并 ...
随机推荐
- weflow的坑
开发工具weflow的坑 使用less,css预处理器.如果less文件有问题项目不能正常打开需要排除错误后才能正常打开.今天遇到个问题background:rgba(255,255,255 .35) ...
- eclipse配置tomcat,并部署一个Java web项目到tomcat上
引用链接:https://blog.csdn.net/cincoutcin/article/details/79408484 eclipse配置tomcat 1.windows——preference ...
- Windows下MongoDB的配置及其远程连接
基本操作MongoDB的基本安装https://blog.csdn.net/heshushun/article/details/77776706启动和配置MongoDB服务参考博客https://bl ...
- Mabitis中的#与$符号区别及用法介绍
这篇文章主要介绍了Mabitis中的 #{}与 ${} 符号区别,需要的朋友可以参考下 一.介绍 mybatis 中使用 Mapper.xml里面的配置进行 sql 查询,经常需要动态传递参数,例 ...
- PyTorch对ResNet网络的实现解析
PyTorch对ResNet网络的实现解析 1.首先导入需要使用的包 import torch.nn as nn import torch.utils.model_zoo as model_zoo # ...
- Druid连接技术
1.导入jar包 druid-1.0.9.jar导入数据库驱动jar包 2.定义配置文件 properties形式 可以叫任意名称,可以放置在任意目录下.(意味着不能自动加载,需要手动导入)3.加载配 ...
- SaltStack之return与job管理
目录 1. SaltStack组件之return 1.1 return流程 1.2 使用mysql作为return存储方式 2. job cache 2.1 job cache流程 2.2 job管理 ...
- 一点点学习PS--实战三
本节实战,练习多张图片合成,调色相饱和度,剪贴蒙版的使用场景,人物内发光,人物轮廓光以及多种图层混合模式的使用,深入了解图层蒙版 1.工具使用 (1)多边形套锁工具:适用于棱角分明的抠图区域,选中了区 ...
- C语言-条件编译使用分析
1.基本概念 条件编译的行为类似于C语言中的if…else… 条件编译是预编译指示命令,用于控制是否编译某段代码 2.实例分析 条件编译初探 22-1.c #include <stdio ...
- c数据结构 -- 栈与队列
栈和队列 ·栈和队列是两种常用的.重要的数据结构 ·栈和队列是限定插入和删除只能在表的“端点”进行的线性表 栈 只能在队尾插入,只能在队尾删除 -- 后进后出 表尾称为栈顶:表头称为栈底 插入元素到栈 ...