• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript tfjs.layers类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@tensorflow/tfjs.layers的典型用法代码示例。如果您正苦于以下问题:TypeScript layers类的具体用法?TypeScript layers怎么用?TypeScript layers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了layers类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: constructor

  constructor() {
    super('strike-zone');

    this.fields = [
      {key : 'px', min : PX_MIN, max : PX_MAX},
      {key : 'pz', min : PZ_MIN, max : PZ_MAX},
      {key : 'sz_top', min : SZ_TOP_MIN, max : SZ_TOP_MAX},
      {key : 'sz_bot', min : SZ_BOT_MIN, max : SZ_BOT_MAX},
      {key : 'left_handed_batter'}
    ];

    this.data =
        new PitchData('dist/strike_zone_training_data.json', 50, this.fields, 2,
                      (pitch) => pitch.type === 'S' ? 0 : 1);

    const model = tf.sequential();
    model.add(tf.layers.dense({
      units : 20,
      activation : 'relu',
      inputShape : [ this.fields.length ]
    }));
    model.add(tf.layers.dense({units : 10, activation : 'relu'}));
    model.add(tf.layers.dense({units : 2, activation : 'softmax'}));
    model.compile({
      optimizer : tf.train.adam(),
      loss : 'categoricalCrossentropy',
      metrics : [ 'accuracy' ]
    });
    this.model = model;
  }
开发者ID:AIED-ECNU,项目名称:tfjs-examples,代码行数:30,代码来源:strike-zone-model.ts


示例2: densenet

function densenet(x: tf.SymbolicTensor, init: any): tf.SymbolicTensor {
    const depth = 8
    const width = 8
    for (var i = 0; i < depth; ++i) {
        let y = tf.layers.dense({ units: width, kernelInitializer: init, activation: 'sigmoid' }).apply(x) as tf.SymbolicTensor
        x = tf.layers.concatenate({}).apply([x, y]) as tf.SymbolicTensor
    }

    return x
}
开发者ID:gyngyn1234,项目名称:blog,代码行数:10,代码来源:model.ts


示例3: perceptron

function perceptron(x: tf.SymbolicTensor, init: any): tf.SymbolicTensor {
    const depth = 8
    const width = 32
    for (var i = 0; i < depth; ++i) {
        x = tf.layers.dense({ units: width, kernelInitializer: init, activation: 'tanh' }).apply(x) as tf.SymbolicTensor
    }

    return x
}
开发者ID:gyngyn1234,项目名称:blog,代码行数:9,代码来源:model.ts


示例4: constructor

  constructor() {
    super('pitch-type');

    this.fields = [
      {key: 'vx0', min: VX0_MIN, max: VX0_MAX},
      {key: 'vy0', min: VY0_MIN, max: VY0_MAX},
      {key: 'vz0', min: VZ0_MIN, max: VZ0_MAX},
      {key: 'ax', min: AX_MIN, max: AX_MAX},
      {key: 'ay', min: AY_MIN, max: AY_MAX},
      {key: 'az', min: AZ_MIN, max: AZ_MAX},
      {key: 'start_speed', min: START_SPEED_MIN, max: START_SPEED_MAX},
      {key: 'left_handed_pitcher'}
    ];

    this.data = new PitchData(
        'dist/pitch_type_training_data.json', 100, this.fields, 7,
        (pitch) => pitch.pitch_code);

    const model = tf.sequential();
    model.add(tf.layers.dense(
        {units: 250, activation: 'relu', inputShape: [this.fields.length]}));
    model.add(tf.layers.dense({units: 175, activation: 'relu'}));
    model.add(tf.layers.dense({units: 150, activation: 'relu'}));
    model.add(tf.layers.dense({units: 7, activation: 'softmax'}));
    model.compile({
      optimizer: tf.train.adam(),
      loss: 'categoricalCrossentropy',
      metrics: ['accuracy']
    });

    this.model = model;

    // All pitch data is stored sequentially (pitch_code 0-6) in the training
    // files. Load the training and validation data file and glob all pitches of
    // the same code together in batches. These will be used for calculating the
    // class accuracy.
    this.trainingClassTensors = concatPitchClassTensors(
        'dist/pitch_type_training_data.json', this.fields, NUM_PITCH_CLASSES,
        TRAINING_DATA_PITCH_CLASS_SIZE);
    this.validationClassTensors = concatPitchClassTensors(
        'dist/pitch_type_validation_data.json', this.fields, NUM_PITCH_CLASSES,
        TRAINING_DATA_PITCH_CLASS_SIZE);
  }
