chore: related #20 added runing the model and getting results on the test

This commit is contained in:
2023-09-27 18:07:04 +01:00
parent b2d3b3c677
commit eab788aabd
2 changed files with 78 additions and 4 deletions

View File

@@ -39,6 +39,7 @@ func MakeDefenition(db *sql.DB, model_id string, target_accuracy int) (id string
type ModelDefinitionStatus int
const (
MODEL_DEFINITION_STATUS_FAILED_TRAINING = -3
MODEL_DEFINITION_STATUS_PRE_INIT ModelDefinitionStatus = 1
MODEL_DEFINITION_STATUS_INIT = 2
MODEL_DEFINITION_STATUS_TRAINING = 3
@@ -56,6 +57,41 @@ func MakeLayer(db *sql.DB, def_id string, layer_order int, layer_type int, shape
return
}
func trainModel(handle *Handle, model *BaseModel) {
definitionsRows, err := handle.Db.Query("select id from model_definition where status=$1 and model_id=$2", MODEL_DEFINITION_STATUS_INIT)
if err != nil {
fmt.Printf("Failed to trainModel!Err:\n")
fmt.Println(err)
ModelUpdateStatus(handle, model.Id, FAILED_TRAINING)
return
}
defer definitionsRows.Close()
definitions := []string{}
for definitionsRows.Next() {
var id string
if err = definitionsRows.Scan(&id); err != nil {
fmt.Printf("Failed to trainModel!Err:\n")
fmt.Println(err)
ModelUpdateStatus(handle, model.Id, FAILED_TRAINING)
return
}
definitions = append(definitions, id)
}
if len(definitions) == 0 {
fmt.Printf("Failed to trainModel!Err:\n")
fmt.Println(err)
ModelUpdateStatus(handle, model.Id, FAILED_TRAINING)
return
}
for _, def_id := range definitions {
_ = def_id
}
}
func handleTrain(handle *Handle) {
handle.Post("/models/train", func(w http.ResponseWriter, r *http.Request, c *Context) *Error {
if !CheckAuthLevel(1, w, r, c) {
@@ -151,6 +187,8 @@ func handleTrain(handle *Handle) {
// TODO start training with id fid
go trainModel(handle, model)
ModelUpdateStatus(handle, model.Id, TRAINING)
Redirect("/models/edit?id=" + model.Id, c.Mode, w, r)
return nil