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