Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- model = tf.sequential();
- model.add(tf.layers.conv2d({
- inputShape: [48, 48, 1],
- kernelSize: FILTER_SIZE,
- filters: 64,
- dataFormat: "channelsLast",
- activation: ActFunc.RELU
- }));
- model.add(tf.layers.maxPooling2d(maxPoolConf));
- model.add(tf.layers.conv2d({
- kernelSize: FILTER_SIZE,
- filters: 128,
- dataFormat: "channelsLast",
- activation: ActFunc.RELU
- }));
- model.add(tf.layers.maxPooling2d(maxPoolConf));
- model.add(tf.layers.conv2d({
- kernelSize: FILTER_SIZE,
- filters: 256,
- dataFormat: "channelsLast",
- activation: ActFunc.RELU
- }));
- model.add(tf.layers.maxPooling2d(maxPoolConf));
- model.add(tf.layers.conv2d({
- kernelSize: FILTER_SIZE,
- filters: 512,
- dataFormat: "channelsLast",
- activation: ActFunc.RELU
- }));
- model.add(tf.layers.maxPooling2d(maxPoolConf));
- model.add(tf.layers.flatten());
- model.add(tf.layers.dense({units: 128, activation: 'relu'}));
- model.add(tf.layers.dense({units: 256, activation: 'relu'}));
- model.add(tf.layers.dense({units: 512, activation: 'relu'}));
- model.add(tf.layers.dense({units: 1024, activation: 'relu'}));
- model.add(tf.layers.dense({
- units: 7,
- activation: 'softmax'
- }));
- model.compile({
- optimizer: 'adam',
- loss: 'categoricalCrossentropy',
- metrics: ['accuracy', 'categoricalCrossentropy']
- });
- let image_tensor = tf.tensor4d(training_data.getInputData(), [training_data.length, 48, 48, 1]);
- let correct_prediction_tensor = tf.tensor2d(training_data.getLabels(), [training_data.length, 7]);
- const history = model.fit(image_tensor, correct_prediction_tensor,
- {
- batchSize: 128,
- epochs: 10,
- shuffle: true,
- callbacks: {
- onEpochEnd: (epoch, logs) => {
- // Plot the loss and accuracy values at the end of every training epoch.
- console.log(epoch, logs);
- },
- onTrainStart: console.log("Starting Training..."),
- onTrainEnd: console.log("Training Finished!"),
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement