Code Monkey home page Code Monkey logo

mediapipe-lite's Introduction

Mediapipe-lite

linux-x64-cpu-gcc macos-x64-cpu-clang windows-x64-cpu-msvc

Builds the mediapipe graph module using cmake, conan, and allows conan packaging for various graphing tasks.

Change Log

Quick Start

  1. Build the Docker image

    cd docker 
    docker build -t x86_u20_cpp_gcc9 -f Dockerfile.x86_u20_gcc9 --no-cache .
  2. Start docker

    docker run -v ${PWD}:/mediapipe-lite --name x86_u20_med -it x86_u20_cpp_gcc9:latest -c "cd /mediapipe-lite && bash docker/init_zsh.sh && zsh"
  3. Compile the test

    # conan install dependencies, run only on first build
    conan install . --build=missing -pr:h=docker/x86_gcc_profile
    cd build
    cmake ..
    make -j 4
    # Declare the path to the dynamic library, unset to run source deactivate_conanrun.sh
    source conanrun.sh
    # run unit test
    make test
    # run object detection example 
    # The model in the config file is at https://drive.google.com/file/d/1U9cm5qfOxnGwyB6ypJjYvB6OeOjLZqpC/view?usp=drive_link
    # Download and place in mediapipe/models folder
    # The test image package can be downloaded from https://drive.google.com/file/d/1IjP8aT_iQ8fV_FCuUJk8TH3_e1X2Y_3Q/view?usp=drive_link
    bin/object_detection --calculator_graph_config_file=../examples/desktop/object_detection/object_detection_desktop_live.pbtxt --input_video_path=$IMAGE_DIR --output_video_path=$OUTPUT_DIR
    # run object detection example with all verbose logs
    GLOG_v=5 bin/object_detection --calculator_graph_config_file=../examples/desktop/object_detection/object_detection_desktop_live.pbtxt --input_video_path=$IMAGE_DIR --output_video_path=$OUTPUT_DIR
  4. Project Architecture

    • libgraph depends only on protobuf, abseil and glog, and is 1.7M in size for x86 environments.
    • libframework contains libgraph and other auxiliary projects.
  5. conan package

    conan create . --build=missing -s build_type=Release  -pr:h=docker/x86_gcc_profile  -o 'export_package=True'
  6. Examples of using Graph

    See the tutorial folder for example code.

    // main.cpp
    #include "mediapipe/framework/calculator_graph.h"
    #include "mediapipe/framework/port/logging.h"
    #include "mediapipe/framework/port/parse_text_proto.h"
    #include "mediapipe/framework/port/status.h"
    
    namespace mediapipe {
    
    absl::Status PrintHelloWorld() {
    // Configures a simple graph, which concatenates 2 PassThroughCalculators.
    CalculatorGraphConfig config =
        ParseTextProtoOrDie<CalculatorGraphConfig>(R"pb(
            input_stream: "in"
            output_stream: "out"
            node {
            calculator: "PassThroughCalculator"
            input_stream: "in"
            output_stream: "out1"
            }
            node {
            calculator: "PassThroughCalculator"
            input_stream: "out1"
            output_stream: "out"
            }
        )pb");
    LOG(INFO) << config.DebugString();
    CalculatorGraph graph;
    MP_RETURN_IF_ERROR(graph.Initialize(config)) << "init graph failed";
    ASSIGN_OR_RETURN(OutputStreamPoller poller,
                    graph.AddOutputStreamPoller("out"));
    MP_RETURN_IF_ERROR(graph.StartRun({}));
    // Give 10 input packets that contains the same string "Hello World!".
    for (int i = 0; i < 10; ++i) {
        MP_RETURN_IF_ERROR(graph.AddPacketToInputStream(
            "in", MakePacket<std::string>("Hello World!").At(Timestamp(i))));
    }
    // Close the input stream "in".
    MP_RETURN_IF_ERROR(graph.CloseInputStream("in"));
    mediapipe::Packet packet;
    // Get the output packets string.
    while (poller.Next(&packet)) {
        LOG(INFO) << packet.Get<std::string>();
    }
    return graph.WaitUntilDone();
    }
    }  // namespace mediapipe
    
    int main(int argc, char** argv) {
    google::InitGoogleLogging(argv[0]);
    FLAGS_stderrthreshold=google::INFO;
    FLAGS_colorlogtostderr=true;
    mediapipe::PrintHelloWorld().ok();
    return 0;
    }

