本文整理匯總了TypeScript中@tensorflow/tfjs-core.image類的典型用法代碼示例。如果您正苦於以下問題:TypeScript image類的具體用法?TypeScript image怎麽用?TypeScript image使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了image類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: switch
export let executeOp: OpExecutor = (node: Node, tensorMap: NamedTensorsMap,
context: ExecutionContext):
tfc.Tensor[] => {
switch (node.op) {
case 'resizeBilinear': {
const images =
getParamValue('images', node, tensorMap, context) as tfc.Tensor;
const size = getParamValue('size', node, tensorMap, context) as number[];
const alignCorners =
getParamValue('alignCorners', node, tensorMap, context) as boolean;
return [tfc.image.resizeBilinear(
images as tfc.Tensor3D | tfc.Tensor4D, [size[0], size[1]],
alignCorners)];
}
case 'resizeNearestNeighbor': {
const images =
getParamValue('images', node, tensorMap, context) as tfc.Tensor;
const size = getParamValue('size', node, tensorMap, context) as number[];
const alignCorners =
getParamValue('alignCorners', node, tensorMap, context) as boolean;
return [tfc.image.resizeNearestNeighbor(
images as tfc.Tensor3D | tfc.Tensor4D, [size[0], size[1]],
alignCorners)];
}
default:
throw TypeError(`Node type ${node.op} is not implemented`);
}
};
示例2: async
export let executeOp: OpExecutor = async(
node: Node, tensorMap: NamedTensorsMap,
context: ExecutionContext): Promise<tfc.Tensor[]> => {
switch (node.op) {
case 'nonMaxSuppression': {
const boxes =
getParamValue('boxes', node, tensorMap, context) as tfc.Tensor;
const scores =
getParamValue('scores', node, tensorMap, context) as tfc.Tensor;
const maxOutputSize =
getParamValue('maxOutputSize', node, tensorMap, context) as number;
const iouThreshold =
getParamValue('iouThreshold', node, tensorMap, context) as number;
const scoreThreshold =
getParamValue('scoreThreshold', node, tensorMap, context) as number;
return [await tfc.image.nonMaxSuppressionAsync(
boxes as tfc.Tensor2D, scores as tfc.Tensor1D, maxOutputSize,
iouThreshold, scoreThreshold)];
}
case 'whereAsync': {
return [await tfc.whereAsync(
getParamValue('condition', node, tensorMap, context) as tfc.Tensor)];
}
default:
throw TypeError(`Node type ${node.op} is not implemented`);
}
};
示例3: getImageTensor
const outTensor = tf.tidy(() => {
const params = this._params
let imgTensor = getImageTensor(netInput)
const [height, width] = imgTensor.shape.slice(1)
imageDimensions = { width, height }
// work with 128 x 128 sized face images
if (imgTensor.shape[1] !== 128 || imgTensor.shape[2] !== 128) {
imgTensor = tf.image.resizeBilinear(imgTensor, [128, 128])
}
let out = conv(imgTensor, params.conv0_params)
out = maxPool(out)
out = conv(out, params.conv1_params)
out = conv(out, params.conv2_params)
out = maxPool(out)
out = conv(out, params.conv3_params)
out = conv(out, params.conv4_params)
out = maxPool(out)
out = conv(out, params.conv5_params)
out = conv(out, params.conv6_params)
out = maxPool(out, [1, 1])
out = conv(out, params.conv7_params)
const fc0 = tf.relu(fullyConnectedLayer(out.as2D(out.shape[0], -1), params.fc0_params))
const fc1 = fullyConnectedLayer(fc0, params.fc1_params)
return fc1
})
示例4: padToSquare
return tf.tidy(() => {
let x = padToSquare(getImageTensor(netInput), true)
// work with 150 x 150 sized face images
if (x.shape[1] !== 150 || x.shape[2] !== 150) {
x = tf.image.resizeBilinear(x, [150, 150])
}
x = normalize(x)
let out = convDown(x, this._params.conv32_down)
out = tf.maxPool(out, 3, 2, 'valid')
out = residual(out, this._params.conv32_1)
out = residual(out, this._params.conv32_2)
out = residual(out, this._params.conv32_3)
out = residualDown(out, this._params.conv64_down)
out = residual(out, this._params.conv64_1)
out = residual(out, this._params.conv64_2)
out = residual(out, this._params.conv64_3)
out = residualDown(out, this._params.conv128_down)
out = residual(out, this._params.conv128_1)
out = residual(out, this._params.conv128_2)
out = residualDown(out, this._params.conv256_down)
out = residual(out, this._params.conv256_1)
out = residual(out, this._params.conv256_2)
out = residualDown(out, this._params.conv256_down_out)
const globalAvg = out.mean([1, 2]) as tf.Tensor2D
const fullyConnected = tf.matMul(globalAvg, this._params.fc)
return fullyConnected
})
示例5:
return tf.tidy(() => {
const resized = tf.image.resizeBilinear(x, resizedImageSize, false)
return tf.sub(tf.mul(resized, weight), bias)
})