Skip to content

Commit 5024d3a

Browse files
committed
update tflite module
1 parent 85194da commit 5024d3a

File tree

1 file changed

+7
-2
lines changed
  • src/viam/examples/modules/tflite

1 file changed

+7
-2
lines changed

src/viam/examples/modules/tflite/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <tensorflow/lite/c/c_api.h>
2525

26+
#include <viam/sdk/common/instance.hpp>
2627
#include <viam/sdk/common/proto_value.hpp>
2728
#include <viam/sdk/components/component.hpp>
2829
#include <viam/sdk/config/resource.hpp>
@@ -723,6 +724,10 @@ class MLModelServiceTFLite : public vsdk::MLModelService,
723724
};
724725

725726
int serve(const std::string& socket_path) try {
727+
// Every Viam C++ SDK program must have one and only one Instance object which is created before
728+
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
729+
vsdk::Instance inst;
730+
726731
// Create a new model registration for the service.
727732
auto module_registration = std::make_shared<vsdk::ModelRegistration>(
728733
// Identify that this resource offers the MLModelService API
@@ -737,10 +742,10 @@ int serve(const std::string& socket_path) try {
737742
});
738743

739744
// Register the newly created registration with the Registry.
740-
vsdk::Registry::register_model(module_registration);
745+
inst.registry()->register_model(module_registration);
741746

742747
// Construct the module service and tell it where to place the socket path.
743-
auto module_service = std::make_shared<vsdk::ModuleService>(socket_path);
748+
auto module_service = std::make_shared<vsdk::ModuleService>(socket_path, inst.registry());
744749

745750
// Add the server as providing the API and model declared in the
746751
// registration.

0 commit comments

Comments
 (0)