本文整理匯總了TypeScript中@tensorflow/tfjs-core.conv2d函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript conv2d函數的具體用法?TypeScript conv2d怎麽用?TypeScript conv2d使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了conv2d函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
return tf.tidy(() => {
let out = tf.conv2d(x, params.filters, strides, 'same')
out = tf.add(out, params.batch_norm_offset)
return tf.clipByValue(out, 0, 6)
})
示例2:
return tf.tidy(() => {
const out = tf.add(
tf.conv2d(x, params.filters, [1, 1], padding),
params.bias
) as tf.Tensor4D
return withRelu ? tf.relu(out) : out
})
示例3: convLayer
function convLayer(
x: tf.Tensor4D,
params: ConvLayerParams,
strides: [number, number],
withRelu: boolean,
padding: 'valid' | 'same' = 'same'
): tf.Tensor4D {
const { filters, bias } = params.conv
let out = tf.conv2d(x, filters, strides, padding)
out = tf.add(out, bias)
out = scale(out, params.scale)
return withRelu ? tf.relu(out) : out
}
示例4: switch
(node: Node, tensorMap: NamedTensorsMap,
context: ExecutionContext): tfc.Tensor[] => {
switch (node.op) {
case 'conv1d': {
const stride =
getParamValue('stride', node, tensorMap, context) as number;
const pad = getParamValue('pad', node, tensorMap, context);
const dataFormat =
(getParamValue('dataFormat', node, tensorMap, context) as string)
.toUpperCase();
const dilation =
getParamValue('dilation', node, tensorMap, context) as number;
return [tfc.conv1d(
getParamValue('x', node, tensorMap, context) as tfc.Tensor3D,
getParamValue('filter', node, tensorMap, context) as tfc.Tensor3D,
stride, pad as 'valid' | 'same', dataFormat as 'NWC' | 'NCW',
dilation)];
}
case 'conv2d': {
const stride =
getParamValue('strides', node, tensorMap, context) as number[];
const pad = getParamValue('pad', node, tensorMap, context);
const dataFormat =
(getParamValue('dataFormat', node, tensorMap, context) as string)
.toUpperCase();
const dilations =
getParamValue('dilations', node, tensorMap, context) as number[];
return [tfc.conv2d(
getParamValue('x', node, tensorMap, context) as tfc.Tensor3D |
tfc.Tensor4D,
getParamValue('filter', node, tensorMap, context) as tfc.Tensor4D,
[stride[1], stride[2]], pad as 'valid' | 'same',
dataFormat as 'NHWC' | 'NCHW', [dilations[0], dilations[1]])];
}
case 'conv2dTranspose': {
const shape = getParamValue(
'outputShape', node, tensorMap,
context) as [number, number, number] |
[number, number, number, number];
const stride =
getParamValue('strides', node, tensorMap, context) as number[];
const pad = getParamValue('pad', node, tensorMap, context);
return [tfc.conv2dTranspose(
getParamValue('x', node, tensorMap, context) as tfc.Tensor3D |
tfc.Tensor4D,
getParamValue('filter', node, tensorMap, context) as tfc.Tensor4D,
shape, [stride[1], stride[2]], pad as 'valid' | 'same')];
}
case 'depthwiseConv2d': {
const stride =
getParamValue('strides', node, tensorMap, context) as number[];
const pad = getParamValue('pad', node, tensorMap, context);
const dilations =
getParamValue('dilations', node, tensorMap, context) as number[];
const dataFormat =
(getParamValue('dataFormat', node, tensorMap, context) as string)
.toUpperCase();
return [tfc.depthwiseConv2d(
getParamValue('input', node, tensorMap, context) as tfc.Tensor3D |
tfc.Tensor4D,
getParamValue('filter', node, tensorMap, context) as tfc.Tensor4D,
[stride[1], stride[2]], pad as 'valid' | 'same',
dataFormat as 'NHWC' | 'NCHW', [dilations[0], dilations[1]])];
}
case 'avgPool': {
const stride =
getParamValue('strides', node, tensorMap, context) as number[];
const pad = getParamValue('pad', node, tensorMap, context);
const kernelSize =
getParamValue('kernelSize', node, tensorMap, context) as number[];
return [tfc.avgPool(
getParamValue('x', node, tensorMap, context) as tfc.Tensor3D |
tfc.Tensor4D,
[kernelSize[1], kernelSize[2]], [stride[1], stride[2]],
pad as 'valid' | 'same')];
}
case 'maxPool': {
const stride =
getParamValue('strides', node, tensorMap, context) as number[];
const pad = getParamValue('pad', node, tensorMap, context);
const kernelSize =
getParamValue('kernelSize', node, tensorMap, context) as number[];
return [tfc.maxPool(
getParamValue('x', node, tensorMap, context) as tfc.Tensor3D |
tfc.Tensor4D,
[kernelSize[1], kernelSize[2]], [stride[1], stride[2]],
pad as 'valid' | 'same')];
}
default:
throw TypeError(`Node type ${node.op} is not implemented`);
}
};