本文整理汇总了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);
});
示例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
}
}
示例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([]);
});
});
});
//.........这里部分代码省略.........