2019-07-17 13:16:24 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import tf from '@tensorflow/tfjs-node-gpu';
|
|
|
|
|
|
|
|
class AITrainer {
|
2019-07-17 14:15:31 +00:00
|
|
|
constructor({ settings, GatewayRepo, DatasetFetcher }) {
|
2019-07-17 13:16:24 +00:00
|
|
|
this.settings = settings;
|
2019-07-17 14:15:31 +00:00
|
|
|
this.dataset_fetcher = DatasetFetcher;
|
|
|
|
this.repo_gateway = GatewayRepo;
|
2019-07-17 13:16:24 +00:00
|
|
|
this.model = this.generate_model();
|
|
|
|
}
|
|
|
|
|
|
|
|
generate_model() {
|
|
|
|
let model = tf.sequential();
|
|
|
|
model.add(tf.layers.dense({
|
|
|
|
units: 256, // 256 nodes
|
|
|
|
activation: "sigmoid", // Sigmoid activation function
|
|
|
|
inputShape: [3], // 2 inputs - lat and long
|
|
|
|
}))
|
|
|
|
model.add(tf.layers.dense({
|
|
|
|
units: 1, // 1 output value - RSSI
|
|
|
|
activation: "sigmoid" // The example code uses softmax, but this is generally best used for classification tasks
|
|
|
|
}));
|
|
|
|
|
|
|
|
model.compile({
|
|
|
|
optimizer: tf.train.adam(),
|
|
|
|
loss: "absoluteDifference",
|
|
|
|
metrics: [ "accuracy", "meanSquaredError" ]
|
|
|
|
});
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2019-07-17 14:15:31 +00:00
|
|
|
async train() {
|
|
|
|
for(let gateway of this.repo_gateway.iterate()) {
|
|
|
|
let dataset = this.dataset_fetcher.fetch(gateway.id);
|
|
|
|
await this.train_dataset(dataset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async train_dataset(dataset) {
|
|
|
|
// TODO: Fill this in
|
2019-07-17 13:16:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AITrainer;
|