本文整理匯總了TypeScript中@tensorflow/tfjs-core.sub函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript sub函數的具體用法?TypeScript sub怎麽用?TypeScript sub使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了sub函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
return tf.tidy(() => {
const avg_r = tf.fill([1, 150, 150, 1], 122.782);
const avg_g = tf.fill([1, 150, 150, 1], 117.001);
const avg_b = tf.fill([1, 150, 150, 1], 104.298);
const avg_rgb = tf.concat([avg_r, avg_g, avg_b], 3)
return tf.div(tf.sub(x, avg_rgb), tf.scalar(256))
})
示例2: getCenterCoordinatesAndSizesLayer
function getCenterCoordinatesAndSizesLayer(x: tf.Tensor2D) {
const vec = tf.unstack(tf.transpose(x, [1, 0]))
const sizes = [
tf.sub(vec[2], vec[0]),
tf.sub(vec[3], vec[1])
]
const centers = [
tf.add(vec[0], tf.div(sizes[0], tf.scalar(2))),
tf.add(vec[1], tf.div(sizes[1], tf.scalar(2)))
]
return {
sizes,
centers
}
}
示例3: dLoss
// Define losses.
dLoss(truePred: tf.Tensor1D, generatedPred: tf.Tensor1D) {
if (this.lossType === 'LeastSq loss') {
return tf.add(
truePred.sub(tf.scalar(1)).square().mean(),
generatedPred.square().mean()
) as tf.Scalar;
} else {
return tf.add(
truePred.log().mul(tf.scalar(0.95)).mean(),
tf.sub(tf.scalar(1), generatedPred).log().mean()
).mul(tf.scalar(-1)) as tf.Scalar;
}
}
示例4: decodeBoxesLayer
function decodeBoxesLayer(x0: tf.Tensor2D, x1: tf.Tensor2D) {
const {
sizes,
centers
} = getCenterCoordinatesAndSizesLayer(x0)
const vec = tf.unstack(tf.transpose(x1, [1, 0]))
const div0_out = tf.div(tf.mul(tf.exp(tf.div(vec[2], tf.scalar(5))), sizes[0]), tf.scalar(2))
const add0_out = tf.add(tf.mul(tf.div(vec[0], tf.scalar(10)), sizes[0]), centers[0])
const div1_out = tf.div(tf.mul(tf.exp(tf.div(vec[3], tf.scalar(5))), sizes[1]), tf.scalar(2))
const add1_out = tf.add(tf.mul(tf.div(vec[1], tf.scalar(10)), sizes[1]), centers[1])
return tf.transpose(
tf.stack([
tf.sub(add0_out, div0_out),
tf.sub(add1_out, div1_out),
tf.add(add0_out, div0_out),
tf.add(add1_out, div1_out)
]),
[1, 0]
)
}
示例5:
return tf.tidy(() => {
const resized = tf.image.resizeBilinear(x, resizedImageSize, false)
return tf.sub(tf.mul(resized, weight), bias)
})