问题
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