當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript tfjs.tensor2d函數代碼示例

本文整理匯總了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);
    }
  }
開發者ID:tseitz,項目名稱:TuneWrangler,代碼行數:26,代碼來源:analyze.ts

示例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()));
  });
開發者ID:Vakrim,項目名稱:not_so_ragdoll,代碼行數:7,代碼來源:index.ts

示例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]);
 });
開發者ID:AIED-ECNU,項目名稱:tfjs-examples,代碼行數:9,代碼來源:pitch-data.ts

示例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);
  }
}
開發者ID:alonn24,項目名稱:alonn24.github.io,代碼行數:11,代碼來源:keras.ts

示例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());
})();
開發者ID:Vakrim,項目名稱:not_so_ragdoll,代碼行數:38,代碼來源:createModelOfSim.ts


注:本文中的@tensorflow/tfjs.tensor2d函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。