當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript deeplearn.randomUniform函數代碼示例

本文整理匯總了TypeScript中deeplearn.randomUniform函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript randomUniform函數的具體用法?TypeScript randomUniform怎麽用?TypeScript randomUniform使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了randomUniform函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
    });
  }
開發者ID:ScapeQin,項目名稱:deeplearnjs,代碼行數:27,代碼來源:pool_benchmarks.ts

示例2: run

  async run(size: number): Promise<number> {
    if (this.lastRunTimeMs > LAST_RUN_CPU_CUTOFF_MS) {
      return new Promise<number>((resolve, reject) => {
        resolve(-1);
      });
    }
    dl.setBackend('cpu');

    const a: dl.Tensor2D = dl.randomUniform([size, size], -1, 1);
    const b: dl.Tensor2D = dl.randomUniform([size, size], -1, 1);
    const start = performance.now();
    dl.matMul(a, b);
    const end = performance.now();
    this.lastRunTimeMs = end - start;
    return this.lastRunTimeMs;
  }
開發者ID:kodamatomohiro,項目名稱:tfjs-core,代碼行數:16,代碼來源:matmul_benchmarks.ts

示例3: 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

示例4: run

  async run(size: number): Promise<number> {
    if (this.lastRunTimeMs > LAST_RUN_CPU_CUTOFF_MS) {
      return new Promise<number>((resolve, reject) => {
        resolve(-1);
      });
    }
    const safeMode = false;
    const math = new dl.NDArrayMath('cpu', safeMode);
    dl.ENV.setMath(math);

    const a: dl.Tensor2D = dl.randomUniform([size, size], -1, 1);
    const b: dl.Tensor2D = dl.randomUniform([size, size], -1, 1);
    const start = performance.now();
    math.matMul(a, b);
    const end = performance.now();

    math.dispose();

    this.lastRunTimeMs = end - start;
    return this.lastRunTimeMs;
  }
開發者ID:ScapeQin,項目名稱:deeplearnjs,代碼行數:21,代碼來源:matmul_benchmarks.ts

示例5: 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

示例6: 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

示例7: 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;
  }
開發者ID:ScapeQin,項目名稱:deeplearnjs,代碼行數:54,代碼來源:conv_benchmarks.ts

示例8: 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;
  }
開發者ID:ScapeQin,項目名稱:deeplearnjs,代碼行數:17,代碼來源:reduction_ops_benchmark.ts

示例9: 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


注:本文中的deeplearn.randomUniform函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。