CMakeList.txt

add_executable(hello_world hello_world.cc
${PROJECT_SOURCE_DIR}/mediapipe/calculators/core/pass_through_calculator.cc)
target_link_libraries(new_node PUBLIC 
                          -Wl,--whole-archive 
                          stream_handler)
target_link_libraries(hello_world PUBLIC 
                          -Wl,--no-whole-archive 
                        graph)

Note: Since stream_handler, calculator in mediapipe are called dynamically by registering them with a registrar, there are two ways to make sure the registered classes are available in the final executable.

  1. compile the handler, the used calculator into static libraries and force linking of all symbols by passing a parameter to ld, as in the above cmake operation for the stream_handler library
  2. compile the source code of the handler and calculator implementations directly with the target files, as in the test_package example.

Running output

I20230721 17:08:09.523499 140015 hello_world.cc:41] node {
  calculator: "PassThroughCalculator"
  input_stream: "in"
  output_stream: "out1"
}
node {
  calculator: "PassThroughCalculator"
  input_stream: "out1"
  output_stream: "out"
}
input_stream: "in"
output_stream: "out"
I20230721 17:08:09.525810 140015 hello_world.cc:57] Hello World!
I20230721 17:08:09.525838 140015 hello_world.cc:57] Hello World!
I20230721 17:08:09.525846 140015 hello_world.cc:57] Hello World!
I20230721 17:08:09.525852 140015 hello_world.cc:57] Hello World!
I20230721 17:08:09.525859 140015 hello_world.cc:57] Hello World!
I20230721 17:08:09.525866 140015 hello_world.cc:57] Hello World!
I20230721 17:08:09.525872 140015 hello_world.cc:57] Hello World!
I20230721 17:08:09.525879 140015 hello_world.cc:57] Hello World!
I20230721 17:08:09.525885 140015 hello_world.cc:57] Hello World!
I20230721 17:08:09.525892 140015 hello_world.cc:57] Hello World!

TODO List

  • Clean up redundant code step by step
  • Add doc, CI, CD, CT, code formatting checking and other related processes.
  • Improve tutorials and code examples
  • Add pipieline test benchmark.
  • Improve python interface, allow adding python node.

mediapipe-lite's People

Contributors

lzx1413 avatar nreallzx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mediapipe-lite's Issues

Is that possible to compile this repo in Windows?

Hey there,

I am really interested in your project, and I am trying to compile it in Windows 11, not in Ubuntu. When I run 'conan install . --build=missing -pr:h=docker/x86_gcc_profile', it turns out the error: "c++.exe: fatal error: cannot specify '-o' with '-c', '-S' or '-E' with multiple files." "ERROR: gemmlowp/cci.20210928: Error in build() method, line 60 cmake.build() ConanException: Error 2 while executing". What could be the potiential reason for this error? It seems that there is wrong configuration in CMakeList?

I already changed x86_gcc_profile (os=Windows).

Thanks a lot in advance.

image sequence and opencv version?

Hello, I have a few questions. I noticed that the object detection is tested using an image sequence. Why is it used this way? The previous version of opencv was 3.4.12, but later it was updated to 4.5.5. Why is this?
Looking forward to your reply

zstd compiled failed

