chore: added way to add new images
This commit is contained in:
@@ -102,7 +102,7 @@ func generateCvs(c *Context, run_path string, model_id string) (count int, err e
|
||||
}
|
||||
|
||||
func setModelClassStatus(c *Context, status ModelClassStatus, filter string, args ...any) (err error) {
|
||||
_, err = c.Db.Exec("update model_classes set stauts = $1 where "+filter, args...)
|
||||
_, err = c.Db.Exec(fmt.Sprintf("update model_classes set status=%d where %s", status, filter), args...)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -485,6 +485,7 @@ func (nf ToRemoveList) Less(i, j int) bool {
|
||||
}
|
||||
|
||||
func trainModel(c *Context, model *BaseModel) {
|
||||
|
||||
definitionsRows, err := c.Db.Query("select id, target_accuracy, epoch from model_definition where status=$1 and model_id=$2", MODEL_DEFINITION_STATUS_INIT, model.Id)
|
||||
if err != nil {
|
||||
c.Logger.Error("Failed to train Model! Err:")
|
||||
@@ -783,9 +784,7 @@ func trainModelExp(c *Context, model *BaseModel) {
|
||||
|
||||
if len_def == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if len_def == 1 {
|
||||
} else if len_def == 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -811,44 +810,38 @@ func trainModelExp(c *Context, model *BaseModel) {
|
||||
}
|
||||
}
|
||||
|
||||
rows, err := c.Db.Query("select id from model_definition where model_id=$1 and status=$2 order by accuracy desc limit 1;", model.Id, MODEL_DEFINITION_STATUS_TRANIED)
|
||||
// Set the class status to trained
|
||||
err = setModelClassStatus(c, MODEL_CLASS_STATUS_TRAINED, "model_id=$1 and status=$2;", model.Id, MODEL_CLASS_STATUS_TRAINING)
|
||||
if err != nil {
|
||||
failed("DB: failed to read definition")
|
||||
failed("Failed to set class status")
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var dat JustId
|
||||
|
||||
if !rows.Next() {
|
||||
err = GetDBOnce(c, &dat, "model_definition where model_id=$1 and status=$2 order by accuracy desc limit 1;", model.Id, MODEL_DEFINITION_STATUS_TRANIED)
|
||||
if err == NotFoundError {
|
||||
failed("All definitions failed to train!")
|
||||
return
|
||||
}
|
||||
|
||||
var id string
|
||||
if err = rows.Scan(&id); err != nil {
|
||||
failed("Failed to read id")
|
||||
} else if err != nil {
|
||||
failed("DB: failed to read definition")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if _, err = c.Db.Exec("update model_definition set status=$1 where id=$2;", MODEL_DEFINITION_STATUS_READY, id); err != nil {
|
||||
if _, err = c.Db.Exec("update model_definition set status=$1 where id=$2;", MODEL_DEFINITION_STATUS_READY, dat.Id); err != nil {
|
||||
failed("Failed to update model definition")
|
||||
return
|
||||
}
|
||||
|
||||
to_delete, err := c.Db.Query("select id from model_definition where status != $1 and model_id=$2", MODEL_DEFINITION_STATUS_READY, model.Id)
|
||||
if err != nil {
|
||||
to_delete, err := GetDbMultitple[JustId](c, "model_definition where status!=$1 and model_id=$2", MODEL_DEFINITION_STATUS_READY, model.Id)
|
||||
if err != nil {
|
||||
failed("Failed to select model_definition to delete")
|
||||
return
|
||||
}
|
||||
defer to_delete.Close()
|
||||
}
|
||||
|
||||
for to_delete.Next() {
|
||||
var id string
|
||||
if to_delete.Scan(&id); err != nil {
|
||||
failed("Failed to scan the id of a model_definition to delete")
|
||||
return
|
||||
}
|
||||
os.RemoveAll(path.Join("savedData", model.Id, "defs", id))
|
||||
}
|
||||
for _, d := range(to_delete) {
|
||||
os.RemoveAll(path.Join("savedData", model.Id, "defs", d.Id))
|
||||
}
|
||||
|
||||
// TODO Check if returning also works here
|
||||
if _, err = c.Db.Exec("delete from model_definition where status!=$1 and model_id=$2;", MODEL_DEFINITION_STATUS_READY, model.Id); err != nil {
|
||||
@@ -863,7 +856,6 @@ func trainModelExp(c *Context, model *BaseModel) {
|
||||
|
||||
// There should only be one def availabale
|
||||
def := JustId{}
|
||||
|
||||
if err = GetDBOnce(c, &def, "model_definition where model_id=$1", model.Id); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -1099,7 +1091,7 @@ func generateDefinition(c *Context, model *BaseModel, target_accuracy int, numbe
|
||||
}
|
||||
|
||||
func generateDefinitions(c *Context, model *BaseModel, target_accuracy int, number_of_models int) *Error {
|
||||
cls, err := model_classes.ListClasses(c.Db, model.Id)
|
||||
cls, err := model_classes.ListClasses(c, model.Id)
|
||||
if err != nil {
|
||||
ModelUpdateStatus(c, model.Id, FAILED_PREPARING_TRAINING)
|
||||
// TODO improve this response
|
||||
@@ -1267,7 +1259,7 @@ func generateExpandableDefinition(c *Context, model *BaseModel, target_accuracy
|
||||
|
||||
// TODO make this json friendy
|
||||
func generateExpandableDefinitions(c *Context, model *BaseModel, target_accuracy int, number_of_models int) *Error {
|
||||
cls, err := model_classes.ListClasses(c.Db, model.Id)
|
||||
cls, err := model_classes.ListClasses(c, model.Id)
|
||||
if err != nil {
|
||||
ModelUpdateStatus(c, model.Id, FAILED_PREPARING_TRAINING)
|
||||
// TODO improve this response
|
||||
|
||||
Reference in New Issue
Block a user