Tensorflow.js: tf.pad results in TypeError: t.map is not a function

谁说我不能喝 提交于 2020-01-05 04:09:07

问题


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]])

When I execute it:

tf.pad(t, padding, "CONSTANT")

I get:

TypeError: t.map is not a function

I'm using the latest version of tfjs.


回答1:


padding is a normal js array of tuples ( array of arrray) and not a tensor.

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]]


来源:https://stackoverflow.com/questions/59244722/tensorflow-js-tf-pad-results-in-typeerror-t-map-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!