当前位置: 首页>>代码示例>>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;未经允许,请勿转载。