/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:502:11: error: expected declaration specifiers or ‘...’ before ‘%’ token
502 | movq (%ip##n), %bits##n;
| ^
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:86:5: note: in expansion of macro ‘RELOAD_BITS’
86 | X(3)
| ^
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:525:5: note: in expansion of macro ‘FOR_EACH_STREAM’
525 | FOR_EACH_STREAM(RELOAD_BITS)
| ^~~~~~~~~~~~~~~
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:503:5: error: unknown type name ‘orq’
503 | orq $1, %bits##n;
| ^~~
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:86:5: note: in expansion of macro ‘RELOAD_BITS’
86 | X(3)
| ^
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:525:5: note: in expansion of macro ‘FOR_EACH_STREAM’
525 | FOR_EACH_STREAM(RELOAD_BITS)
| ^~~~~~~~~~~~~~~
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:503:13: error: expected identifier or ‘(’ before ‘%’ token
503 | orq $1, %bits##n;
| ^
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:86:5: note: in expansion of macro ‘RELOAD_BITS’
86 | X(3)
| ^
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:525:5: note: in expansion of macro ‘FOR_EACH_STREAM’
525 | FOR_EACH_STREAM(RELOAD_BITS)
| ^~~~~~~~~~~~~~~
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:504:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘%’ token
504 | shlxq %rax, %bits##n, %bits##n
| ^
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:86:5: note: in expansion of macro ‘RELOAD_BITS’
86 | X(3)
| ^
/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S:525:5: note: in expansion of macro ‘FOR_EACH_STREAM’
525 | FOR_EACH_STREAM(RELOAD_BITS)
| ^~~~~~~~~~~~~~~
lib/CMakeFiles/libzstd_static.dir/build.make:367: recipe for target 'lib/CMakeFiles/libzstd_static.dir/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S.o' failed
make[2]: *** [lib/CMakeFiles/libzstd_static.dir/home/guo/.conan2/p/b/zstd73802e9128a93/b/src/lib/decompress/huf_decompress_amd64.S.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:168: recipe for target 'lib/CMakeFiles/libzstd_static.dir/all' failed
make[1]: *** [lib/CMakeFiles/libzstd_static.dir/all] Error 2
Makefile:148: recipe for target 'all' failed
make: *** [all] Error 2

zstd/1.5.5: ERROR:
Package '8969826c941f6515ea907b027537a12871ec4d58' build failed
zstd/1.5.5: WARN: Build folder /home/guo/.conan2/p/b/zstd73802e9128a93/b/build/Release


Recipe 'zstd/1.5.5' cannot build its binary
It is possible that this recipe is not Conan 2.0 ready
If the recipe comes from ConanCenter check: https://conan.io/cci-v2.html
If it is your recipe, check if it is updated to 2.0


ERROR: zstd/1.5.5: Error in build() method, line 72
cmake.build()
ConanException: Error 2 while executing

ERROR: Error downloading file https://github.com/abseil/abseil-cpp/archive/20230125.1.tar.gz

Hello, when I execute the command “conan install . --build=missing -pr:h=docker/x86_gcc_profile”, the following error appears. It seems to be a network problem, but manual download is ok. Is there any solution to this?

======== Installing packages ========
abseil/20230125.1: WARN: Trying to remove corrupted source folder
abseil/20230125.1: WARN: This can take a while for big packages
abseil/20230125.1: Calling source() in /home/fqy/.conan2/p/absei555651ad2a7c7/s/src
abseil/20230125.1: ERROR: Error downloading file https://github.com/abseil/abseil-cpp/archive/20230125.1.tar.gz: 'HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /abseil/abseil-cpp/archive/20230125.1.tar.gz (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f3d63d76f28>: Failed to establish a new connection: [Errno 111] Connection refused',))'
abseil/20230125.1: Waiting 5 seconds to retry...
abseil/20230125.1: ERROR: Error downloading file https://github.com/abseil/abseil-cpp/archive/20230125.1.tar.gz: 'HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /abseil/abseil-cpp/archive/20230125.1.tar.gz (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f3d5d891ac8>: Failed to establish a new connection: [Errno 111] Connection refused',))'
abseil/20230125.1: Waiting 5 seconds to retry...
ERROR: abseil/20230125.1: Error in source() method, line 81
get(self, **self.conan_data["sources"][self.version], strip_root=True)
ConanException: Error downloading file https://github.com/abseil/abseil-cpp/archive/20230125.1.tar.gz: 'HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /abseil/abseil-cpp/archive/20230125.1.tar.gz (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f3d5d85de48>: Failed to establish a new connection: [Errno 111] Connection refused',))'

Error when installing package gemmlowp

Hi, this error occurred when I executed this command "conan install . --build=missing".
Details of my error is as follows:

-------- Installing package gemmlowp/cci.20210928 (9 of 36) --------
gemmlowp/cci.20210928: Building from source
gemmlowp/cci.20210928: Package gemmlowp/cci.20210928:304a31a3234b5e06f2381a08061a5b62a7197a8c
gemmlowp/cci.20210928: Copying sources to build folder
gemmlowp/cci.20210928: Building your package in C:\Users\yunfeng.kang.conan2\p\b\gemml65ce78f08a802\b
gemmlowp/cci.20210928: Calling generate()
gemmlowp/cci.20210928: Generators folder: C:\Users\yunfeng.kang.conan2\p\b\gemml65ce78f08a802\b\build\Release\generators
gemmlowp/cci.20210928: CMakeToolchain generated: conan_toolchain.cmake
gemmlowp/cci.20210928: CMakeToolchain generated: CMakePresets.json
gemmlowp/cci.20210928: Generating aggregated env files
gemmlowp/cci.20210928: Generated aggregated env files: ['conanbuild.bat', 'conanrun.bat']
gemmlowp/cci.20210928: Calling build()
gemmlowp/cci.20210928: Apply patch (file): patches/build-static-libraries.patch
gemmlowp/cci.20210928: Running CMake.configure()
gemmlowp/cci.20210928: RUN: cmake -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="C:/Users/yunfeng.kang/.conan2/p/b/gemml65ce78f08a802/b/build/Release/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/yunfeng.kang/.conan2/p/b/gemml65ce78f08a802/p" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "C:\Users\yunfeng.kang.conan2\p\b\gemml65ce78f08a802\b\src\contrib"
-- Using Conan toolchain: C:/Users/yunfeng.kang/.conan2/p/b/gemml65ce78f08a802/b/build/Release/generators/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/mingw64_11/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/mingw64_11/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (4.0s)
-- Generating done (0.1s)
CMake Warning:
Manually-specified variables were not used by the project:

CMAKE_SH

-- Build files have been written to: C:/Users/yunfeng.kang/.conan2/p/b/gemml65ce78f08a802/b/build/Release

gemmlowp/cci.20210928: Running CMake.build()
gemmlowp/cci.20210928: RUN: cmake --build "C:\Users\yunfeng.kang.conan2\p\b\gemml65ce78f08a802\b\build\Release" -- -j12
[ 50%] Building CXX object CMakeFiles/eight_bit_int_gemm.dir/C_/Users/yunfeng.kang/.conan2/p/b/gemml65ce78f08a802/b/src/eight_bit_int_gemm/eight_bit_int_gemm.cc.obj
c++.exe: fatal error: cannot specify '-o' with '-c', '-S' or '-E' with multiple files
compilation terminated.
mingw32-make[2]: *** [CMakeFiles\eight_bit_int_gemm.dir\build.make:75: CMakeFiles/eight_bit_int_gemm.dir/C_/Users/yunfeng.kang/.conan2/p/b/gemml65ce78f08a802/b/src/eight_bit_int_gemm/eight_bit_int_gemm.cc.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/eight_bit_int_gemm.dir/all] Error 2
mingw32-make: *** [Makefile:135: all] Error 2

gemmlowp/cci.20210928: ERROR:
Package '304a31a3234b5e06f2381a08061a5b62a7197a8c' build failed
gemmlowp/cci.20210928: WARN: Build folder C:\Users\yunfeng.kang.conan2\p\b\gemml65ce78f08a802\b\build\Release


Recipe 'gemmlowp/cci.20210928' cannot build its binary
It is possible that this recipe is not Conan 2.0 ready
If the recipe comes from ConanCenter check: https://conan.io/cci-v2.html
If it is your recipe, check if it is updated to 2.0


ERROR: gemmlowp/cci.20210928: Error in build() method, line 60
cmake.build()
ConanException: Error 2 while executing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.