Tensorflow.js:tf.pad 导致 TypeError:t.map 不是函数 [英] Tensorflow.js: tf.pad results in TypeError: t.map is not a function
本文介绍了Tensorflow.js:tf.pad 导致 TypeError:t.map 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码来自 TF API 文档:
This code is from the TF API docs:
let t = tf.tensor([[1, 2, 3], [4, 5, 6]])
let padding = tf.tensor([[1, 1,], [2, 2]])
当我执行它时:
tf.pad(t, padding, "CONSTANT")
我明白了:
类型错误:t.map 不是函数
TypeError: t.map is not a function
我使用的是最新版本的 tfjs.
I'm using the latest version of tfjs.
推荐答案
padding 是一个普通的 js 元组数组(array of arrray)而不是张量.
padding is a normal js array of tuples ( array of arrray) and not a tensor.
至于现在1.3.1版本,只支持CONSTANT模式.方法如下:
As for now, the version 1.3.1, only the CONSTANT mode is supported. Here is the way to go:
let t = tf.tensor([[1, 2, 3], [4, 5, 6]])
let padding = [[2, 2,], [1, 1]]
tf.pad(t, padding).print()
// [[0, 0, 0, 0, 0],
// [0, 0, 0, 0, 0],
// [0, 1, 2, 3, 0],
// [0, 4, 5, 6, 0],
// [0, 0, 0, 0, 0],
// [0, 0, 0, 0, 0]]
这篇关于Tensorflow.js:tf.pad 导致 TypeError:t.map 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文