本文整理匯總了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());
})();