跳过正文
  1. Posts/

tensorflow Session 学习笔记

·1 分钟

tensorflow-session官方文档

说下我自己的理解:

session中文一般叫会话,可以理解成op执行时候需要的一层虚拟化的封装。

op必须在session中才能执行。

tensor也是在tensor中才可以存在(tf.variable和tensor几乎是一回事,只是tf.variable的会话不要求session,也可以理解成tf.variable在session中就成了tensor.

需要注意的是session一般会占据资源,所以在使用完记得释放,或者写成with的形式(看到with总想叫成开域语句…感觉暴露年龄orz

下面这两种形式是等价的:

1# Using the `close()` method.
2sess = tf.Session()
3sess.run(...)
4sess.close()
5
6# Using the context manager.
7with tf.Session() as sess:
8  sess.run(...)

session本身有一些配置,我们使用configproto:

1# Launch the graph in a session that allows soft device placement and
2# logs the placement decisions.
3sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True,
4                                        log_device_placement=True))

allow_soft_placement的作用是自动选择可用的设备(如果指定的设备不可用(?)),防止指定的设备不可用而挂掉的情况。

log_device_placement :To find out which devices your operations and tensors are assigned to.

相关文章

Distributed Tensorflow : Cannot assign a device for operation save

·1 分钟
是在使用分布式tensorflow遇到的一个错误 报错如下: InvalidArgumentError (see above for traceback): Cannot assign a device for operation ‘save/Rest│| 2 GeForce GTX 1080 On | 0000:08:00.0 Off | N/A | oreV2_888’: Operation was explicitly assigned to /job:worker/task:0/device:CPU:0 but available │| 24% 39C P8 12W / 180W | 0MiB / 8114MiB | 0% Default | devices are [ /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/gpu:0 ]. Make sure the device specification refers to a valid device.

分布式 tensorflow 学习笔记(非最终版)

·4 分钟
感觉资料不是很多,先收集资料好了。 tf-distributed官网文档 SO-between-graph和in-graph的区别 inception.README.md SyncReplicasOptimizer SO_How does ps work in distribute Tensorflow? update:在多个nodes(机)上跑。。。tf默认是异步更新的。。。同步的话。。大概需要syncreplicasoptimizer?

TensorFlow Architecture 学习笔记(二)Adding a New Op

·6 分钟
Adding a New Op # * [目录](https://www.tensorflow.org/extend/adding_an_op#top_of_page) * [定义运算的接口](https://www.tensorflow.org/extend/adding_an_op#define_the_ops_interface) * [实现运算的核心部分(kernels)](https://www.tensorflow.org/extend/adding_an_op#implement_the_kernel_for_the_op) * [多线程cpu kernels](https://www.tensorflow.org/extend/adding_an_op#multi-threaded_cpu_kernels) * [GPU kernels](https://www.tensorflow.org/extend/adding_an_op#gpu_kernels) * [构建运算库](https://www.tensorflow.org/extend/adding_an_op#build_the_op_library) * [用系统编译器编译你的运算(TensorFlow binary installation)](https://www.tensorflow.org/extend/adding_an_op#compile_the_op_using_your_system_compiler_tensorflow_binary_installation) * [使用bazel编译你的运算(TensorFlow source installation)](https://www.tensorflow.org/extend/adding_an_op#compile_the_op_using_bazel_tensorflow_source_installation) * [在 Python 中使用你的运算](https://www.tensorflow.org/extend/adding_an_op#use_the_op_in_python) * [验证你添加的运算可以工作](https://www.tensorflow.org/extend/adding_an_op#verify_that_the_op_works) * [在你的运算中添加高级特性](https://www.tensorflow.org/extend/adding_an_op#building_advanced_features_into_your_op) * [条件检查和验证](https://www.tensorflow.org/extend/adding_an_op#conditional_checks_and_validation) * [Op registration](https://www.tensorflow.org/extend/adding_an_op#op_registration) * [GPU Support](https://www.tensorflow.org/extend/adding_an_op#gpu_support) * [用python 实现梯度](https://www.tensorflow.org/extend/adding_an_op#implement_the_gradient_in_python) * [Shape functions in C++](https://www.tensorflow.org/extend/adding_an_op#shape_functions_in_c) 对于要添加原生tensorflow中没有定义的运算的需求,首先建议在python层面,能不能将需要的op用其他原生的op拼凑起来。