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


TypeScript tfjs-core.tensor3d函数代码示例

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


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

示例1: it

 it('should create three new tensors', () => {
   const input =
       tensor3d([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [3, 2, 2], 'int32');
   const numTensors: number = memory().numTensors;
   tensorArray.split([1, 1, 1], input);
   expect(memory().numTensors).toEqual(numTensors + 3);
 });
开发者ID:oveddan,项目名称:tfjs-converter,代码行数:7,代码来源:tensor_array_test.ts

示例2: extractParams

export function extractParams(weights: Float32Array): NetParams {
  const {
    extractWeights,
    getRemainingWeights
  } = extractWeightsFactory(weights)

  const {
    extractMobilenetV1Params,
    extractPredictionLayerParams
  } = extractorsFactory(extractWeights)

  const mobilenetv1_params = extractMobilenetV1Params()
  const prediction_layer_params = extractPredictionLayerParams()
  const extra_dim = tf.tensor3d(
    extractWeights(5118 * 4),
    [1, 5118, 4]
  )
  const output_layer_params = {
    extra_dim
  }

  if (getRemainingWeights().length !== 0) {
    throw new Error(`weights remaing after extract: ${getRemainingWeights().length}`)
  }

  return {
    mobilenetv1_params,
    prediction_layer_params,
    output_layer_params
  }
}
开发者ID:BakirDiyar,项目名称:face-api.js,代码行数:31,代码来源:extractParams.ts

示例3: describe

describe('graph', () => {
  let node: Node;
  const input1 = [tfc.tensor1d([1])];
  const input2 = [tfc.tensor1d([1])];
  const input3 = [tfc.tensor3d([1, 1, 1, 2, 2, 2], [1, 2, 3])];
  const context = new ExecutionContext({}, {});

  beforeEach(() => {
    node = {
      name: 'input1',
      op: '',
      category: 'graph',
      inputNames: [],
      inputs: [],
      params: {},
      children: []
    };
  });

  describe('executeOp', () => {
    describe('const', () => {
      it('should return input', () => {
        node.op = 'const';
        expect(executeOp(node, {input1}, context)).toEqual(input1);
      });
    });
    describe('placeholder', () => {
      it('should return input', () => {
        node.op = 'placeholder';
        expect(executeOp(node, {input1}, context)).toEqual(input1);
      });
      it('should return default if input not set', () => {
        node.inputNames = ['input2'];
        node.op = 'placeholder';
        node.params.default = createTensorAttr(0);
        expect(executeOp(node, {input2}, context)).toEqual(input2);
      });
    });
    describe('identity', () => {
      it('should return input', () => {
        node.inputNames = ['input'];
        node.params.x = createTensorAttr(0);
        node.op = 'identity';
        expect(executeOp(node, {input: input1}, context)).toEqual(input1);
      });
    });
    describe('snapshot', () => {
      it('should return input', () => {
        node.inputNames = ['input'];
        node.params.x = createTensorAttr(0);
        node.op = 'snapshot';
        const result =
            (executeOp(node, {input: input1}, context) as tfc.Tensor[])[0];
        expect(result.rank).toEqual(input1[0].rank);
        test_util.expectArraysClose(result, [1]);
      });
    });
    describe('shape', () => {
      it('should return shape', () => {
        node.inputNames = ['input'];
        node.params.x = createTensorAttr(0);
        node.op = 'shape';
        expect(
            Array.prototype.slice.call(
                (executeOp(node, {input: input3}, context) as tfc.Tensor[])[0]
                    .dataSync()))
            .toEqual([1, 2, 3]);
      });
    });
    describe('size', () => {
      it('should return size', () => {
        node.inputNames = ['input'];
        node.params.x = createTensorAttr(0);
        node.op = 'size';
        expect(
            Array.prototype.slice.call(
                (executeOp(node, {input: input3}, context) as tfc.Tensor[])[0]
                    .dataSync()))
            .toEqual([6]);
      });
    });
    describe('rank', () => {
      it('should return rank', () => {
        node.inputNames = ['input'];
        node.params.x = createTensorAttr(0);
        node.op = 'rank';
        expect(
            Array.prototype.slice.call(
                (executeOp(node, {input: input3}, context) as tfc.Tensor[])[0]
                    .dataSync()))
            .toEqual([3]);
      });
    });
    describe('noop', () => {
      it('should return empty', () => {
        node.op = 'noop';
        expect(executeOp(node, {}, context)).toEqual([]);
      });
    });
  });
//.........这里部分代码省略.........
开发者ID:oveddan,项目名称:tfjs-converter,代码行数:101,代码来源:graph_executor_test.ts


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