当前位置:首页 » python教程 » 正文

Tensorflow--取tensorf指定列的操作方式

看: 1003次  时间:2020-09-04  分类 : python教程

我就废话不多说了,大家还是直接看代码吧~

In [1]: import os
In [2]: os.environ["CUDA_VISIBLE_DEVICES"] = "0"
In [3]: import tensorflow as tf
In [4]:sess =tf.Session()
In [5]: input = tf.constant([[[1,2,3],[4,5,6],[7,8,9]],[[10,11,12],[13,14,15],[1
 ...: 6,17,18]]])

In [6]: input.get_shape()
Out[6]: TensorShape([Dimension(2), Dimension(3), Dimension(3)])

In [7]: input_2 = input[:,:,2]

In [8]: print(sess.run(input_2))
[[ 3 6 9]
 [12 15 18]]

In [9]: input_2 = input[:,:,0:2]

In [10]: print(sess.run(input_2))
[[[ 1 2]
 [ 4 5]
 [ 7 8]]

 [[10 11]
 [13 14]
 [16 17]]]

In [11]: input = tf.constant([[[[1,2,3],[4,5,6],[7,8,9]],[[10,11,12],[13,14,15],
 ...: [16,17,18]]]])

In [12]: input.get_shape()
Out[12]: TensorShape([Dimension(1), Dimension(2), Dimension(3), Dimension(3)])

In [13]: input_2 = input[:,:,2]

In [14]: print(sess.run(input_2))
[[[ 7 8 9]
 [16 17 18]]]

In [15]: input_2 = input[:,:,:,2]

In [16]: print(sess.run(input_2))
[[[ 3 6 9]
 [12 15 18]]]

补充知识:TensorFlow 训练过程中获取某个Tensor值;只有conv1和bn1存在NAN

1. 在训练过程中,获取某个参数Tensor的值:

获取所有Tensor的name:

[tensor.name for tensor in tf.get_default_graph().as_graph_def().node]

根据name获得Tensor:

bn_gamma = sess.graph.get_tensor_by_name('bn1_audio/batch_normalization/beta:0')

sess.run(), print

2. 只有conv1的filter, bias和bn1的gamma为nan:

由于训练数据中存在nan.

bn1后的max pooling层输出全为0 (∵bn1输出有0), 导致后续参数和输出看起来正常, 但是不会更新.

以上这篇Tensorflow--取tensorf指定列的操作方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持python博客。

<< 上一篇 下一篇 >>

搜索

推荐资源

  Powered By python教程网   鲁ICP备18013710号
python博客 - 小白学python最友好的网站!