diff --git a/logic/models/edit.go b/logic/models/edit.go index 0ec2302..1c3b335 100644 --- a/logic/models/edit.go +++ b/logic/models/edit.go @@ -99,12 +99,14 @@ func handleEdit(handle *Handle) { case TRAINING: type defrow struct { + Id string Status int EpochProgress int + Epoch int Accuracy float64 } - def_rows, err := c.Db.Query("select status, epoch_progress, accuracy from model_definition where model_id=$1", model.Id) + def_rows, err := c.Db.Query("select id, status, epoch, epoch_progress, accuracy from model_definition where model_id=$1 order by created_on asc", model.Id) if err != nil { return c.Error500(err) } @@ -114,16 +116,54 @@ func handleEdit(handle *Handle) { for def_rows.Next() { var def defrow - err = def_rows.Scan(&def.Status, &def.EpochProgress, &def.Accuracy) + err = def_rows.Scan(&def.Id, &def.Status, &def.Epoch, &def.EpochProgress, &def.Accuracy) if err != nil { return c.Error500(err) } defs = append(defs, def) } + type layerdef struct { + LayerType int + Shape string + } + + layers := []layerdef{} + + for _, def := range defs { + if def.Status == MODEL_DEFINITION_STATUS_TRAINING { + rows, err := c.Db.Query("select layer_type, shape from model_definition_layer where def_id=$1 order by layer_order asc;", def.Id) + if err != nil { + return c.Error500(err) + } + defer rows.Close() + + for rows.Next() { + var layerdef layerdef + err = rows.Scan(&layerdef.LayerType, &layerdef.Shape) + if err != nil { + return c.Error500(err) + } + layers = append(layers, layerdef) + } + break + } + } + + sep_mod := 100 + if len(layers) > 8 { + sep_mod = 100 - (len(layers)-8)*10 + } + + if sep_mod < 10 { + sep_mod = 10 + } + LoadBasedOnAnswer(c.Mode, w, "/models/edit.html", c.AddMap(AnyMap{ - "Model": model, - "Defs": defs, + "Model": model, + "Defs": defs, + "Layers": layers, + "SepMod": sep_mod, })) case PREPARING_ZIP_FILE: LoadBasedOnAnswer(c.Mode, w, "/models/edit.html", c.AddMap(AnyMap{ diff --git a/logic/models/train/train.go b/logic/models/train/train.go index 0f7605f..f69591b 100644 --- a/logic/models/train/train.go +++ b/logic/models/train/train.go @@ -19,7 +19,7 @@ import ( . "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils" ) -const EPOCH_PER_RUN = 20 +const EPOCH_PER_RUN = 1 const MAX_EPOCH = 100 func MakeDefenition(db *sql.DB, model_id string, target_accuracy int) (id string, err error) { @@ -36,28 +36,6 @@ func MakeDefenition(db *sql.DB, model_id string, target_accuracy int) (id string return } -type ModelDefinitionStatus int - -const ( - MODEL_DEFINITION_STATUS_CANCELD_TRAINING = -4 - MODEL_DEFINITION_STATUS_FAILED_TRAINING = -3 - MODEL_DEFINITION_STATUS_PRE_INIT ModelDefinitionStatus = 1 - MODEL_DEFINITION_STATUS_INIT = 2 - MODEL_DEFINITION_STATUS_TRAINING = 3 - MODEL_DEFINITION_STATUS_PAUSED_TRAINING = 6 - MODEL_DEFINITION_STATUS_TRANIED = 4 - MODEL_DEFINITION_STATUS_READY = 5 -) - -type LayerType int - -const ( - LAYER_INPUT LayerType = 1 - LAYER_DENSE = 2 - LAYER_FLATTEN = 3 - LAYER_SIMPLE_BLOCK = 4 -) - func ModelDefinitionUpdateStatus(c *Context, id string, status ModelDefinitionStatus) (err error) { _, err = c.Db.Exec("update model_definition set status = $1 where id = $2", status, id) return @@ -301,7 +279,10 @@ func trainModel(c *Context, model *BaseModel) { } def.epoch += EPOCH_PER_RUN accuracy = accuracy * 100 - def.acuracy = accuracy + def.acuracy = float64(accuracy) + + definitions[i].epoch += EPOCH_PER_RUN + definitions[i].acuracy = accuracy if accuracy >= float64(def.target_accuracy) { c.Logger.Info("Found a definition that reaches target_accuracy!") @@ -361,11 +342,11 @@ func trainModel(c *Context, model *BaseModel) { continue } - sort.Sort(definitions) + sort.Reverse(definitions) - acc := definitions[0].acuracy - 20 + acc := definitions[0].acuracy - 20.0 - c.Logger.Info("Training models, Highest acc", "acc", acc) + c.Logger.Info("Training models, Highest acc", "acc", definitions[0].acuracy, "mod_acc", acc) toRemove = []int{} for i, def := range definitions { diff --git a/logic/models/utils/types.go b/logic/models/utils/types.go index df75962..faa88a4 100644 --- a/logic/models/utils/types.go +++ b/logic/models/utils/types.go @@ -29,14 +29,40 @@ const ( READY = 5 ) +type ModelDefinitionStatus int + +type LayerType int + +const ( + LAYER_INPUT LayerType = 1 + LAYER_DENSE = 2 + LAYER_FLATTEN = 3 + LAYER_SIMPLE_BLOCK = 4 +) + +const ( + MODEL_DEFINITION_STATUS_CANCELD_TRAINING ModelDefinitionStatus = -4 + MODEL_DEFINITION_STATUS_FAILED_TRAINING = -3 + MODEL_DEFINITION_STATUS_PRE_INIT = 1 + MODEL_DEFINITION_STATUS_INIT = 2 + MODEL_DEFINITION_STATUS_TRAINING = 3 + MODEL_DEFINITION_STATUS_PAUSED_TRAINING = 6 + MODEL_DEFINITION_STATUS_TRANIED = 4 + MODEL_DEFINITION_STATUS_READY = 5 +) + var ModelNotFoundError = errors.New("Model not found error") func GetBaseModel(db *sql.DB, id string) (base *BaseModel, err error) { rows, err := db.Query("select name, status, id, width, height, color_mode, format from models where id=$1;", id) - if err != nil { return } + if err != nil { + return + } defer rows.Close() - if !rows.Next() { return nil, ModelNotFoundError } + if !rows.Next() { + return nil, ModelNotFoundError + } base = &BaseModel{} var colorMode string diff --git a/logic/utils/handler.go b/logic/utils/handler.go index 1c51f59..f70d073 100644 --- a/logic/utils/handler.go +++ b/logic/utils/handler.go @@ -563,12 +563,12 @@ func (x Handle) ReadTypesFiles(pathTest string, baseFilePath string, fileTypes [ // fmt.Printf("Requested path: %s\n", user_path) found := false - index := -1; + index := -1 for i, fileType := range fileTypes { if strings.HasSuffix(user_path, fileType) { found = true - index = i; + index = i break } } @@ -637,5 +637,11 @@ func NewHandler(db *sql.DB) *Handle { func (x Handle) Startup() { fmt.Printf("Starting up!\n") - log.Fatal(http.ListenAndServe(":8000", nil)) + + port := os.Getenv("PORT") + if port == "" { + port = "8000" + } + + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) } diff --git a/views/models/edit.html b/views/models/edit.html index aacc485..59a25b6 100644 --- a/views/models/edit.html +++ b/views/models/edit.html @@ -437,6 +437,9 @@
+ Done Progress + | Training Round Progress | @@ -451,6 +454,9 @@||
---|---|---|---|
+ {{.Epoch}} + | {{.EpochProgress}}/20 | @@ -471,6 +477,49 @@ {{ end }}||
+ + | +