本文整理汇总了TypeScript中@tensorflow/tfjs-core.tensor2d函数的典型用法代码示例。如果您正苦于以下问题:TypeScript tensor2d函数的具体用法?TypeScript tensor2d怎么用?TypeScript tensor2d使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tensor2d函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(() => {
tensorArray = new TensorArray(
NAME, DTYPE, SIZE, SHAPE, IDENTICAL_SHAPE, DYNAMIC_SIZE,
CLEAR_AFTER_READ);
tensor = tensor2d([1], [1, 1], 'int32');
tensor2 = tensor2d([2], [1, 1], 'int32');
});
示例2: extractFcParams
function extractFcParams(channelsIn: number, channelsOut: number,): FCParams {
const fc_weights = tf.tensor2d(extractWeights(channelsIn * channelsOut), [channelsIn, channelsOut])
const fc_bias = tf.tensor1d(extractWeights(channelsOut))
return {
weights: fc_weights,
bias: fc_bias
}
}
示例3: it
it('should generate the output array', async () => {
await model.load();
const input = tfc.tensor2d([1, 1], [2, 1], 'int32');
const output = model.execute({'Input': input}, ['Add', 'Const']);
expect(Array.isArray(output)).toBeTruthy();
expect((output as tfc.Tensor[])[0].dataSync()[0]).toEqual(2);
expect((output as tfc.Tensor[])[1].dataSync()[0]).toEqual(1);
});
示例4: generateAtlas
generateAtlas() {
for (let i = 0; i < this.atlasSize; ++i) {
const distribution = this.sampleFromTrueDistribution(
this.selectedShapeName, this.drawingPositions);
this.inputAtlasList.push(distribution[0]);
this.inputAtlasList.push(distribution[1]);
}
this.atlas = tf.tensor2d(this.inputAtlasList, [this.atlasSize, 2]);
}
示例5: extractParams
export function extractParams(weights: Float32Array): NetParams {
const {
extractWeights,
getRemainingWeights
} = extractWeightsFactory(weights)
const {
extractConvLayerParams,
extractResidualLayerParams
} = extractorsFactory(extractWeights)
const conv32_down = extractConvLayerParams(4704, 32, 7)
const conv32_1 = extractResidualLayerParams(9216, 32, 3)
const conv32_2 = extractResidualLayerParams(9216, 32, 3)
const conv32_3 = extractResidualLayerParams(9216, 32, 3)
const conv64_down = extractResidualLayerParams(36864, 64, 3, true)
const conv64_1 = extractResidualLayerParams(36864, 64, 3)
const conv64_2 = extractResidualLayerParams(36864, 64, 3)
const conv64_3 = extractResidualLayerParams(36864, 64, 3)
const conv128_down = extractResidualLayerParams(147456, 128, 3, true)
const conv128_1 = extractResidualLayerParams(147456, 128, 3)
const conv128_2 = extractResidualLayerParams(147456, 128, 3)
const conv256_down = extractResidualLayerParams(589824, 256, 3, true)
const conv256_1 = extractResidualLayerParams(589824, 256, 3)
const conv256_2 = extractResidualLayerParams(589824, 256, 3)
const conv256_down_out = extractResidualLayerParams(589824, 256, 3)
const fc = tf.transpose(tf.tensor2d(extractWeights(256 * 128), [128, 256]), [1, 0])
if (getRemainingWeights().length !== 0) {
throw new Error(`weights remaing after extract: ${getRemainingWeights().length}`)
}
return {
conv32_down,
conv32_1,
conv32_2,
conv32_3,
conv64_down,
conv64_1,
conv64_2,
conv64_3,
conv128_down,
conv128_1,
conv128_2,
conv256_down,
conv256_1,
conv256_2,
conv256_down_out,
fc
}
}
示例6: it
it('should call tfc.pad', () => {
spyOn(tfc, 'pad');
node.op = 'pad';
node.params.padding = createNumericArrayAttrFromIndex(1);
node.params.constantValue = createNumberAttr(1);
node.inputNames = ['input1', 'input3'];
const input3 = [tfc.tensor2d([1, 1, 2, 2], [2, 2])];
executeOp(node, {input1, input3}, context);
expect(tfc.pad).toHaveBeenCalledWith(input1[0], [[1, 1], [2, 2]], 1);
});
示例7: it
it('should split the tensor to tensorArray', async () => {
const tensorArray =
new TensorArray('', 'int32', 2, [3], true, false, true);
const input4 = [tensor2d([0, 0, 0, 1, 1, 1], [2, 3], 'int32')];
context.addTensorArray(tensorArray);
node.op = 'tensorArraySplit';
node.params['tensorArrayId'] = createNumberAttrFromIndex(0);
node.params['tensor'] = createTensorAttr(1);
node.params['lengths'] = createNumericArrayAttrFromIndex(2);
node.inputNames = ['input2', 'input4', 'input3'];
const input2 = [scalar(tensorArray.id)];
const input3 = [tensor1d([1, 1], 'int32')];
await executeOp(node, {input2, input3, input4}, context);
expect(tensorArray.size()).toEqual(2);
});