小编DiI*_*Ili的帖子

InvalidArgumentError:ConcatOp:输入的尺寸应匹配

使用dynamic_rnn时的Tensorflow 1.7最初运行良好,但在第32步(运行代码时发生变化),出现错误。当我使用较小的批处理时,似乎代码可以运行更长的时间,但是错误仍然弹出。只是无法找出问题所在。

    from mapping import *


def my_input_fn(features, targets, batch_size=20, shuffle=True, num_epochs=None, sequece_lenth=None):
    ds = tf.data.Dataset.from_tensor_slices(
        (features, targets, sequece_lenth))  # warning: 2GB limit
    ds = ds.batch(batch_size).repeat(num_epochs)

    if shuffle:
        ds = ds.shuffle(10000)
    features, labels, sequence = ds.make_one_shot_iterator().get_next()
    return features, labels, sequence


def lstm_cell(lstm_size=50):
    return tf.contrib.rnn.BasicLSTMCell(lstm_size)


class RnnModel:
    def __init__(self,
                 batch_size,
                 hidden_units,
                 time_steps,
                 num_features
                 ):
        self.batch_size = batch_size
        self.hidden_units = hidden_units
        stacked_lstm = tf.contrib.rnn.MultiRNNCell(
            [lstm_cell(i) for i in self.hidden_units])
        self.initial_state = stacked_lstm.zero_state(batch_size, tf.float32)
        self.model = stacked_lstm
        self.state = self.initial_state
        self.time_steps = time_steps …
Run Code Online (Sandbox Code Playgroud)

tensorflow rnn

4
推荐指数
1
解决办法
4342
查看次数

ValueError:操作u'tpu_140462710602256 / VarIsInitializedOp'已标记为不可提取

该代码在GPU和CPU上正常工作,但是当我使用keras_to_tpu_model函数使模型能够在TPU上运行时,发生了错误。

这是colab的完整输出:https :
//colab.research.google.com/gist/WangHexie/2252beb26f16354cb6e9ba2639970e5b/tpu-error.ipynb将运行类型更改为TPU,我认为这可以复制。

github上的代码:https : //github.com/WangHexie/DHNE/blob/master/src/hypergraph_embedding.py#L60

您可以通过更改为gpu分支在GPU上测试代码。

追溯

    Traceback (most recent call last):
  File "src/hypergraph_embedding.py", line 158, in <module>
    h.train(dataset)
  File "src/hypergraph_embedding.py", line 75, in train
    epochs=self.options.epochs_to_train, verbose=1)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/keras/engine/training.py", line 2177, in fit_generator
    initial_epoch=initial_epoch)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/keras/engine/training_generator.py", line 176, in fit_generator
    x, y, sample_weight=sample_weight, class_weight=class_weight)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/keras/engine/training.py", line 1940, in train_on_batch
    outputs = self.train_function(ins)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/tpu/python/tpu/keras_support.py", line 1238, in __call__
    infeed_manager)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/tpu/python/tpu/keras_support.py", line 1143, in _tpu_model_ops_for_input_specs
    infeed_manager)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/tpu/python/tpu/keras_support.py", line 1053, in _specialize_model
    _model_fn, inputs=[[]] * …
Run Code Online (Sandbox Code Playgroud)

keras tensorflow google-colaboratory google-cloud-tpu

3
推荐指数
1
解决办法
1913
查看次数