本文整理汇总了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)
})
开发者ID:BakirDiyar,项目名称:face-api.js,代码行数:7,代码来源:pointwiseConvLayer.ts
示例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
})
开发者ID:BakirDiyar,项目名称:face-api.js,代码行数:8,代码来源:convLayer.ts
示例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
}
开发者ID:BakirDiyar,项目名称:face-api.js,代码行数:14,代码来源:convLayer.ts
示例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`);
}
};
开发者ID:oveddan,项目名称:tfjs-converter,代码行数:97,代码来源:convolution_executor.ts
注:本文中的@tensorflow/tfjs-core.conv2d函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论