开发者ID:AIED-ECNU,项目名称:tfjs-examples,代码行数:43,代码来源:pitch-type-model.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


示例6: resnet

function resnet(x: tf.SymbolicTensor, init: any): tf.SymbolicTensor {
    const depth = 8
    const width = 32
    for (var i = 0; i < depth; ++i) {
        let y: tf.SymbolicTensor
        if (i != 0)
            y = tf.layers.activation({ activation: 'tanh' }).apply(x) as tf.SymbolicTensor
        else
            y = x

        y = tf.layers.dense({ units: width, kernelInitializer: init, activation: 'tanh' }).apply(x) as tf.SymbolicTensor
        
        let x_ = x
        if (x_.shape[1] != width)
            x_ = tf.layers.dense({ units: width, kernelInitializer: init }).apply(x_) as tf.SymbolicTensor
        
        x = tf.layers.add().apply([x_, y]) as tf.SymbolicTensor
    }

    x = tf.layers.activation({ activation: 'tanh' }).apply(x) as tf.SymbolicTensor

    return x
}
开发者ID:gyngyn1234,项目名称:blog,代码行数:23,代码来源:model.ts


示例7: createModel

export function createModel(type: "densenet" | "perceptron" | "resnet", scale: number, bw = false, seed?: number): tf.Model {
    let init = tf.initializers.varianceScaling({ scale: scale, mode: 'fanIn', distribution: 'normal', seed })
    let binit = tf.initializers.zeros() // tf.initializers.randomNormal({ mean: 0, stddev: 4 })
    let input = tf.input({ shape: [ 4 ] })

    let x: tf.SymbolicTensor = input

    switch (type) {
        case "densenet":
            x = densenet(x, init);
            break;
        case "perceptron":
            x = perceptron(x, init);
            break;
        case "resnet":
            x = resnet(x, init);
            break;
    }

    x = tf.layers.dense({ units: bw ? 1 : 3, activation: 'tanh', kernelInitializer: tf.initializers.glorotNormal({ seed }) }).apply(x) as tf.SymbolicTensor

    return tf.model({ inputs: input, outputs: x })
}
开发者ID:gyngyn1234,项目名称:blog,代码行数:23,代码来源:model.ts


示例8: Scene

window.tf = tf;

const scene = new Scene();
const renderer = new Renderer(scene);

console.time('go!');
for (let i = 0; i < 60 * 10; i++) {}
console.timeEnd('go!');
console.log('constraints', scene.constraints.length);
console.log(scene.getPositions().length);
console.log(scene.fitness);

const model = tf.sequential({
  layers: [
    tf.layers.dense({ units: 32, inputShape: [24], activation: 'relu' }),
    tf.layers.dense({ units: 10 }),
  ],
});

model.compile({ optimizer: 'sgd', loss: 'meanSquaredError' });

window.model = model;

const frame = function() {
  scene.step();

  tf.tidy(() => {
    const output = model.predictOnBatch(
      tf.tensor2d(scene.getPositions(), [1, 24])
    ) as tf.Tensor<tf.Rank.R1>;
开发者ID:Vakrim,项目名称:not_so_ragdoll,代码行数:30,代码来源:index.ts



注:本文中的@tensorflow/tfjs.layers类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap