本文整理汇总了TypeScript中deeplearn.NDArrayMath.dispose方法的典型用法代码示例。如果您正苦于以下问题:TypeScript NDArrayMath.dispose方法的具体用法?TypeScript NDArrayMath.dispose怎么用?TypeScript NDArrayMath.dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类deeplearn.NDArrayMath
的用法示例。
在下文中一共展示了NDArrayMath.dispose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: run
run(size: number, option: string,
params: PoolBenchmarkParams): Promise<number> {
const safeMode = false;
const math = new dl.NDArrayMath('cpu', safeMode);
dl.ENV.setMath(math);
const outputDepth = params.depth;
const xShape: [number, number, number] = [size, size, outputDepth];
const fieldSize = params.fieldSize;
const stride = params.stride;
const zeroPad = dl.conv_util.computeDefaultPad(xShape, fieldSize, stride);
const op = getPoolingOp(option, math);
const x: dl.Tensor3D = dl.randomUniform(xShape, -1, 1);
const start = performance.now();
for (let i = 0; i < CPU_OP_RUNS; i++) {
op(x, fieldSize, stride, zeroPad);
}
const avgTime = (performance.now() - start) / CPU_OP_RUNS;
math.dispose();
return new Promise<number>((resolve, reject) => {
resolve(avgTime);
});
}
示例2: run
async run(size: number, opType: string, params: ConvParams): Promise<number> {
const safeMode = false;
const math = new dl.NDArrayMath('webgl', safeMode);
dl.ENV.setMath(math);
const inDepth = params.inDepth;
const inShape: [number, number, number] = [size, size, inDepth];
const filterSize = params.filterSize;
const stride = params.stride;
const pad = params.pad;
let x: dl.Tensor3D = dl.randomUniform(inShape, -1, 1);
let W: dl.Tensor4D;
let b: dl.Tensor1D;
let benchmark: () => dl.Tensor;
if (opType === 'regular') {
const regParams = params as RegularConvParams;
const wShape = dl.conv_util.computeWeightsShape4D(
inDepth, regParams.outDepth, filterSize, filterSize);
W = dl.randomUniform(wShape, -1, 1);
b = dl.randomUniform([regParams.outDepth], -1, 1);
benchmark = () => x.conv2d(W, b, stride, pad);
} else if (opType === 'transposed') {
const regParams = params as RegularConvParams;
const wShape = dl.conv_util.computeWeightsShape4D(
inDepth, regParams.outDepth, filterSize, filterSize);
W = dl.randomUniform(wShape, -1, 1);
x = dl.randomUniform([size, size, regParams.outDepth], -1, 1);
benchmark = () =>
x.conv2dTranspose(W, [size, size, inDepth], stride, pad);
} else if (opType === 'depthwise') {
const depthwiseParams = params as DepthwiseConvParams;
const wShape = dl.conv_util.computeWeightsShape4D(
inDepth, depthwiseParams.channelMul, filterSize, filterSize);
W = dl.randomUniform(wShape, -1, 1);
benchmark = () => x.depthwiseConv2D(W, stride, pad);
} else {
throw new Error(`Unknown option ${opType}`);
}
const time = await benchmark_util.warmupAndBenchmarkGPU(benchmark);
x.dispose();
W.dispose();
math.dispose();
if (b != null) {
b.dispose();
}
return time;
}
示例3: run
async run(size: number, option: string) {
const safeMode = false;
const math = new dl.NDArrayMath('webgl', safeMode);
dl.ENV.setMath(math);
const input: dl.Tensor2D = dl.randomUniform([size, size], -1, 1);
const op = getReductionOp(option);
const benchmark = () => op(input);
const time = await benchmark_util.warmupAndBenchmarkGPU(benchmark);
input.dispose();
math.dispose();
return time;
}
示例4: run
async run(size: number): Promise<number> {
const safeMode = false;
const math = new dl.NDArrayMath('webgl', safeMode);
dl.ENV.setMath(math);
const a: dl.Tensor2D = dl.randomNormal([size, size]);
const b: dl.Tensor2D = dl.randomNormal([size, size]);
const benchmark = () => math.matMul(a, b);
const time = await benchmark_util.warmupAndBenchmarkGPU(benchmark);
a.dispose();
b.dispose();
math.dispose();
return time;
}
示例5: run
async run(size: number) {
const safeMode = false;
const math = new dl.NDArrayMath('webgl', safeMode);
dl.ENV.setMath(math);
const x: dl.Tensor3D = dl.randomUniform([size, size, 8], -1, 1);
const mean = dl.tensor1d([0]);
const variance = dl.tensor1d([1]);
const varianceEpsilon = .001;
const benchmark = () =>
x.batchNormalization(mean, variance, varianceEpsilon);
const time = await benchmark_util.warmupAndBenchmarkGPU(benchmark);
x.dispose();
mean.dispose();
variance.dispose();
math.dispose();
return time;
}