当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript deeplearn.setBackend函数代码示例

本文整理汇总了TypeScript中deeplearn.setBackend函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setBackend函数的具体用法?TypeScript setBackend怎么用?TypeScript setBackend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setBackend函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: run

  async run(size: number, option: string) {
    dl.setBackend('webgl');

    const input: dl.Tensor2D = dl.randomUniform([size, size], -1, 1);
    const op = getUnaryOp(option);

    const benchmark = () => op(input);

    const time = await benchmark_util.warmupAndBenchmarkGPU(benchmark);

    input.dispose();
    return time;
  }
开发者ID:kodamatomohiro,项目名称:tfjs-core,代码行数:13,代码来源:unary_ops_benchmark.ts

示例2: run

  async run(size: number, option: string): Promise<number> {
    dl.setBackend('cpu');

    const input: dl.Tensor2D = dl.randomUniform([size, size], -1, 1);
    const op = getReductionOp(option);
    const start = performance.now();

    dl.tidy(() => {
      op(input).get();
    });

    const end = performance.now();
    return end - start;
  }
开发者ID:kodamatomohiro,项目名称:tfjs-core,代码行数:14,代码来源:reduction_ops_benchmark.ts

示例3: run

  async run(size: number): Promise<number> {
    dl.setBackend('webgl');

    const a: dl.Tensor2D = dl.randomNormal([size, size]);
    const b: dl.Tensor2D = dl.randomNormal([size, size]);

    const benchmark = () => dl.matMul(a, b);

    const time = await benchmark_util.warmupAndBenchmarkGPU(benchmark);

    a.dispose();
    b.dispose();

    return time;
  }
开发者ID:kodamatomohiro,项目名称:tfjs-core,代码行数:15,代码来源:matmul_benchmarks.ts

示例4: run

  async run(size: number, opType: string, params: ConvParams): Promise<number> {
    dl.setBackend('webgl');

    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 benchmark: () => dl.Tensor;
    if (opType === 'regular') {
      const regParams = params as RegularConvParams;
      const wShape: [number, number, number, number] =
          [filterSize, filterSize, inDepth, regParams.outDepth];
      W = dl.randomUniform(wShape, -1, 1);
      benchmark = () => x.conv2d(W, stride, pad);
    } else if (opType === 'transposed') {
      const regParams = params as RegularConvParams;
      const wShape: [number, number, number, number] =
          [filterSize, filterSize, inDepth, regParams.outDepth];
      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: [number, number, number, number] =
          [filterSize, filterSize, inDepth, depthwiseParams.channelMul];
      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();

    return time;
  }
开发者ID:kodamatomohiro,项目名称:tfjs-core,代码行数:46,代码来源:conv_benchmarks.ts

示例5: run

  async run(size: number, option: string, params: PoolBenchmarkParams):
      Promise<number> {
    dl.setBackend('webgl');

    const outputDepth = params.depth;
    const xShape: [number, number, number] = [size, size, outputDepth];
    const fieldSize = params.fieldSize;
    const stride = params.stride;
    const x: dl.Tensor3D = dl.randomUniform(xShape, -1, 1);
    const op = getPoolingOp(option);

    const benchmark = () => op(x, fieldSize, stride);
    const time = await benchmark_util.warmupAndBenchmarkGPU(benchmark);

    x.dispose();

    return time;
  }
开发者ID:kodamatomohiro,项目名称:tfjs-core,代码行数:18,代码来源:pool_benchmarks.ts

示例6: run

  async run(size: number) {
    dl.setBackend('webgl');

    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();

    return time;
  }
开发者ID:kodamatomohiro,项目名称:tfjs-core,代码行数:19,代码来源:batchnormalization3d_benchmark.ts


注:本文中的deeplearn.setBackend函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。