-
Notifications
You must be signed in to change notification settings - Fork 5
RSDK-13040 Split tflite_mlmodel code into a separate library #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lvhg
wants to merge
37
commits into
main
Choose a base branch
from
RSDK-13040-split-into-seperate-library
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
7578f04
start writing the tests and header
9a7888f
attempt to build cmake
c02a3b9
update cmakelists and conanfile
bfa82d5
add main file
d1ee749
update header file
d7f9c75
planning for tests
c503977
move cmakefiles and cmakecache
df53bad
add to gitignore file
0b32815
remove tests
489b41c
add to cmakelists, remove build documents from git
3664c41
fix library linking, fix imports
ddca157
fix header file problems
ed09b6f
move to header file
55c554f
move class definition to header file
f2379be
fix syntax errors
a61a9ad
move some small methods to cpp
5e99066
move most methods to cpp
42e14ce
fix some of the errors in hpp and cpp files, but still make is not ru…
e1773a1
moved methods from write_to_tflite_tensor_visitor to cpp
6d17ea6
add back metadata function that somehow got removed
4c7f65a
remove alias
34c5374
add constructor to hpp file and remove alias from main. make is worki…
aa27c58
move write_to_tflite_tensor_visitor_ definition to cpp
cf0e95a
remove comments
df89d23
remove macos 13 as it has been retired
72fea80
fix formatting with clang-format
be68410
change executable/library name and remove unnecessary imports
a7a04c2
move write_to_tflite_tensor_visitor class to cpp
7efc8d9
fix write to tflite class errors
8f5a0ca
formatting, removing comments, move service_name to cpp
28668ee
move make_tensor_view methods to cpp file and rename them - does not …
3ce48ee
fix errors related to tensor_views_from_tflite_tensor
2429753
move service_data_type_from_tflite_data_type to cpp file, make MLMode…
29a8770
remove unnecessary imports, namespace changes
bd576dc
change executable/library name, fix binary name, change method name/s…
49e4f9d
put namespace alias back
14756f0
namespace/variable name changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| AllowShortFunctionsOnASingleLine: Empty | ||
| AllowShortIfStatementsOnASingleLine: false | ||
| AllowShortLoopsOnASingleLine: false | ||
| BasedOnStyle: Google | ||
| BinPackArguments: false | ||
| BinPackParameters: false | ||
| ColumnLimit: 100 | ||
| Cpp11BracedListStyle: true | ||
| DerivePointerAlignment: false | ||
| IncludeBlocks: Preserve | ||
| IncludeCategories: | ||
| - Regex: "<.*>" | ||
| Priority: 1 | ||
| SortPriority: 0 | ||
| - Regex: '^(<|"(boost|google|grpc)/)' | ||
| Priority: 3 | ||
| SortPriority: 0 | ||
| - Regex: ".*" | ||
| Priority: 1 | ||
| SortPriority: 0 | ||
| IncludeIsMainRegex: "(Test)?$" | ||
| IncludeIsMainSourceRegex: "" | ||
| IndentWidth: 4 | ||
| MaxEmptyLinesToKeep: 1 | ||
| NamespaceIndentation: None | ||
| SortIncludes: true | ||
| SpaceBeforeAssignmentOperators: true | ||
| Standard: Cpp11 | ||
| UseTab: Never | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,4 +28,5 @@ | |
| *.app | ||
|
|
||
| CMakeUserPresets.json | ||
| build-conan | ||
| build-conan/ | ||
| build/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,16 +38,20 @@ find_package(Threads REQUIRED) | |
| find_package(viam-cpp-sdk REQUIRED) | ||
| find_package(tensorflowlite REQUIRED) | ||
|
|
||
| add_executable(tflite_cpu | ||
| src/tflite_cpu.cpp | ||
| ) | ||
| add_library(tflite_cpu_service src/tflite_cpu.cpp) | ||
|
|
||
| target_link_libraries(tflite_cpu | ||
| PRIVATE Threads::Threads | ||
| PRIVATE viam-cpp-sdk::viamsdk | ||
| target_link_libraries(tflite_cpu_service | ||
acmorrow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| PUBLIC Threads::Threads | ||
| PUBLIC viam-cpp-sdk::viamsdk | ||
| PRIVATE tensorflow::tensorflowlite | ||
| ) | ||
|
|
||
| add_executable(tflite_cpu | ||
| src/main.cpp | ||
| ) | ||
|
|
||
| target_link_libraries(tflite_cpu PRIVATE tflite_cpu_service) | ||
|
|
||
| install( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. What happened to the install target? Was this intentional? If so, why? |
||
| TARGETS tflite_cpu | ||
| ) | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #include <stdexcept> | ||
|
|
||
| #include <viam/sdk/common/instance.hpp> | ||
| #include <viam/sdk/module/service.hpp> | ||
| #include <viam/sdk/registry/registry.hpp> | ||
|
|
||
| #include "tflite_cpu.hpp" | ||
|
|
||
| namespace { | ||
|
|
||
| int serve(const std::string& socket_path) try { | ||
| // Every Viam C++ SDK program must have one and only one Instance object which is created before | ||
| // any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed. | ||
| viam::sdk::Instance inst; | ||
|
|
||
| // Create a new model registration for the service. | ||
| auto module_registration = std::make_shared<viam::sdk::ModelRegistration>( | ||
| // Identify that this resource offers the MLModelService API | ||
| viam::sdk::API::get<viam::sdk::MLModelService>(), | ||
|
|
||
| // Declare a model triple for this service. | ||
| viam::sdk::Model{"viam", "mlmodel-tflite", "tflite_cpu"}, | ||
acmorrow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Define the factory for instances of the resource. | ||
| [](viam::sdk::Dependencies deps, viam::sdk::ResourceConfig config) { | ||
| return std::make_shared<viam::mlmodel_tflite::MLModelServiceTFLite>(std::move(deps), | ||
| std::move(config)); | ||
| }); | ||
|
|
||
| // Register the newly created registration with the Registry. | ||
| viam::sdk::Registry::get().register_model(module_registration); | ||
|
|
||
| // Construct the module service and tell it where to place the socket path. | ||
| auto module_service = std::make_shared<viam::sdk::ModuleService>(socket_path); | ||
|
|
||
| // Add the server as providing the API and model declared in the | ||
| // registration. | ||
| module_service->add_model_from_registry(module_registration->api(), | ||
| module_registration->model()); | ||
|
|
||
| // Start the module service. | ||
| module_service->serve(); | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } catch (const std::exception& ex) { | ||
| std::cout << "ERROR: A std::exception was thrown from `serve`: " << ex.what() << std::endl; | ||
| return EXIT_FAILURE; | ||
| } catch (...) { | ||
| std::cout << "ERROR: An unknown exception was thrown from `serve`" << std::endl; | ||
| return EXIT_FAILURE; | ||
| } | ||
acmorrow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } // namespace | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| const auto usage = std::string("usage: ") + argv[0] + " /path/to/unix/socket"; | ||
|
|
||
| if (argc < 2) { | ||
| std::cout << "ERROR: insufficient arguments\n"; | ||
| std::cout << usage << "\n"; | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| return serve(argv[1]); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.