tfjs:错误:传递到堆栈的参数张量必须是`Tensor []`或`TensorLike []`

时间:2020-10-08 21:23:00

标签: javascript tensorflow

完全相同的问题已经发布了几次,但不幸的是没有找到答案。我想做的是构建一对一的RNN,其中上一个时间步的输出是使用层API的当前时间步的输入。这是我的示例代码,试图使其尽可能简单:

const cells = [
  tf.layers.simpleRNNCell({units: 4, activation: 'relu'}),
  tf.layers.simpleRNNCell({units: 3, activation: 'relu'}),
];
const rnn = tf.layers.rnn({cell: cells, returnSequences: true});


const x = tf.tensor([
 [
   [10, 8, 5],
 ],
 [
   [0, 2, 0],
 ],
]);

const y = tf.tensor([
  [
    [0.3, 0.5, 0.4],
  ],
  [
    [0.1, 0, 0]
  ]
])

const model = tf.sequential();

model.add(tf.layers.inputLayer({ inputShape: [1, 3] }))
for (let i = 0; i < 10; i++) {
 model.add(rnn)
};

model.compile({
 loss: 'categoricalCrossentropy',
 optimizer: 'adam',
 metrics: ['accuracy']
});

model.fit(x, y, {
 epochs: 10,
 batchSize: x.shape[0],
 yieldEvery: 'batch'
});
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>

您也可以尝试,它会引发错误(在浏览器中,它引发:Error: 'slice' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen,在节点中,它引发问题标题中的内容。)

我在做什么错了?

0 个答案:

没有答案