Add unified training mode, but apparently we're now crashing the client 🤔
This commit is contained in:
parent
80606f93d8
commit
3ebc54ef74
4 changed files with 64 additions and 4 deletions
|
@ -18,6 +18,7 @@ export default async function(c) {
|
||||||
// 2: CLI Argument Parsing
|
// 2: CLI Argument Parsing
|
||||||
let args = process.argv.slice(2); // Slice out the node binary name and the filename
|
let args = process.argv.slice(2); // Slice out the node binary name and the filename
|
||||||
let extras = [];
|
let extras = [];
|
||||||
|
|
||||||
for(let i = 0; i < args.length; i++) {
|
for(let i = 0; i < args.length; i++) {
|
||||||
if(!args[i].startsWith("-")) {
|
if(!args[i].startsWith("-")) {
|
||||||
extras.push(args[i]);
|
extras.push(args[i]);
|
||||||
|
@ -36,6 +37,13 @@ export default async function(c) {
|
||||||
console.log(program.version);
|
console.log(program.version);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "--ai-unified":
|
||||||
|
settings.ai.mode = "unified";
|
||||||
|
break;
|
||||||
|
case "--ai-split":
|
||||||
|
settings.ai.mode = "split";
|
||||||
|
break;
|
||||||
|
|
||||||
// Add more arguments here
|
// Add more arguments here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,8 +107,15 @@ export default async function(c) {
|
||||||
|
|
||||||
l.log(`${a.fgreen}${a.hicol}Training AIs${a.reset}`);
|
l.log(`${a.fgreen}${a.hicol}Training AIs${a.reset}`);
|
||||||
let ai_trainer = c.cradle.AITrainer;
|
let ai_trainer = c.cradle.AITrainer;
|
||||||
|
switch(settings.ai.mode) {
|
||||||
|
case "split":
|
||||||
await ai_trainer.train_all();
|
await ai_trainer.train_all();
|
||||||
break;
|
break;
|
||||||
|
case "unified":
|
||||||
|
await ai_trainer.train_unified();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "geojson-debug":
|
case "geojson-debug":
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
|
@ -17,8 +17,11 @@ ${a.fblue}${a.hicol}Subcommands:${a.reset}
|
||||||
${a.fyellow}train-ai${a.reset} Trains the AI on the consolidated data
|
${a.fyellow}train-ai${a.reset} Trains the AI on the consolidated data
|
||||||
|
|
||||||
${a.fblue}${a.hicol}Options:${a.reset}
|
${a.fblue}${a.hicol}Options:${a.reset}
|
||||||
${a.fyellow}-h --help ${a.reset}Show this message
|
${a.fyellow}-h --help ${a.reset} Show this message
|
||||||
${a.fyellow}-v --version ${a.reset}Show the version of this program
|
${a.fyellow}-v --version ${a.reset} Show the version of this program
|
||||||
|
|
||||||
|
${a.fyellow} --ai-unified${a.reset} Switch to the unified AI training mode. This trains 1 AI for everything, instead of 1 AI per gateway.
|
||||||
|
${a.fyellow} --ai-split${a.reset} Switch to the split AI training mode (the default). This trains 1 AI per gateway.
|
||||||
|
|
||||||
${a.fblue}${a.hicol}Environment Variables:${a.reset}
|
${a.fblue}${a.hicol}Environment Variables:${a.reset}
|
||||||
(none yet)
|
(none yet)
|
||||||
|
|
|
@ -84,6 +84,12 @@ learning_rate = 0.1
|
||||||
# The momentum term to use when learning
|
# The momentum term to use when learning
|
||||||
momentum = 0.1
|
momentum = 0.1
|
||||||
|
|
||||||
|
# Either "split" or "unified".
|
||||||
|
# Describes the mode of training for the AIs.
|
||||||
|
# In split mode (the default), 1 AI is trained for each of the gateways detected.
|
||||||
|
# In unified mode, we train 1 AI that predict everything.
|
||||||
|
mode = "split"
|
||||||
|
|
||||||
# The directory to output trained AIs to, relative to the repository root.
|
# The directory to output trained AIs to, relative to the repository root.
|
||||||
output_directory = "app/ais/"
|
output_directory = "app/ais/"
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,43 @@ class AITrainer {
|
||||||
this.repo_gateway = GatewayRepo;
|
this.repo_gateway = GatewayRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async train_unified() {
|
||||||
|
this.l.log(`${this.a.fgreen}${this.a.hicol}Unified training mode activated.${this.a.reset}`);
|
||||||
|
let filepath = path.join(
|
||||||
|
this.root_dir,
|
||||||
|
"..",
|
||||||
|
this.settings.ai.output_directory,
|
||||||
|
"ai.json"
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!fs.existsSync(path.dirname(filepath)))
|
||||||
|
await fs.promises.mkdir(path.dirname(filepath), { recursive: true });
|
||||||
|
|
||||||
|
let training_result = await this.train_gateway(null, filepath);
|
||||||
|
|
||||||
|
await fs.promises.writeFile(
|
||||||
|
path.join(
|
||||||
|
path.dirname(this.root_dir),
|
||||||
|
this.settings.ai.output_directory,
|
||||||
|
"index.json"
|
||||||
|
),
|
||||||
|
JSON.stringify({
|
||||||
|
properties: {
|
||||||
|
rssi_min: -150,
|
||||||
|
rssi_max: 0
|
||||||
|
},
|
||||||
|
index: [{
|
||||||
|
id: "Unified AI (not a real gateway)",
|
||||||
|
filename: "ai.json",
|
||||||
|
latitude: 0, longitude: 0,
|
||||||
|
net_settings: training_result.net_settings
|
||||||
|
}]
|
||||||
|
}, null, "\t")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async train_all() {
|
async train_all() {
|
||||||
|
this.l.log(`${this.a.fgreen}${this.a.hicol}Split (default) training mode activated.${this.a.reset}`);
|
||||||
let index = [];
|
let index = [];
|
||||||
for(let gateway of this.repo_gateway.iterate()) {
|
for(let gateway of this.repo_gateway.iterate()) {
|
||||||
let filepath = path.join(this.root_dir, "..", this.settings.ai.output_directory, `${gateway.id}.json`);
|
let filepath = path.join(this.root_dir, "..", this.settings.ai.output_directory, `${gateway.id}.json`);
|
||||||
|
@ -87,7 +123,7 @@ class AITrainer {
|
||||||
timeout: Infinity
|
timeout: Infinity
|
||||||
});
|
});
|
||||||
|
|
||||||
await fs.promises.writeFile(destination_filename, JSON.stringify(net.toJSON()));
|
await fs.promises.writeFile(destination_filename, JSON.stringify(net.toJSON()), null, "\t");
|
||||||
// console.log(result);
|
// console.log(result);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue