From dfa62118de355b5137a30923581a55527b9ad5d3 Mon Sep 17 00:00:00 2001 From: Andre Henriques Date: Thu, 28 Sep 2023 12:16:36 +0100 Subject: [PATCH] chore: #22 Added code to run through --- a.out | Bin 0 -> 9160 bytes logic/models/index.go | 1 + logic/models/run.go | 22 +++++++++++++--------- views/models/edit.html | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100755 a.out diff --git a/a.out b/a.out new file mode 100755 index 0000000000000000000000000000000000000000..bdddb1ff9f98eaa4bcceb1ecd7b54808c7c61dcf GIT binary patch literal 9160 zcmeHN&1w`u5U$;*iOIngOb`?@>cNu}6b)Vs9sEO33En&nv(Cg_*qxD?5y{C{*hk1C z1fL|2kV_yhphwrL?)sA5#lY%CkZPFu>ZiZy?r&>P)nA{#e$j5V2%}9~bmkE`O)TBQ z42eCaOZ;A;Wk#Y4{5VZJwSYVNG2oKUTVNF4Nb{qX^BLe3?-2p9Cqdzz4X37JN8K3| zp6oSR5BX@_c>{P9!UQDcw>kbNJe=>{ag)hD=Uory+Zgn_8-r}~VO*E-ee%Bra zfGJ=Km;$DNDPRhi0;Yf|@INSk-YXEj=Y8#0fB!iy<(voVU(`dNs4u-^8HegG2bZoX zt|(qtTvhzn5PHmu+`o2HTakV|TI-VuIah}kx#8_5!?boz{Kh$PN}j!cyZz?XQ%aI< zT_<&uRt+V2k?|`_o0KT7_l8Z{Wo)W|Jy`vs$*WHke=I)7y|nI8ob44nJz!H&ocEI5 zDjnuNk`DVHrgr=Hj+{p{lluZPaE}4^8*q;yWW!w8f_M3m+5sQ+wXcN-%~5~2X8`{W zbAOD-CHSbv1Lfc3ybR0-KSYV{u_3hxKI-*Q`KV9XqlCam{1L|%CitlT6Xm1cd5Rwz zhD%S_k{H&fjte;)Jb0&XtdGD;Hsrr1dys*;#r=yT9}OCd2|hkQwYJXn5CvzXvCE9I mNAPieiDPY@>R}WG@AhPn?b-8R<=F4|-=aX=32^$J<^KXD6JeeJ literal 0 HcmV?d00001 diff --git a/logic/models/index.go b/logic/models/index.go index fa0258b..ef3e194 100644 --- a/logic/models/index.go +++ b/logic/models/index.go @@ -18,6 +18,7 @@ func HandleModels (handle *Handle) { model_classes.HandleList(handle) // Train endpoints + handleRun(handle) models_train.HandleTrainEndpoints(handle) } diff --git a/logic/models/run.go b/logic/models/run.go index 2694c9f..8ece6af 100644 --- a/logic/models/run.go +++ b/logic/models/run.go @@ -70,19 +70,20 @@ func handleRun(handle *Handle) { } definitions_rows, err := handle.Db.Query("select id from model_definition where model_id=$1;", model.Id) - if !definitions_rows.Next() { - // TODO improve this - return ErrorCode(nil, 400, c.AddMap(nil)) + if err != nil { + return Error500(err) } defer definitions_rows.Close() if !definitions_rows.Next() { - return Error500(nil) + // TODO improve this + fmt.Printf("Could not find definition\n") + return ErrorCode(nil, 400, c.AddMap(nil)) } var def_id string if err = definitions_rows.Scan(&def_id); err != nil { - return Error500(nil) + return Error500(err) } // TODO create a database table with tasks @@ -97,18 +98,21 @@ func handleRun(handle *Handle) { img_file.Write(file) root := tg.NewRoot() - tf_img := image.Read(root, path.Join(run_path, "img.png"), 1) - tf_model := tg.LoadModel(path.Join("savedData", model.Id, "defs", def_id, "model"), []string{"serve"}, nil) + tf_img := image.Read(root, path.Join(run_path, "img.png"), 3) - tf_img_tensor, err := tf.NewTensor(tf_img.Value()) + batch := tg.Batchify(root, []tf.Output{tf_img.Value()}) + exec_results := tg.Exec(root, []tf.Output{batch}, nil, &tf.SessionOptions{}) + inputImage, err:= tf.NewTensor(exec_results[0].Value()) if err != nil { return Error500(err) } + tf_model := tg.LoadModel(path.Join("savedData", model.Id, "defs", def_id, "model"), []string{"serve"}, nil) + results := tf_model.Exec([]tf.Output{ tf_model.Op("StatefulPartitionedCall", 0), }, map[tf.Output]*tf.Tensor{ - tf_model.Op("serving_default_inputs_input", 0): tf_img_tensor, + tf_model.Op("serving_default_rescaling_input", 0): inputImage, }) predictions := results[0] diff --git a/views/models/edit.html b/views/models/edit.html index 0930963..f1eeab8 100644 --- a/views/models/edit.html +++ b/views/models/edit.html @@ -303,7 +303,7 @@ Image File - +