changeset 1951:060d61913e39 deep-learning

deep learning in steps
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Aug 2022 21:49:37 +0200
parents 6ffd65cfd2ee
children a1e0aae9c17f
files Applications/StoneWebViewer/WebApplication/app.js Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp
diffstat 2 files changed, 45 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebApplication/app.js	Fri Aug 12 15:48:35 2022 +0200
+++ b/Applications/StoneWebViewer/WebApplication/app.js	Fri Aug 12 21:49:37 2022 +0200
@@ -1372,6 +1372,11 @@
   stone.LoadDeepLearningModel('model.message');
 });
 
-window.addEventListener('DeepLearningReady', function() {
+window.addEventListener('DeepLearningModelReady', function() {
   app.deepLearningReady = true;
+  app.deepLearningProgress = 0;
 });
+
+window.addEventListener('DeepLearningStep', function(args) {
+  app.deepLearningProgress = args.detail.progress;
+});
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Fri Aug 12 15:48:35 2022 +0200
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Fri Aug 12 21:49:37 2022 +0200
@@ -3668,6 +3668,8 @@
 #include <emscripten/fetch.h>
 #include "deep-learning/WebAssembly/Worker.pb.h"
 
+static void SendRequestToWebWorker(const OrthancStone::Messages::Request& request);
+
 static void DeepLearningCallback(char* data,
                                  int size,
                                  void* payload)
@@ -3683,8 +3685,44 @@
 
       case OrthancStone::Messages::ResponseType::PARSED_MODEL:
         LOG(WARNING) << "Number of steps in the model: " << response.parse_model().number_of_steps();
-        DISPATCH_JAVASCRIPT_EVENT("DeepLearningReady");
+        DISPATCH_JAVASCRIPT_EVENT("DeepLearningModelReady");
+        break;
+
+      case OrthancStone::Messages::ResponseType::LOADED_IMAGE:
+      {
+        OrthancStone::Messages::Request request;
+        request.set_type(OrthancStone::Messages::RequestType::EXECUTE_STEP);
+        SendRequestToWebWorker(request);
         break;
+      }
+
+      case OrthancStone::Messages::ResponseType::STEP_DONE:
+      {
+        EM_ASM({
+            const customEvent = document.createEvent("CustomEvent");
+            customEvent.initCustomEvent("DeepLearningStep", false, false,
+                                        { "progress" : $0 });
+            window.dispatchEvent(customEvent);
+          },
+          response.step().progress()
+          );
+
+        if (response.step().done())
+        {
+          LOG(WARNING) << "SUCCESS! Mask: " << response.step().output().width() << "x"
+                       << response.step().output().height() << " for frame "
+                       << response.step().output().sop_instance_uid() << " / "
+                       << response.step().output().frame_number();
+        }
+        else
+        {
+          OrthancStone::Messages::Request request;
+          request.set_type(OrthancStone::Messages::RequestType::EXECUTE_STEP);
+          SendRequestToWebWorker(request);
+        }
+        
+        break;
+      }
 
       default:
         LOG(ERROR) << "Unsupported response type from the deep learning worker";