本文整理汇总了TypeScript中@tensorflow/tfjs.sequential函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sequential函数的具体用法?TypeScript sequential怎么用?TypeScript sequential使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sequential函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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
示例3:
(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
示例4: 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.sequential函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论