TensorFlow.js有状态的SimpleRNN Tensor被处置

我正在尝试创建一个有状态的RNN模型。我可以一次致电预测,然后其他致电给我一个错误:Uncaught Error: Tensor is disposed.

predict error

我的模型声明如下:

function createModel() {
  const inputGame = tf.input({
    batchShape: [1,1,OUTPUT_SHAPE],name: 'inputGame',});
  const inputPlayer = tf.input({
    batchShape: [1,INPUT_PLAYER],name: 'inputPlayer',});
  const input = tf.layers
    .concatenate({name: 'concatenate'})
    .apply([inputGame,inputPlayer]);
  const rnn = tf.layers.simpleRNN({
    units: 128,activation: 'relu',stateful: true,kernelInitializer: 'glorotNormal',biasInitializer: 'glorotNormal',name: 'rnn',});
  const dense = tf.layers.dense({
    units: OUTPUT_SHAPE,activation: 'sigmoid',name: 'dense',});
  const output = dense.apply(rnn.apply(input));
  const model = tf.model({inputs: [inputGame,inputPlayer],outputs: [output]});
  const surface = {name: 'Model Summary',tab: 'Model Inspection'};
  tfvis.show.modelSummary(surface,model);
  return model;
}

然后我称之为每秒预测:

const inputGameTensor = tf.tensor(frame);
const inputPlayerTensor = tf.zeros([1,INPUT_PLAYER]);
const output = model.predict([inputGameTensor,inputPlayerTensor],true);

我怀疑在state层中有一个SimpleRNN张量,并且在调用一次预测后为disposed()。我对TensorFlow.js不够了解,无法研究这个假设。

我的代码在以下位置运行: https://luxedo.github.io/TGNN/

dasnan 回答:TensorFlow.js有状态的SimpleRNN Tensor被处置

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3105769.html

大家都在问