with tf.Session() as sess、 和tf.nn.tanh的用法以及作用
tf.nn.tanh 双曲正切曲线一个Session可能会拥有一些资源,例如Variable或者Queue。当我们不再需要该session的时候,需要将这些资源进行释放。有两种方式, 调用session.close()方法; 使用with tf.Session()创建上下文(Context)来执行,当上下文退出时自动释放。1. Session提供了Operation执行和Tensor求值的环境; 由于回话接受以后需要手动关闭,不然变量没有办法释放; 2. 以下方法可以不用手动关闭 使用with tf.Session()创建上下文(Context)来执行,当上下文退出时自动释放
代码实例:
import tensorflow as tfa = [1.,3.,5.]
b = [[1.,3.,5.],[2,4,6]]
L1 = tf.nn.tanh(a)
L2 = tf.nn.tanh(b)sess1 =tf.Session()print("数组的双曲结果1:",L1)
print("数组的双曲结果2:",sess1.run(L1))
sess1.close()# 2. 实例
init = tf.global_variables_initializer() # 这个也是一个知识点:tf.global_variables_initializer()什么时候用
with tf.Session() as sess:sess.run(init)print("数组的双曲结果:",sess.run(L1))print('矩阵的双曲结果',sess.run(L2))
with tf.Session() as sess、 和tf.nn.tanh的用法以及作用相关推荐
- 关于tensorflow2.0的tf.Session() as sess的说明
import tensorflow.compat.v1 as tf #import tensorflow as tf tf.disable_eager_execution() #2.0版本与1.0版本 ...
- tensorflow 无法执行sess =tf .session ()_深度学习|费解的tensorflow
学过Python的小伙伴都会觉得,python的语法简单,逻辑清晰.虽然tensorflow是python的一个库(并不是标准库),但是使用并不简单,你可能会被tensorflow的奇怪语法设计困惑, ...
- tf.nn.embedding_lookup()的用法
函数: tf.nn.embedding_lookup( params, ids, partition_strategy='mod', name=None, validate_indices=True, ...
- 【TensorFlow】tf.nn.softmax_cross_entropy_with_logits的用法
[TensorFlow]tf.nn.softmax_cross_entropy_with_logits的用法 from:https://blog.csdn.net/mao_xiao_feng/arti ...
- tf.nn.in_top_k的用法
http://blog.csdn.net/uestc_c2_403/article/details/73187915 tf.nn.in_top_k组要是用于计算预测的结果和实际结果的是否相等,返回一个 ...
- tf.nn.rnn_cell.DropoutWrapper用法细节案例2
-- coding: utf-8 -- import tensorflow as tf from tensorflow.contrib import rnn 导入 MINST 数据集 from ten ...
- with tf.Session(config=tf.ConfigProto(log_device_placement=True))
这个加上后,不能顺利利用gpu了, with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess,tf.devic ...
- tf.InteractiveSession()与tf.Session()
tf.InteractiveSession() tf.InteractiveSession():它能让你在运行图的时候,插入一些计算图,这些计算图是由某些操作(operations)构成的.这对于工作 ...
- 对比tensorflow查看打印输出张量Tensor的两种方法(急切执行tf.enable_eager_execution()和tf.Session.run())
第一种:tf.enable_eager_execution() # -*- coding: utf-8 -*- """ @File : 111.py @Time : 20 ...
最新文章
- Nginx配置文件nginx.conf中文详解(总结)
- jmeter(二)录制脚本
- matlab mobilenet v2,MobileNetV2-SSDLite代码分析-6 VOC Dataset
- python迭代算法_Python实现简单的梯度下降法
- python网络-计算机网络基础(23)
- 用C#写的汉语转拼音缩写的例子
- React Native编译错误:ReactAndroid:buildReactNdkLib FAILED
- UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb4 in position 176: in xxxx
- Memcacher win7 安装测试
- js sdk demo java_微信JS-SDK DEMO页面和示例代码
- xgboost的plot_importance绘图时出现的f0、f1、f2、f3、f4、f5等改为对应特征的字段名
- 维盟无线ap服务器地址,让WiFi飞起来!维盟室外无线AP桥接与中继配置方案
- 关于软件测试未来发展趋势分析与总结
- C++ 11基本语法及基本算法
- [日常技能]手机投屏到电视的5种方法
- WebService 深入详解
- UGUI图集的理解与使用
- 圣诞树太俗气,圣诞牛才够创意----阿里巴巴B2B高上大玩法的启示
- python查询mysql数据库_python针对mysql数据库的连接、查询、更新、删除操作示例...
- 2021年有哪些能用的活体人物虚拟主播