changeset 2055:d4e769a0961f deep-learning

automating invokation of protobuf in deep-learning
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Apr 2023 10:53:09 +0200
parents 0d814292a17e
children 66c130af0d3c
files Applications/StoneWebViewer/WebAssembly/CMakeLists.txt Applications/StoneWebViewer/WebAssembly/DeepLearningWorker.proto Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp
diffstat 3 files changed, 80 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebAssembly/CMakeLists.txt	Thu Mar 30 17:20:26 2023 +0200
+++ b/Applications/StoneWebViewer/WebAssembly/CMakeLists.txt	Tue Apr 18 10:53:09 2023 +0200
@@ -24,8 +24,6 @@
 project(OrthancStone)
 include(${CMAKE_SOURCE_DIR}/../Version.cmake)
 
-include(${CMAKE_SOURCE_DIR}/deep-learning/WebAssembly/Protobuf.cmake)  # TODO
-
 set(ORTHANC_STONE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../../../wasm-binaries/StoneWebViewer" CACHE PATH "Where to put the WebAssembly binaries")
 
 
@@ -63,6 +61,8 @@
 SET(ENABLE_LOCALE ON)  # Necessary for text rendering
 SET(ENABLE_PUGIXML ON) # Necessary for OsiriX annotations
 SET(ORTHANC_SANDBOXED ON)
+SET(ENABLE_PROTOBUF ON)           # Necessary for deep learning
+SET(ENABLE_PROTOBUF_COMPILER ON)  # Necessary for deep learning
 
 # this will set up the build system for Stone of Orthanc and will
 # populate the ORTHANC_STONE_SOURCES CMake variable
@@ -120,9 +120,21 @@
   ${STONE_WRAPPER}
   )
 
-add_custom_target(StoneWrapper
+add_custom_command(
+  OUTPUT
+  ${AUTOGENERATED_DIR}/DeepLearningWorker.pb.h
+  ${AUTOGENERATED_DIR}/DeepLearningWorker.pb.cc
+  COMMAND ${PROTOC_EXECUTABLE} --cpp_out=${AUTOGENERATED_DIR} -I${CMAKE_SOURCE_DIR}
+  ${CMAKE_SOURCE_DIR}/DeepLearningWorker.proto
+  DEPENDS
+  ${CMAKE_SOURCE_DIR}/DeepLearningWorker.proto
+  ProtobufCompiler
+  )
+
+add_custom_target(AutogeneratedFiles
   DEPENDS
   ${STONE_WRAPPER}
+  ${AUTOGENERATED_DIR}/DeepLearningWorker.pb.cc
   )  
 
 
@@ -135,9 +147,8 @@
 
 add_executable(StoneWebViewer
   ${ORTHANC_STONE_SOURCES}
-  ${AUTOGENERATED_SOURCES}
-  ${PROTOBUF_SOURCES}  # TODO
-  ${CMAKE_SOURCE_DIR}/Worker.pb.cc  # TODO
+  ${AUTOGENERATED_SOURCES}  # Populated by "EmbedResources()"
+  ${AUTOGENERATED_DIR}/DeepLearningWorker.pb.cc
   StoneWebViewer.cpp
   )
 
@@ -148,7 +159,7 @@
   )
 
 # Make sure to have the wrapper generated
-add_dependencies(StoneWebViewer StoneWrapper)
+add_dependencies(StoneWebViewer AutogeneratedFiles)
 
 
 # Declare installation files for the module
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/StoneWebViewer/WebAssembly/DeepLearningWorker.proto	Tue Apr 18 10:53:09 2023 +0200
@@ -0,0 +1,61 @@
+syntax = "proto2";
+option optimize_for = LITE_RUNTIME;
+
+package OrthancStone.Messages;
+
+enum RequestType {
+  PARSE_MODEL = 1;
+  LOAD_IMAGE = 2;
+  EXECUTE_STEP = 3;
+}
+
+enum ResponseType {
+  INITIALIZED = 1;
+  PARSED_MODEL = 2;
+  LOADED_IMAGE = 3;
+  STEP_DONE = 4;
+}
+
+message ParseModelRequest {
+  required bytes content = 1;
+}
+
+message ParseModelResponse {
+  required uint32 number_of_steps = 1;
+}
+
+message LoadImageRequest {
+  required string sop_instance_uid = 1;
+  required uint32 frame_number = 2;
+  required uint32 height = 3;
+  required uint32 width = 4;
+  repeated float values = 5 [packed=true];
+}
+
+message SegmentationMask {
+  required string sop_instance_uid = 1;
+  required uint32 frame_number = 2;
+  required uint32 height = 3;
+  required uint32 width = 4;
+  repeated bool values = 5 [packed=true];
+}
+
+message StepResponse {
+  required bool done = 1;
+  required float progress = 2;
+  optional SegmentationMask mask = 3;
+}
+
+message Request {
+  required RequestType type = 1;
+
+  optional ParseModelRequest parse_model = 2;
+  optional LoadImageRequest load_image = 3;
+}
+
+message Response {
+  required ResponseType type = 1;
+
+  optional ParseModelResponse parse_model = 2;
+  optional StepResponse step = 3;
+}
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Thu Mar 30 17:20:26 2023 +0200
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Tue Apr 18 10:53:09 2023 +0200
@@ -3927,7 +3927,7 @@
 
 
 #include <emscripten/fetch.h>
-#include "Worker.pb.h"
+#include <DeepLearningWorker.pb.h>
 
 enum DeepLearningState
 {