本文整理汇总了TypeScript中@tensorflow/tfjs.tensor2d函数的典型用法代码示例。如果您正苦于以下问题:TypeScript tensor2d函数的具体用法?TypeScript tensor2d怎么用?TypeScript tensor2d使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tensor2d函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
s.draw = () => {
s.background(0);
let spectrum = fft.analyze();
if (spectrum.some((i) => i > 0)) {
const tensor = tf.tensor2d(spectrum, [64, 4]);
tensor.print();
}
s.noStroke();
s.translate(s.width / 2, s.height / 2);
for (var i = 0; i < spectrum.length; i++) {
var angle = s.map(i, 0, spectrum.length, 0, 360);
var amp = spectrum[i];
var r = s.map(amp, 0, 256, 20, 100);
//fill(i, 255, 255);
var x = r * s.cos(angle);
var y = r * s.sin(angle);
s.stroke(i, 255, 255);
s.line(0, 0, x, y);
//vertex(x, y);
//var y = map(amp, 0, 256, height, 0);
//rect(i * w, y, w - 2, height - y);
}
}
示例2:
tf.tidy(() => {
const output = model.predictOnBatch(
tf.tensor2d(scene.getPositions(), [1, 24])
) as tf.Tensor<tf.Rank.R1>;
scene.setMomentum(Array.from(output.dataSync()));
});
示例3:
return tf.tidy(() => {
let offset = 0;
for (let i = 0; i < pitches.length; i++) {
const pitch = pitches[i];
data.set(pitchTrainDataArray(pitch, fields), offset);
offset += fields.length;
}
return tf.tensor2d(data, shape as [number, number]);
});
示例4: function
export default async function () {
const products = await load('./data/proposed_new_products.json');
const model = await tf.loadModel('data/trained_model/model.json');
const modelConf = await load('data/trained_model_conf.json');
const tensors: any = model.predict(tf.tensor2d(products));
for (let i = 0; i < tensors.size; i++) {
let prediction = tensors.get(i, 0);
console.log('prediction', (prediction + modelConf.adding) / modelConf.multiplying);
}
}
示例5:
(async () => {
const model = tf.sequential({
layers: [
tf.layers.dense({ units: 200, inputShape: [400], activation: 'relu' }),
tf.layers.dense({ units: 200, activation: 'relu' }),
tf.layers.dense({ units: 200, activation: 'relu' }),
tf.layers.dense({ units: 1 }),
],
});
const optimizer = tf.train.sgd(0.001);
model.compile({ loss: 'meanSquaredError', optimizer });
const xs = tf.tensor2d(results.map(r => r.input));
const ys = tf.tensor2d(results.map(r => [r.fitness]));
const [evaluteX, trainX] = tf.split(xs, 2, 0);
const [evaluteY, trainY] = tf.split(ys, 2, 0);
await model
.fit(trainX, trainY, {
epochs: 100,
shuffle: true,
validationSplit: 0.2,
})
.then(h => {
console.log(h);
console.log(
`Learning Loss: ${h.history.loss[h.history.loss.length - 1]}`
);
console.log(
`Validation Loss: ${h.history.val_loss[h.history.val_loss.length - 1]}`
);
});
console.log(tf.memory());
})();