标签: tensorflow

如何在TensorFlow中应用渐变剪裁?

考虑示例代码.

我想知道如何在可能爆炸梯度的RNN上对此网络应用渐变剪辑.

tf.clip_by_value(t, clip_value_min, clip_value_max, name=None)
Run Code Online (Sandbox Code Playgroud)

这是一个可以使用的示例,但我在哪里介绍这个?在defN的RNN

    lstm_cell = rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0)
    # Split data because rnn cell needs a list of inputs for the RNN inner loop
    _X = tf.split(0, n_steps, _X) # n_steps
tf.clip_by_value(_X, -1, 1, name=None)
Run Code Online (Sandbox Code Playgroud)

但是这没有意义,因为张量_X是输入而不是渐变的被剪裁的东西?

我是否必须为此定义自己的优化器,还是有更简单的选项?

python machine-learning deep-learning lstm tensorflow

90
推荐指数
6
解决办法
6万
查看次数

在TensorFlow中使用预先训练的单词嵌入(word2vec或Glove)

我最近回顾了一个卷积文本分类的有趣实现.但是,我所评论的所有TensorFlow代码都使用随机(未预先训练)的嵌入向量,如下所示:

with tf.device('/cpu:0'), tf.name_scope("embedding"):
    W = tf.Variable(
        tf.random_uniform([vocab_size, embedding_size], -1.0, 1.0),
        name="W")
    self.embedded_chars = tf.nn.embedding_lookup(W, self.input_x)
    self.embedded_chars_expanded = tf.expand_dims(self.embedded_chars, -1)
Run Code Online (Sandbox Code Playgroud)

有谁知道如何使用Word2vec的结果或GloVe预训练的单词嵌入而不是随机的?

python numpy deep-learning tensorflow

89
推荐指数
5
解决办法
5万
查看次数

具有Tensorflow后端的Keras可以随意使用CPU或GPU吗?

我在Keras上安装了Tensorflow后端和CUDA.我想有时需要强迫Keras使用CPU.这可以在没有在虚拟环境中安装单独的CPU Tensorflow的情况下完成吗?如果是这样的话?如果后端是Theano,可以设置标志,但我还没有听说过可通过Keras访问的Tensorflow标志.

python machine-learning keras tensorflow

88
推荐指数
5
解决办法
10万
查看次数

订购批量标准化和退出?

最初的问题是关于TensorFlow实现的具体问题.但是,答案仅适用于实施.这个一般答案也是TensorFlow的正确答案.

在TensorFlow中使用批量标准化和dropout(特别是使用contrib.layers)时,我是否需要担心排序?

似乎有可能如果我使用dropout然后立即批量标准化可能会有麻烦.例如,如果批量标准化的偏移训练到训练输出的较大比例数,但是然后将相同的偏移应用于较小的(由于具有更多输出的补偿)标度数而在测试期间没有丢失,那么转移可能会关闭.TensorFlow批量标准化层是否会自动对此进行补偿?或者这不是因为某些原因我不在乎?

此外,在将这两者结合使用时还有其他需要注意的问题吗?例如,假设我使用他们以正确的顺序在问候上述(假设有一个正确的顺序),可以存在与使用分批正常化和漏失在多个连续层烦恼?我没有立即看到问题,但我可能会遗漏一些东西.

非常感谢!

更新:

实验测试似乎表明排序确实很重要.我运行了相同的网络两次,只有批量规范和退出反向.当辍学率在批量规范之前时,随着训练损失的减少,验证损失似乎在增加.在另一种情况下,他们都会倒下.但就我而言,动作很慢,所以在经过多次训练后情况可能会发生变化,这只是一次测试.一个更明确和知情的答案仍然会受到赞赏.

python neural-network conv-neural-network tensorflow

87
推荐指数
6
解决办法
5万
查看次数

如何在远程服务器上运行Tensorboard?

我是Tensorflow的新手,可以从我正在做的一些可视化中获益.我知道Tensorboard是一个有用的可视化工具,但我如何在远程Ubuntu机器上运行它?

data-visualization machine-learning remote-access tensorflow tensorboard

85
推荐指数
10
解决办法
7万
查看次数

哪个TensorFlow和CUDA版本组合兼容?

我注意到一些较新的TensorFlow版本与较旧的CUDA和cuDNN版本不兼容.是否存在兼容版本的概述,甚至是官方测试组合的列表?我在TensorFlow文档中找不到它.

compatibility cuda version tensorflow cudnn

85
推荐指数
4
解决办法
13万
查看次数

global_step在Tensorflow中意味着什么?

这是来自TensorFlow网站的教程代码,

  1. 有谁能帮忙解释一下是什么global_step意思?

    我在Tensorflow网站上发现,使用全局步骤计算训练步骤,但我并不完全明白这意味着什么.

  2. 此外,数字0在设置时意味着什么global_step

    def training(loss,learning_rate):
        tf.summary.scalar('loss',loss)
        optimizer = tf.train.GradientDescentOptimizer(learning_rate)

        # Why 0 as the first parameter of the global_step tf.Variable?
        global_step = tf.Variable(0, name='global_step',trainable=False)

        train_op = optimizer.minimize(loss, global_step=global_step)

        return train_op
Run Code Online (Sandbox Code Playgroud)

根据Tensorflow doc global_step:在变量更新后增加1.这意味着一次更新后global_step变为1吗?

deep-learning tensorflow

84
推荐指数
2
解决办法
4万
查看次数

如何在TensorFlow上进行Xavier初始化

我正在将我的Caffe网络移植到TensorFlow,但它似乎没有xavier初始化.我正在使用,truncated_normal但这似乎使得训练更加困难.

python tensorflow

80
推荐指数
6
解决办法
8万
查看次数

如何*实际*读取TensorFlow中的CSV数据?

我对TensorFlow的世界相对较新,并且非常困惑于你如何将CSV数据实际读入TensorFlow中的可用示例/标签张量.TensorFlow教程中有关读取CSV数据的示例相当分散,只能让您了解能够训练CSV数据的方法.

这是我根据CSV教程编写的代码:

from __future__ import print_function
import tensorflow as tf

def file_len(fname):
    with open(fname) as f:
        for i, l in enumerate(f):
            pass
    return i + 1

filename = "csv_test_data.csv"

# setup text reader
file_length = file_len(filename)
filename_queue = tf.train.string_input_producer([filename])
reader = tf.TextLineReader(skip_header_lines=1)
_, csv_row = reader.read(filename_queue)

# setup CSV decoding
record_defaults = [[0],[0],[0],[0],[0]]
col1,col2,col3,col4,col5 = tf.decode_csv(csv_row, record_defaults=record_defaults)

# turn features back into a tensor
features = tf.stack([col1,col2,col3,col4])

print("loading, " + str(file_length) + " line(s)\n")
with tf.Session() …
Run Code Online (Sandbox Code Playgroud)

python csv tensorflow

80
推荐指数
2
解决办法
4万
查看次数

Numpy和Tensorflow中np.mean和tf.reduce_mean的区别?

MNIST初学者教程中,有tf.cast

tf.reduce_mean基本上改变了对象的张量类型,但是np.meantf.reduce_mean?之间有什么区别?

这是关于以下内容的文档reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None):

accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
Run Code Online (Sandbox Code Playgroud)

对于一维矢量,它看起来像input_tensor但我不明白发生了什么reduction_indices.None有道理,因为[1,2]和[1,2]的平均值是[1.5,1.5],但是发生了什么np.mean == tf.reduce_mean

python numpy machine-learning mean tensorflow

79
推荐指数
3
解决办法
5万
查看次数