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框架(下)的更多相关文章

  1. 初学深度学习(TensorFlow框架的心得and经验总结)自用环境的总结

    初学者的时间大部分浪费在了环境上了: 建议直接上Linux系统,我推荐国产的深度系统,deepin这几年一直在不断的发展,现在15.4已经很不错了 1,图形化界面很漂亮,内置正版crossover,并 ...

  2. 深度学习之tensorflow框架(中)

    会话 开启会话 tf.Session用于完整的程序中 tf.InteractiveSession用于交互式上下文中的tensorflow 查看张量的值 都必须在会话里面 c_new_value=new ...

  3. 深度学习之tensorflow框架(上)

    import tensorflow as tf import os os.environ[' def tensorflow_demo(): #原生python加法运算 a = 2; b=3; c=a+ ...

  4. 对比深度学习十大框架:TensorFlow 并非最好?

    http://www.oschina.net/news/80593/deep-learning-frameworks-a-review-before-finishing-2016 TensorFlow ...

  5. 作为深度学习最强框架的TensorFlow如何进行时序预测!(转)

    作为深度学习最强框架的TensorFlow如何进行时序预测! BigQuant 2 个月前 摘要: 2017年深度学习框架关注度排名tensorflow以绝对的优势占领榜首,本文通过一个小例子介绍了T ...

  6. 深度学习调用TensorFlow、PyTorch等框架

    深度学习调用TensorFlow.PyTorch等框架 一.开发目标目标 提供统一接口的库,它可以从C++和Python中的多个框架中运行深度学习模型.欧米诺使研究人员能够在自己选择的框架内轻松建立模 ...

  7. 深度学习之 TensorFlow(一):基础库包的安装

    1.TensorFlow 简介:TensorFlow 是谷歌公司开发的深度学习框架,也是目前深度学习的主流框架之一. 2.TensorFlow 环境的准备: 本人使用 macOS,Python 版本直 ...

  8. 深度学习之TensorFlow安装与初体验

    深度学习之TensorFlow安装与初体验 学习前 搞懂一些关系和概念 首先,搞清楚一个关系:深度学习的前身是人工神经网络,深度学习只是人工智能的一种,深层次的神经网络结构就是深度学习的模型,浅层次的 ...

  9. [源码解析] 深度学习分布式训练框架 Horovod (1) --- 基础知识

    [源码解析] 深度学习分布式训练框架 Horovod --- (1) 基础知识 目录 [源码解析] 深度学习分布式训练框架 Horovod --- (1) 基础知识 0x00 摘要 0x01 分布式并 ...

随机推荐

  1. H3C端口隔离

    一.端口隔离简介 为了实现端口间的二层隔离,可以将不同的端口加入不同的VLAN,但VLAN资源有限.采用端口隔离特性,用户只需要将端口加入到隔离组中,就可以实现隔离组内端口之间二层隔离,而不关心这些端 ...

  2. php文件上传 form表单形式

    1.php界面 <?php header( 'Content-Type:text/html;charset=utf-8 ');include_once("conn/conn.php&q ...

  3. cmd 下sql语句及结果

    Microsoft Windows [版本 10.0.14393](c) 2016 Microsoft Corporation.保留所有权利. C:\Users\李长青>mysql -uroot ...

  4. @RendSection{"scripts",require:false}的作用

    MVC视图中,Javascripts代码被放于下面的Razor代码中(@section Scripts{}). 好处:在视图进行JavaScript编程时,是一个很好的实践,在共享视图(_Layout ...

  5. const真有点烦

    在C++中const代替#define的操作,当定义一个const时必须附一个值给它:const int size = 100;通常C++编译器不为const创建存储空间,相反它把这个定义保存在符号表 ...

  6. eclipse怎么debug项目

    1.打断点,服务器debug启动 2.debug:打断点,加项目.f5:进入方法    f6:下一行代码   f8:执行到下一个断点处

  7. opencv:程序运行完保持dos窗口不关闭

    (1)在main函数最后加上 system("pause"); 第一种不能加到含有imshow图片显示的结尾:否则会不能显示图片: (2)利用cvWaitKey()函数: 这种能加 ...

  8. bzoj 1483

    Description N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1,2,2,1的四个布丁一共有3段颜色. Input 第 ...

  9. 题解 【Codefoeces687B】Remainders Game

    题意: 给出c1,c2,...cn,问对于任何一个正整数x,给出x%c1,x%c2,...的值x%k的值是否确定; 思路: 中国剩余定理.详见https://blog.csdn.net/acdream ...

  10. pygame 浅解

    import pygame from first_pygame.plane_spirit import * # 调用重载的精灵类 # 初始化 pygame.init() # 初始化所有所需游戏模块 s ...