2020-09-15 17:32:51 +00:00
"use strict" ;
import path from 'path' ;
import CliParser from 'applause-cli' ;
import train from './subcommands/train/train.mjs' ;
import predict from './subcommands/predict/predict.mjs' ;
const _ _dirname = import . meta . url . slice ( 7 , import . meta . url . lastIndexOf ( "/" ) ) ;
export default async function ( ) {
let cli = new CliParser ( path . resolve ( _ _dirname , "../package.json" ) ) ;
cli . subcommand ( "train" , "Trains a new AI" )
. argument ( "input" , "The input directory containing the training data" , null , "string" )
2020-12-15 18:22:50 +00:00
. argument ( "output" , "Path to the output directory to save the trained AI to" )
. argument ( "image-size" , "The width+height of input images (images are assumed to be square; default: 256)" , 256 , "integer" )
. argument ( "cross-entropy" , "Use categorical cross-entropy loss instead of mean-squared error (best if each image has only a single label)" , false , "boolean" )
2020-09-15 17:32:51 +00:00
cli . subcommand ( "predict" , "Predicts the genres of the specified image" )
. argument ( "input" , "Path to the input image" )
. argument ( "ai-model" , "Path to the saved AI model to load" ) ;
let settings = cli . parse ( process . argv . slice ( 2 ) ) ;
if ( cli . current _subcommand == null ) {
cli . write _help _exit ( ) ;
return ;
}
switch ( cli . current _subcommand ) {
case "train" :
await train ( settings ) ;
break ;
case "predict" :
await predict ( settings ) ;
break ;
default :
console . error ( ` Error: Unknown subcommand ' ${ cli . current _subcommand } ' (try --help for usage information) ` ) ;
process . exit ( 1 ) ;
break ;
}
}