4

いくつかの時系列データで GRU セルを実行して、最後の層の活性化に従ってそれらをクラスター化したいと考えています。GRU セルの実装に 1 つの小さな変更を加えました

def __call__(self, inputs, state, scope=None):
"""Gated recurrent unit (GRU) with nunits cells."""
with vs.variable_scope(scope or type(self).__name__):  # "GRUCell"
  with vs.variable_scope("Gates"):  # Reset gate and update gate.
    # We start with bias of 1.0 to not reset and not update.
    r, u = array_ops.split(1, 2, linear([inputs, state], 2 * self._num_units, True, 1.0))
    r, u = sigmoid(r), sigmoid(u)
  with vs.variable_scope("Candidate"):
    c = tanh(linear([inputs, r * state], self._num_units, True))
  new_h = u * state + (1 - u) * c

  # store the activations, everything else is the same
  self.activations = [r,u,c]
return new_h, new_h

この後、この GRU セルを呼び出すスクリプトでアクティベーションを返す前に、次の方法でアクティベーションを連結します。

@property
def activations(self):
    return self._activations


@activations.setter
def activations(self, activations_array):
    print "PRINT THIS"         
    concactivations = tf.concat(concat_dim=0, values=activations_array, name='concat_activations')
    self._activations = tf.reshape(tensor=concactivations, shape=[-1], name='flatten_activations')

次の方法で GRU セルを呼び出します

outputs, state = rnn.rnn(cell=cell, inputs=x, initial_state=initial_state, sequence_length=s)

入力バッチsの各要素のタイムスタンプの数を含むバッチ長の配列です。

そして最後に、使用してフェッチします

fetched = sess.run(fetches=cell.activations, feed_dict=feed_dict)

実行すると、次のエラーが表示されます

トレースバック (最新の呼び出しが最後): ファイル "xxx.py"、162 行目、取得済み = sess.run(fetches=cell.activations, feed_dict=feed_dict) ファイル "/xxx/local/lib/python2.7/site- packages/tensorflow/python/client/session.py"、315 行目、実行中 return self._run(None, fetches, feed_dict) ファイル "/xxx/local/lib/python2.7/site-packages/tensorflow/python/ client/session.py"、511 行目、_run feed_dict_string) ファイル "/xxx/local/lib/python2.7/site-packages/tensorflow/python/client/session.py"、564 行目、_do_run target_list) ファイル"/xxx/local/lib/python2.7/site-packages/tensorflow/python/client/session.py"、588 行目、_do_call six.reraise(e_type, e_value, e_traceback) ファイル "/xxx/local/lib /python2.7/site-packages/tensorflow/python/client/session.py」、571行目、in _do_call return fn(*args) ファイル "/xxx/local/lib/python2.7/site-packages/tensorflow/python/client/session.py"、555 行目、_run_fn

return tf_session.TF_Run(session, feed_dict, fetch_list, target_list) tensorflow.python.pywrap_tensorflow.StatusNotOK: 無効な引数: RNN/cond_396/ClusterableGRUCell/flatten_activations:0 に対して返されたテンソルが無効でした。

可変長シーケンスを渡して、最後のステップで GRU セルからアクティベーションをフェッチする方法について、誰かが洞察を与えることができますか? ありがとう。

4

1 に答える 1

0

最後のステップからアクティベーションを取得するには、アクティベーションを tf.rnn によって返される状態の一部にします。

于 2016-09-06T20:30:34.790 に答える