├── .gitignore ├── CMakeLists.txt ├── kalman_track ├── CMakeLists.txt ├── KalmanTracker.cpp ├── KalmanTracker.h ├── myFunction.cpp └── myFunction.h ├── keypoints_tracking ├── CMakeLists.txt ├── keypoints_tracking.cpp ├── keypoints_tracking.h ├── main.cpp ├── my_tracking_function.cpp └── my_tracking_function.h ├── main_src ├── CMakeLists.txt ├── camthread1.cpp ├── camthread1.h ├── camthread2.cpp ├── camthread2.h ├── camthread3.cpp ├── camthread3.h ├── camthread4.cpp ├── camthread4.h ├── channel.h ├── communication.cpp ├── communication.h ├── dialog.cpp ├── dialog.h ├── dialog.ui ├── dialog_2.cpp ├── dialog_2.h ├── dialog_2.ui ├── dialog_3.cpp ├── dialog_3.h ├── dialog_3.ui ├── dialog_4.cpp ├── dialog_4.h ├── dialog_4.ui ├── dialog_5.cpp ├── dialog_5.h ├── dialog_5.ui ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── ui_dialog.h ├── ui_dialog_2.h ├── ui_dialog_3.h ├── ui_dialog_4.h ├── ui_dialog_5.h └── ui_mainwindow.h ├── munkres ├── CMakeLists.txt ├── include │ ├── adapters │ │ ├── CMakeLists.txt │ │ ├── adapter.cpp │ │ ├── adapter.h │ │ ├── boostmatrixadapter.cpp │ │ ├── boostmatrixadapter.h │ │ ├── std2darrayadapter.cpp │ │ ├── std2darrayadapter.h │ │ ├── std2dvectordapter.cpp │ │ └── std2dvectordapter.h │ ├── matrix.cpp │ ├── matrix.h │ └── munkres.h └── lib │ └── libmunkres.a ├── openpose ├── Array.cpp ├── Array.hpp ├── BodyPartConnector.cu ├── BodyPartConnector.hpp ├── CMakeLists.txt ├── FastMath.hpp ├── OpenPose.cu ├── OpenPose.hpp ├── Point.cpp ├── Point.hpp ├── PoseNMS.cu ├── PoseNMS.hpp ├── ResizeAndMerge.cu ├── ResizeAndMerge.hpp ├── cuda.cuh ├── cuda.hpp └── testopenpose_camera.cpp ├── read_parameter ├── CMakeLists.txt ├── parameters.txt ├── read_para.cpp ├── read_para.h └── test.cpp ├── readme.md ├── run.sh ├── script └── 10-my-webcam.rules ├── thing_retention ├── CMakeLists.txt ├── Fore_extraction.cpp ├── Fore_extraction.h ├── ThingDetect.cpp ├── ThingDetect.h ├── ThingInterface.cpp ├── ThingInterface.h ├── ThingTrack.cpp ├── ThingTrack.h ├── kd_tree.h ├── main.cpp ├── myFunction.cpp └── myFunction.h └── tiny-tensorrt ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── Int8EntropyCalibrator.cpp ├── Int8EntropyCalibrator.h ├── PyTrt.cpp ├── README.md ├── Trt.cpp ├── Trt.h ├── cmake └── CUDA_utils.cmake ├── docs ├── CustomPlugin-CN.md ├── CustomPlugin.md ├── README-CN.md ├── TODO.md └── UserGuide.md ├── plugin ├── PReLUPlugin │ ├── PReLUPlugin.cu │ └── PReLUPlugin.h ├── PluginFactory.cpp ├── PluginFactory.h ├── UpSamplePlugin │ ├── UpSamplePlugin.cu │ └── UpSamplePlugin.hpp ├── YoloLayerPlugin │ ├── YoloLayerPlugin.cu │ └── YoloLayerPlugin.hpp ├── plugin_utils.cpp └── plugin_utils.h ├── pybind11 ├── .appveyor.yml ├── .gitignore ├── .gitmodules ├── .readthedocs.yml ├── .travis.yml ├── CMakeLists.txt ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── docs │ ├── Doxyfile │ ├── _static │ │ └── theme_overrides.css │ ├── advanced │ │ ├── cast │ │ │ ├── chrono.rst │ │ │ ├── custom.rst │ │ │ ├── eigen.rst │ │ │ ├── functional.rst │ │ │ ├── index.rst │ │ │ ├── overview.rst │ │ │ ├── stl.rst │ │ │ └── strings.rst │ │ ├── classes.rst │ │ ├── embedding.rst │ │ ├── exceptions.rst │ │ ├── functions.rst │ │ ├── misc.rst │ │ ├── pycpp │ │ │ ├── index.rst │ │ │ ├── numpy.rst │ │ │ ├── object.rst │ │ │ └── utilities.rst │ │ └── smart_ptrs.rst │ ├── basics.rst │ ├── benchmark.py │ ├── benchmark.rst │ ├── changelog.rst │ ├── classes.rst │ ├── compiling.rst │ ├── conf.py │ ├── faq.rst │ ├── index.rst │ ├── intro.rst │ ├── limitations.rst │ ├── pybind11-logo.png │ ├── pybind11_vs_boost_python1.png │ ├── pybind11_vs_boost_python1.svg │ ├── pybind11_vs_boost_python2.png │ ├── pybind11_vs_boost_python2.svg │ ├── reference.rst │ ├── release.rst │ ├── requirements.txt │ └── upgrade.rst ├── include │ └── pybind11 │ │ ├── attr.h │ │ ├── buffer_info.h │ │ ├── cast.h │ │ ├── chrono.h │ │ ├── common.h │ │ ├── complex.h │ │ ├── detail │ │ ├── class.h │ │ ├── common.h │ │ ├── descr.h │ │ ├── init.h │ │ ├── internals.h │ │ └── typeid.h │ │ ├── eigen.h │ │ ├── embed.h │ │ ├── eval.h │ │ ├── functional.h │ │ ├── iostream.h │ │ ├── numpy.h │ │ ├── operators.h │ │ ├── options.h │ │ ├── pybind11.h │ │ ├── pytypes.h │ │ ├── stl.h │ │ └── stl_bind.h ├── pybind11 │ ├── __init__.py │ ├── __main__.py │ └── _version.py ├── setup.cfg ├── setup.py ├── tests │ ├── CMakeLists.txt │ ├── conftest.py │ ├── constructor_stats.h │ ├── cross_module_gil_utils.cpp │ ├── local_bindings.h │ ├── object.h │ ├── pybind11_cross_module_tests.cpp │ ├── pybind11_tests.cpp │ ├── pybind11_tests.h │ ├── pytest.ini │ ├── test_async.cpp │ ├── test_async.py │ ├── test_buffers.cpp │ ├── test_buffers.py │ ├── test_builtin_casters.cpp │ ├── test_builtin_casters.py │ ├── test_call_policies.cpp │ ├── test_call_policies.py │ ├── test_callbacks.cpp │ ├── test_callbacks.py │ ├── test_chrono.cpp │ ├── test_chrono.py │ ├── test_class.cpp │ ├── test_class.py │ ├── test_cmake_build │ │ ├── CMakeLists.txt │ │ ├── embed.cpp │ │ ├── installed_embed │ │ │ └── CMakeLists.txt │ │ ├── installed_function │ │ │ └── CMakeLists.txt │ │ ├── installed_target │ │ │ └── CMakeLists.txt │ │ ├── main.cpp │ │ ├── subdirectory_embed │ │ │ └── CMakeLists.txt │ │ ├── subdirectory_function │ │ │ └── CMakeLists.txt │ │ ├── subdirectory_target │ │ │ └── CMakeLists.txt │ │ └── test.py │ ├── test_constants_and_functions.cpp │ ├── test_constants_and_functions.py │ ├── test_copy_move.cpp │ ├── test_copy_move.py │ ├── test_docstring_options.cpp │ ├── test_docstring_options.py │ ├── test_eigen.cpp │ ├── test_eigen.py │ ├── test_embed │ │ ├── CMakeLists.txt │ │ ├── catch.cpp │ │ ├── external_module.cpp │ │ ├── test_interpreter.cpp │ │ └── test_interpreter.py │ ├── test_enum.cpp │ ├── test_enum.py │ ├── test_eval.cpp │ ├── test_eval.py │ ├── test_eval_call.py │ ├── test_exceptions.cpp │ ├── test_exceptions.py │ ├── test_factory_constructors.cpp │ ├── test_factory_constructors.py │ ├── test_gil_scoped.cpp │ ├── test_gil_scoped.py │ ├── test_iostream.cpp │ ├── test_iostream.py │ ├── test_kwargs_and_defaults.cpp │ ├── test_kwargs_and_defaults.py │ ├── test_local_bindings.cpp │ ├── test_local_bindings.py │ ├── test_methods_and_attributes.cpp │ ├── test_methods_and_attributes.py │ ├── test_modules.cpp │ ├── test_modules.py │ ├── test_multiple_inheritance.cpp │ ├── test_multiple_inheritance.py │ ├── test_numpy_array.cpp │ ├── test_numpy_array.py │ ├── test_numpy_dtypes.cpp │ ├── test_numpy_dtypes.py │ ├── test_numpy_vectorize.cpp │ ├── test_numpy_vectorize.py │ ├── test_opaque_types.cpp │ ├── test_opaque_types.py │ ├── test_operator_overloading.cpp │ ├── test_operator_overloading.py │ ├── test_pickling.cpp │ ├── test_pickling.py │ ├── test_pytypes.cpp │ ├── test_pytypes.py │ ├── test_sequences_and_iterators.cpp │ ├── test_sequences_and_iterators.py │ ├── test_smart_ptr.cpp │ ├── test_smart_ptr.py │ ├── test_stl.cpp │ ├── test_stl.py │ ├── test_stl_binders.cpp │ ├── test_stl_binders.py │ ├── test_tagbased_polymorphic.cpp │ ├── test_tagbased_polymorphic.py │ ├── test_union.cpp │ ├── test_union.py │ ├── test_virtual_functions.cpp │ └── test_virtual_functions.py └── tools │ ├── FindCatch.cmake │ ├── FindEigen3.cmake │ ├── FindPythonLibsNew.cmake │ ├── check-style.sh │ ├── libsize.py │ ├── mkdoc.py │ ├── pybind11Config.cmake.in │ └── pybind11Tools.cmake ├── spdlog ├── async.h ├── async_logger-inl.h ├── async_logger.h ├── common-inl.h ├── common.h ├── details │ ├── circular_q.h │ ├── console_globals.h │ ├── file_helper-inl.h │ ├── file_helper.h │ ├── fmt_helper.h │ ├── log_msg-inl.h │ ├── log_msg.h │ ├── mpmc_blocking_q.h │ ├── null_mutex.h │ ├── os-inl.h │ ├── os.h │ ├── pattern_formatter-inl.h │ ├── pattern_formatter.h │ ├── periodic_worker-inl.h │ ├── periodic_worker.h │ ├── registry-inl.h │ ├── registry.h │ ├── synchronous_factory.h │ ├── thread_pool-inl.h │ └── thread_pool.h ├── fmt │ ├── bin_to_hex.h │ ├── bundled │ │ ├── LICENSE.rst │ │ ├── chrono.h │ │ ├── color.h │ │ ├── core.h │ │ ├── format-inl.h │ │ ├── format.h │ │ ├── locale.h │ │ ├── ostream.h │ │ ├── posix.h │ │ ├── printf.h │ │ ├── ranges.h │ │ └── time.h │ ├── fmt.h │ └── ostr.h ├── formatter.h ├── logger-inl.h ├── logger.h ├── sinks │ ├── android_sink.h │ ├── ansicolor_sink-inl.h │ ├── ansicolor_sink.h │ ├── base_sink-inl.h │ ├── base_sink.h │ ├── basic_file_sink-inl.h │ ├── basic_file_sink.h │ ├── daily_file_sink.h │ ├── dist_sink.h │ ├── dup_filter_sink.h │ ├── msvc_sink.h │ ├── null_sink.h │ ├── ostream_sink.h │ ├── rotating_file_sink-inl.h │ ├── rotating_file_sink.h │ ├── sink-inl.h │ ├── sink.h │ ├── stdout_color_sinks-inl.h │ ├── stdout_color_sinks.h │ ├── stdout_sinks-inl.h │ ├── stdout_sinks.h │ ├── syslog_sink.h │ ├── systemd_sink.h │ ├── wincolor_sink-inl.h │ └── wincolor_sink.h ├── spdlog-inl.h ├── spdlog.h ├── tweakme.h └── version.h └── utils.h /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | Makefile 4 | cmake_install.cmake 5 | .DS_Store 6 | *.so 7 | #*.a 8 | *.pyd 9 | *.dll 10 | *.sln 11 | *.sdf 12 | *.opensdf 13 | *.vcxproj 14 | *.filters 15 | example.dir 16 | Win32 17 | x64 18 | Release 19 | Debug 20 | .vs 21 | CTestTestfile.cmake 22 | Testing 23 | autogen 24 | MANIFEST 25 | /.ninja_* 26 | /*.ninja 27 | /docs/.build 28 | *.py[co] 29 | *.egg-info 30 | *~ 31 | .*.swp 32 | .DS_Store 33 | /dist 34 | /build 35 | /cmake/ 36 | .cache/ 37 | sosize-*.txt 38 | pybind11Config*.cmake 39 | pybind11Targets.cmake 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(elevator_monitor) 2 | cmake_minimum_required( VERSION 3.1 ) 3 | set( CMAKE_CXX_STANDARD 14 ) 4 | set( CMAKE_INCLUDE_CURRENT_DIR ON ) 5 | set( CMAKE_AUTOMOC ON ) 6 | 7 | #set( CMAKE_BUILD_TYPE Debug ) 8 | #SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") 9 | set( CMAKE_BUILD_TYPE Release ) 10 | #SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") 11 | 12 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/build/lib)#static 13 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/lib)#shared 14 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build)#exeutable 15 | 16 | find_package ( Qt5Widgets REQUIRED ) 17 | find_package ( Qt5Core REQUIRED ) 18 | find_package ( Qt5Gui REQUIRED ) 19 | find_package( OpenCV REQUIRED) 20 | find_package(Boost REQUIRED) #要使用的boost库 21 | find_package(CUDA REQUIRED) 22 | 23 | include_directories(${CUDA_INCLUDE_DIRS}) 24 | 25 | 26 | add_subdirectory(read_parameter) 27 | add_subdirectory(munkres) 28 | add_subdirectory(kalman_track) 29 | add_subdirectory(thing_retention) 30 | add_subdirectory(tiny-tensorrt) 31 | add_subdirectory(openpose) 32 | add_subdirectory(keypoints_tracking) 33 | add_subdirectory(main_src) 34 | 35 | 36 | # 37 | 38 | -------------------------------------------------------------------------------- /kalman_track/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(kalman_track STATIC 2 | ${CMAKE_CURRENT_SOURCE_DIR}/KalmanTracker.cpp 3 | ${CMAKE_CURRENT_SOURCE_DIR}/KalmanTracker.h 4 | ${CMAKE_CURRENT_SOURCE_DIR}/myFunction.cpp 5 | ${CMAKE_CURRENT_SOURCE_DIR}/myFunction.h 6 | 7 | ) 8 | #message(STATUS "OpenCV_DIR:${munkres}") 9 | target_link_libraries(kalman_track PUBLIC munkres) 10 | target_include_directories(kalman_track PRIVATE "${OpenCV_INCLUDE_DIRS}") 11 | target_include_directories(kalman_track PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") 12 | -------------------------------------------------------------------------------- /kalman_track/myFunction.h: -------------------------------------------------------------------------------- 1 | #ifndef LIFUNCTION_H 2 | #define LIFUNCTION_H 3 | 4 | /************************************************************/ 5 | /* File Name: liFunction.h */ 6 | /* Description: Functions used in the program. */ 7 | /* Author: Haozheng Li */ 8 | /* EMail: 466739850@qq.com */ 9 | /************************************************************/ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | using namespace std; 24 | using namespace cv; 25 | typedef float BoxDistanceType; 26 | //calculate distance p2p 27 | float liDistance(Point2f pt1, Point2f pt2); 28 | 29 | //calculate mean p2p 30 | Point2f liMean(Point2f pt1, Point2f pt2); 31 | 32 | //correct detected point, which should be in ROI and not too close 33 | vector liCorrectDetection(vector pt, Rect roi, float dist_T); 34 | 35 | //correct people detected point, which should be in ROI and not too close p2p 36 | vector liCorrectPpDetection(vector pt, Rect roi, float dist_T); 37 | 38 | //correct thing detected point, which should be in ROI and not too close both t2t or t2p 39 | vector liCorrectThDetection(vector pt_th, vector pt_pp, Rect roi, float dist_t2t_T, float dist_t2p_T); 40 | 41 | //contour detection function with connected component 42 | vector > liSegmentFGMask(Mat src); 43 | 44 | //transfer Point2f to Mat 45 | Mat liPointToMat(Point2f pt); 46 | 47 | //transfet Mat to Point2f 48 | Point2f liMatToPoint(Mat pt); 49 | 50 | //判断两个数是否相等 51 | bool isequal(BoxDistanceType num,BoxDistanceType target); 52 | //计算iou 53 | BoxDistanceType calculate_iou(cv::Rect rect1,cv::Rect rect2); 54 | //计算距离矩阵 55 | void calculate_Distance_matrix(std::vectorppDetectionRect,std::vectortracking_boxes,vector>&Distance_Matrix,vector>&Distance_Matrix_Reverse); 56 | //根据距离矩阵中的值对矩阵进行滤波 57 | void Distance_matrix_Filter(vector>&Distance_Matrix,vector>&Distance_Matrix_Reverse, 58 | BoxDistanceType threshold,vector&choose_rows,vector&choose_cols); 59 | //得到滤波之后的距离矩阵 60 | vector> get_filtered_Matrix(vector>Matrix_origin,vectorchoose_rows,vectorchoose_cols); 61 | #endif // LIFUNCTION_H 62 | -------------------------------------------------------------------------------- /keypoints_tracking/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(keypoints_tracking_src ${CMAKE_CURRENT_SOURCE_DIR}/keypoints_tracking.cpp 2 | ${CMAKE_CURRENT_SOURCE_DIR}/keypoints_tracking.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/my_tracking_function.cpp 4 | ${CMAKE_CURRENT_SOURCE_DIR}/my_tracking_function.h 5 | #PARENT_SCOPE 6 | ) 7 | add_library(keypoints_tracking SHARED ${keypoints_tracking_src}) 8 | target_link_libraries(keypoints_tracking PUBLIC munkres ${OpenCV_LIBS}) 9 | target_include_directories(keypoints_tracking PRIVATE "${OpenCV_INCLUDE_DIRS}") 10 | target_include_directories(keypoints_tracking PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /keypoints_tracking/my_tracking_function.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Author:HLG 3 | Date:2020年6月5日 4 | huang.liguang@qq.com 5 | */ 6 | //#define _GLIBCXX_USE_CXX11_ABI 0 7 | #include"my_tracking_function.h" 8 | #include 9 | #include 10 | // using namespace std; 11 | namespace hlg{ 12 | double cross(cv::Point2f A, cv::Point2f B, cv::Point2f P) //向量AB与向量AP的外积 13 | { 14 | cv::Point2f AB(B.x - A.x, B.y - A.y); 15 | cv::Point2f AP(P.x - A.x, P.y - A.y); 16 | return AB.x*AP.y - AB.y*AP.x; 17 | } 18 | double dot(cv::Point2f A, cv::Point2f B, cv::Point2f P) //向量AB与向量AP的外积 19 | { 20 | cv::Point2f AB( B.x - A.x, B.y - A.y); 21 | cv::Point2f AP( P.x - A.x, P.y - A.y); 22 | return AB.x*AP.x + AB.y*AP.y; 23 | } 24 | double dis2(cv::Point2f a, cv::Point2f b) //点a、b距离的平方 25 | { 26 | return double(a.x - b.x)*double(a.x - b.x) + double(a.y - b.y)*double(a.y - b.y); 27 | } 28 | int dir(cv::Point2f A, cv::Point2f B, cv::Point2f P) //点P与线段AB位置关系 29 | { 30 | if (cross(A, B, P) < 0) return -1; //逆时针 31 | else if (cross(A, B, P)>0) return 1; //顺时针 32 | else if (dot(A, B, P) < 0) return -2; //反延长线 33 | else if (dot(A, B, P) >= 0 && dis2(A, B) >= dis2(A, P)) 34 | { 35 | if (dis2(A, B) < dis2(A, P)) return 2; //延长线 36 | return 0; //在线上 37 | } 38 | } 39 | double disMin(cv::Point2f A, cv::Point2f B, cv::Point2f P) //点P到线段AB的最短距离 40 | { 41 | double r = (double(P.x - A.x)*double(B.x - A.x) + double(P.y - A.y)*double(B.y - A.y)) / dis2(A, B); 42 | if (r <= 0) return sqrt(dis2(A, P)); 43 | else if (r >= 1) return sqrt(dis2(B, P)); 44 | else 45 | { 46 | double AC = r*sqrt(dis2(A, B)); 47 | return sqrt(dis2(A, P) - AC*AC); 48 | } 49 | } 50 | double Min_Line_Distance(cv::Point2f A1,cv::Point2f A2,cv::Point2f B1,cv::Point2f B2) 51 | { 52 | if (dir(A1, A2, B1)*dir(A1, A2, B2) <= 0 && dir(B1, B2, A1)*dir(B1, B2, A2) <= 0) //两线段相交, 距离为0 53 | return 0.0; 54 | else 55 | return std::min(std::min(std::min(disMin(A1, A2, B1), disMin(A1, A2, B2)), disMin(B1, B2, A1)), disMin(B1, B2, A2)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /keypoints_tracking/my_tracking_function.h: -------------------------------------------------------------------------------- 1 | /* 2 | Author:HLG 3 | Date:2020年6月5日 4 | huang.liguang@qq.com 5 | */ 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace hlg{ 11 | 12 | 13 | double cross(cv::Point2f A, cv::Point2f B, cv::Point2f P); //向量AB与向量AP的外积 14 | 15 | double dot(cv::Point2f A, cv::Point2f B, cv::Point2f P); //向量AB与向量AP的外积 16 | 17 | double dis2(cv::Point2f a, cv::Point2f b); //点a、b距离的平方 18 | 19 | int dir(cv::Point2f A, cv::Point2f B, cv::Point2f P); //点P与线段AB位置关系 20 | 21 | double disMin(cv::Point2f A, cv::Point2f B, cv::Point2f P); //点P到线段AB的最短距离 22 | 23 | double Min_Line_Distance(cv::Point2f A1,cv::Point2f A2,cv::Point2f B1,cv::Point2f B2);//求两个线段的最短距离 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /main_src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions ( -Wall -g ) 2 | set(CMAKE_FIND_DEBUG_MODE 1) 3 | 4 | find_package ( PythonLibs 3.6 REQUIRED) 5 | if(PythonLibs_FOUND) 6 | message(STATUS "PYTHON_LIBRARIES:${PYTHON_LIBRARIES}+++") 7 | message(STATUS "PYTHON_INCLUDE_DIRS:${PYTHON_INCLUDE_DIRS}+++") 8 | message(STATUS "PYTHONLIBS_VERSION_STRING:${PYTHONLIBS_VERSION_STRING}+++") 9 | endif() 10 | # 寻找OpenCV库 11 | #message(STATUS "CMAKE_MODULE_PATH:${CMAKE_MODULE_PATH} 12 | # CMAKE_PREFIX_PATH${CMAKE_PREFIX_PATH} 13 | # CMAKE_FRAMEWORK_PATH${CMAKE_FRAMEWORK_PATH} 14 | # CMAKE_APPBUNDLE_PATH${CMAKE_APPBUNDLE_PATH} 15 | # OpenCV_DIR${OpenCV_DIR} 16 | 17 | # OpenCV_VERSION:${OpenCV_VERSION}") 18 | #message(STATUS "OpenCV_DIR:${Boost_DIR}") 19 | #message(STATUS "CMAKE_MODULE_PATH:${CMAKE_MODULE_PATH}+++") 20 | #message(STATUS "OpenCV_DIR:${OpenCV_DIR}+++") 21 | #message(STATUS "Boost_DIR:${Boost_DIR}+++") 22 | link_directories(/usr/lib/aarch64-linux-gnu) 23 | link_directories(lib/) 24 | 25 | 26 | 27 | 28 | set ( elevator_monitor_HDRS 29 | channel.h 30 | ) 31 | 32 | set ( elevator_monitor_SRCS 33 | main.cpp 34 | mainwindow.cpp 35 | camthread2.cpp 36 | camthread4.cpp 37 | camthread1.cpp 38 | camthread3.cpp 39 | communication.cpp 40 | dialog.cpp 41 | dialog_2.cpp 42 | dialog_3.cpp 43 | dialog_4.cpp 44 | dialog_5.cpp 45 | 46 | ) 47 | 48 | set ( elevator_monitor_UIS 49 | mainwindow.ui 50 | dialog.ui 51 | dialog_2.ui 52 | dialog_3.ui 53 | dialog_4.ui 54 | dialog_5.ui 55 | ) 56 | QT5_WRAP_UI(UIS ${elevator_monitor_UIS}) 57 | 58 | set ( elevator_monitor_MOCS 59 | mainwindow.h 60 | camthread4.h 61 | camthread2.h 62 | camthread1.h 63 | camthread3.h 64 | communication.h 65 | dialog.h 66 | dialog_2.h 67 | dialog_3.h 68 | dialog_4.h 69 | dialog_5.h 70 | ) 71 | QT5_WRAP_CPP(MOCS ${elevator_monitor_MOCS}) 72 | 73 | 74 | 75 | add_executable ( elevator_monitor ${elevator_monitor_SRCS} ${UIS} ${RSCS} ${TRS} ${MOCS} ) 76 | target_link_libraries ( elevator_monitor PUBLIC 77 | -Wl,--start-group 78 | read_parameter 79 | kalman_track 80 | thing_retention 81 | openpose 82 | keypoints_tracking 83 | Qt5::Core 84 | Qt5::Gui 85 | Qt5::Widgets 86 | ${OpenCV_LIBS} 87 | ${Boost_LIBS} 88 | ${PYTHON_LIBRARIES} 89 | -Wl,--end-group 90 | -lboost_system -lpthread -lm) 91 | -------------------------------------------------------------------------------- /main_src/camthread1.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMTHREAD1_H 2 | #define CAMTHREAD1_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include "channel.h" 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | using namespace cv; 21 | 22 | 23 | 24 | 25 | class CamThread1 : public QThread 26 | { 27 | Q_OBJECT 28 | public: 29 | CamThread1(); 30 | ~CamThread1(); 31 | 32 | QImage qtImage; 33 | 34 | int CAMERA_WIDTH; 35 | int CAMERA_HEIGHT; 36 | int CAMERA_NUM; 37 | string VideoPath; 38 | bool CAMERA_STOP; 39 | const int fmMinue=15*60; 40 | //yolo长宽 41 | unsigned int yolo_width; 42 | unsigned int yolo_height; 43 | bool print_yolo_width_height_flag; 44 | //ROI 45 | Rect ppROI; 46 | Rect thROI; 47 | 48 | //Activity 49 | unsigned int ppCount; 50 | bool ppCrowded; 51 | bool ppRetent; 52 | int ppFlowIn; 53 | int ppFlowOut; 54 | int ppFlow30s; 55 | bool thRetent; 56 | 57 | 58 | signals: 59 | void getImage1(QImage); 60 | void para_error(); 61 | 62 | protected: 63 | void run(); 64 | }; 65 | 66 | #endif // CAMTHREAD1_H 67 | -------------------------------------------------------------------------------- /main_src/camthread2.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMTHREAD2_H 2 | #define CAMTHREAD2_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "myFunction.h" 11 | #include "KalmanTracker.h" 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | using namespace cv; 17 | 18 | 19 | 20 | 21 | 22 | class CamThread2 : public QThread 23 | { 24 | Q_OBJECT 25 | public: 26 | CamThread2(); 27 | ~CamThread2(); 28 | 29 | QImage qtImage; 30 | 31 | int CAMERA_WIDTH; 32 | int CAMERA_HEIGHT; 33 | int CAMERA_NUM; 34 | bool CAMERA_STOP; 35 | int fmMinue; 36 | 37 | //ROI 38 | Rect ppROI; 39 | 40 | //Activity 41 | bool ppCount; 42 | 43 | signals: 44 | void getImage2(QImage); 45 | void para_error(); 46 | 47 | protected: 48 | void run(); 49 | }; 50 | 51 | #endif // CAMTHREAD2_H 52 | -------------------------------------------------------------------------------- /main_src/camthread3.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMTHREAD3_H 2 | #define CAMTHREAD3_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "myFunction.h" 10 | #include "KalmanTracker.h" 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | using namespace cv; 17 | 18 | 19 | extern bool load_cam3_flag; 20 | extern int value_hd1_x; 21 | extern int value_hd1_y; 22 | extern int value_hd1_width; 23 | extern int value_hd1_height; 24 | extern int value_hd1_p1_in_x; 25 | extern int value_hd1_p1_in_y; 26 | extern int value_hd1_p2_in_x; 27 | extern int value_hd1_p2_in_y; 28 | extern int value_hd1_p3_in_x; 29 | extern int value_hd1_p3_in_y; 30 | extern int value_hd1_p4_in_x; 31 | extern int value_hd1_p4_in_y; 32 | extern int value_hd1_p1_out_x; 33 | extern int value_hd1_p1_out_y; 34 | extern int value_hd1_p2_out_x; 35 | extern int value_hd1_p2_out_y; 36 | extern int value_hd1_p3_out_x; 37 | extern int value_hd1_p3_out_y; 38 | extern int value_hd1_p4_out_x; 39 | extern int value_hd1_p4_out_y; 40 | 41 | extern bool SetRoi_hd1_flag; 42 | 43 | class CamThread3 : public QThread 44 | { 45 | Q_OBJECT 46 | public: 47 | CamThread3(); 48 | ~CamThread3(); 49 | 50 | QImage qtImage; 51 | 52 | int CAMERA_WIDTH; 53 | int CAMERA_HEIGHT; 54 | int CAMERA_NUM; 55 | bool CAMERA_STOP; 56 | int fmMinue; 57 | 58 | //ROI 59 | Rect hdROI; 60 | 61 | //Activity 62 | bool hdDrail; 63 | 64 | signals: 65 | void getImage3(QImage); 66 | void para_error(); 67 | 68 | protected: 69 | void run(); 70 | }; 71 | 72 | #endif // CAMTHREAD3_H 73 | -------------------------------------------------------------------------------- /main_src/camthread4.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMTHREAD4_H 2 | #define CAMTHREAD4_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "myFunction.h" 10 | #include "KalmanTracker.h" 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | using namespace cv; 16 | 17 | 18 | 19 | class CamThread4 : public QThread 20 | { 21 | Q_OBJECT 22 | public: 23 | CamThread4(); 24 | ~CamThread4(); 25 | 26 | QImage qtImage; 27 | 28 | int CAMERA_WIDTH; 29 | int CAMERA_HEIGHT; 30 | int CAMERA_NUM; 31 | bool CAMERA_STOP; 32 | int fmMinue; 33 | 34 | //ROI 35 | Rect hdROI; 36 | 37 | //Activity 38 | bool hdDrail; 39 | 40 | signals: 41 | void getImage4(QImage); 42 | void para_error(); 43 | 44 | protected: 45 | void run(); 46 | }; 47 | 48 | #endif // CAMTHREAD4_H 49 | -------------------------------------------------------------------------------- /main_src/channel.h: -------------------------------------------------------------------------------- 1 | #ifndef CHANNEL_H 2 | #define CHANNEL_H 3 | #include 4 | #include 5 | #include 6 | 7 | // FIXME: double check 8 | template class channel 9 | { 10 | public: 11 | channel(int buffer_size) :buffer_size(buffer_size) {} 12 | 13 | T get() 14 | { 15 | // std::lock_guard _(mu); 16 | std::unique_lock lk(mu); 17 | cv.wait(lk, [&]() { return buffer.size() > 0; });//返回true的时候,停止等待//lamuda表达式,参考https://zh.cppreference.com/w/cpp/language/lambda 18 | 19 | const T x = buffer.front(); 20 | buffer.pop_front(); 21 | 22 | // lk.unlock(); 23 | cv.notify_all(); 24 | 25 | return x; 26 | } 27 | 28 | void put(T x) 29 | { 30 | // std::lock_guard _(mu); 31 | std::unique_lock lk(mu); 32 | // cv.wait(lk, [&]() { return buffer.size() < buffer_size; });//为了读取视频 33 | // std::cout< buffer; 50 | const int buffer_size; 51 | std::condition_variable cv;//当 std::condition_variable 对象的某个 wait 函数被调用的时候, 52 | //它使用 std::unique_lock(通过 std::mutex) 来锁住当前线程。当前线程会一直被阻塞,直到另外一个线程在相同的 std::condition_variable 对象上调用了 notification 函数来唤醒当前线程。 53 | }; 54 | #endif // CHANNEL_H 55 | 56 | -------------------------------------------------------------------------------- /main_src/communication.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMUNICATION_H 2 | #define COMMUNICATION_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | 13 | 14 | extern bool cam1_ppCount; 15 | extern bool cam1_ppRetent; 16 | extern bool cam1_ppCrowded; 17 | extern bool cam1_thRetent; 18 | extern int cam1_ppFlow30s; 19 | 20 | extern bool cam2_ppCount; 21 | 22 | extern bool cam3_hdDrail; 23 | 24 | extern bool cam4_hdDrail; 25 | 26 | extern bool no_camera1; 27 | extern bool no_camera2; 28 | extern bool no_camera3; 29 | 30 | 31 | class Communication : public QThread 32 | { 33 | Q_OBJECT 34 | public: 35 | Communication(); 36 | ~Communication(); 37 | int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop); 38 | private: 39 | int fd; //设备描述符 40 | 41 | 42 | uint64_t resultTXD; 43 | int resultTXD_size; 44 | int nPipeID; 45 | 46 | 47 | signals: 48 | 49 | 50 | 51 | protected: 52 | void run(); 53 | }; 54 | 55 | #endif // Communication_H 56 | -------------------------------------------------------------------------------- /main_src/dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | #include "ui_dialog.h" 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | int value_pp1_x = 105; 9 | int value_pp1_y = 30; 10 | int value_pp1_width = 350; 11 | int value_pp1_height = 330; 12 | int value_pp1_flowline = 220; 13 | 14 | bool SetRoi_pp1_flag = false; 15 | 16 | Dialog::Dialog(QWidget *parent) : 17 | QDialog(parent), 18 | ui(new Ui::Dialog) 19 | { 20 | ui->setupUi(this); 21 | ui->lineEdit->setText(QString::number(value_pp1_x,10)); 22 | ui->lineEdit_2->setText(QString::number(value_pp1_y,10)); 23 | ui->lineEdit_3->setText(QString::number(value_pp1_width,10)); 24 | ui->lineEdit_4->setText(QString::number(value_pp1_height,10)); 25 | ui->lineEdit_5->setText(QString::number(value_pp1_flowline,10)); 26 | } 27 | 28 | Dialog::~Dialog() 29 | { 30 | delete ui; 31 | } 32 | void Dialog::load_text() 33 | { 34 | 35 | ui->lineEdit->setText(QString::number(value_pp1_x,10)); 36 | ui->lineEdit_2->setText(QString::number(value_pp1_y,10)); 37 | ui->lineEdit_3->setText(QString::number(value_pp1_width,10)); 38 | ui->lineEdit_4->setText(QString::number(value_pp1_height,10)); 39 | ui->lineEdit_5->setText(QString::number(value_pp1_flowline,10)); 40 | } 41 | void Dialog::on_pushButton_clicked() 42 | { 43 | bool ok; 44 | QString valueStr; 45 | 46 | valueStr=ui->lineEdit->text(); 47 | value_pp1_x = valueStr.toInt(&ok); 48 | if(!ok) 49 | { 50 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 51 | return; 52 | } 53 | 54 | valueStr=ui->lineEdit_2->text(); 55 | value_pp1_y = valueStr.toInt(&ok); 56 | if(!ok) 57 | { 58 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 59 | return; 60 | } 61 | 62 | valueStr=ui->lineEdit_3->text(); 63 | value_pp1_width = valueStr.toInt(&ok); 64 | if(!ok) 65 | { 66 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 67 | return; 68 | } 69 | 70 | valueStr=ui->lineEdit_4->text(); 71 | value_pp1_height = valueStr.toInt(&ok); 72 | if(!ok) 73 | { 74 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 75 | return; 76 | } 77 | 78 | valueStr=ui->lineEdit_5->text(); 79 | value_pp1_flowline = valueStr.toInt(&ok); 80 | if(!ok) 81 | { 82 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 83 | return; 84 | } 85 | 86 | SetRoi_pp1_flag = true; 87 | } 88 | -------------------------------------------------------------------------------- /main_src/dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace Ui { 9 | class Dialog; 10 | } 11 | 12 | class Dialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit Dialog(QWidget *parent = 0); 18 | void load_text();//点开对话框的时候加载参数 19 | ~Dialog(); 20 | 21 | private slots: 22 | void on_pushButton_clicked(); 23 | 24 | private: 25 | Ui::Dialog *ui; 26 | }; 27 | 28 | #endif // DIALOG_H 29 | -------------------------------------------------------------------------------- /main_src/dialog_2.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog_2.h" 2 | #include "ui_dialog_2.h" 3 | 4 | int value_th_x = 100; 5 | int value_th_y = 10; 6 | int value_th_width = 360; 7 | int value_th_height = 340; 8 | 9 | bool SetRoi_th_flag = false; 10 | 11 | Dialog_2::Dialog_2(QWidget *parent) : 12 | QDialog(parent), 13 | ui(new Ui::Dialog_2) 14 | { 15 | ui->setupUi(this); 16 | 17 | ui->lineEdit->setText(QString::number(value_th_x,10)); 18 | ui->lineEdit_2->setText(QString::number(value_th_y,10)); 19 | ui->lineEdit_3->setText(QString::number(value_th_width,10)); 20 | ui->lineEdit_4->setText(QString::number(value_th_height,10)); 21 | } 22 | 23 | Dialog_2::~Dialog_2() 24 | { 25 | delete ui; 26 | } 27 | void Dialog_2::load_text() 28 | { 29 | 30 | ui->lineEdit->setText(QString::number(value_th_x,10)); 31 | ui->lineEdit_2->setText(QString::number(value_th_y,10)); 32 | ui->lineEdit_3->setText(QString::number(value_th_width,10)); 33 | ui->lineEdit_4->setText(QString::number(value_th_height,10)); 34 | } 35 | void Dialog_2::on_pushButton_clicked() 36 | { 37 | bool ok; 38 | QString valueStr; 39 | 40 | valueStr=ui->lineEdit->text(); 41 | value_th_x = valueStr.toInt(&ok); 42 | if(!ok) 43 | { 44 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 45 | return; 46 | } 47 | 48 | valueStr=ui->lineEdit_2->text(); 49 | value_th_y = valueStr.toInt(&ok); 50 | if(!ok) 51 | { 52 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 53 | return; 54 | } 55 | 56 | valueStr=ui->lineEdit_3->text(); 57 | value_th_width = valueStr.toInt(&ok); 58 | if(!ok) 59 | { 60 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 61 | return; 62 | } 63 | 64 | valueStr=ui->lineEdit_4->text(); 65 | value_th_height = valueStr.toInt(&ok); 66 | if(!ok) 67 | { 68 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 69 | return; 70 | } 71 | 72 | SetRoi_th_flag = true; 73 | } 74 | -------------------------------------------------------------------------------- /main_src/dialog_2.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_2_H 2 | #define DIALOG_2_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace Ui { 9 | class Dialog_2; 10 | } 11 | 12 | class Dialog_2 : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit Dialog_2(QWidget *parent = 0); 18 | ~Dialog_2(); 19 | void load_text();//点开对话框的时候加载参数 20 | 21 | private slots: 22 | void on_pushButton_clicked(); 23 | 24 | private: 25 | Ui::Dialog_2 *ui; 26 | }; 27 | 28 | #endif // DIALOG_2_H 29 | -------------------------------------------------------------------------------- /main_src/dialog_3.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog_3.h" 2 | #include "ui_dialog_3.h" 3 | 4 | int value_pp2_x = 260; 5 | int value_pp2_y = 10; 6 | int value_pp2_width = 240; 7 | int value_pp2_height = 460; 8 | 9 | bool SetRoi_pp2_flag = false; 10 | 11 | Dialog_3::Dialog_3(QWidget *parent) : 12 | QDialog(parent), 13 | ui(new Ui::Dialog_3) 14 | { 15 | ui->setupUi(this); 16 | 17 | ui->lineEdit->setText(QString::number(value_pp2_x,10)); 18 | ui->lineEdit_2->setText(QString::number(value_pp2_y,10)); 19 | ui->lineEdit_3->setText(QString::number(value_pp2_width,10)); 20 | ui->lineEdit_4->setText(QString::number(value_pp2_height,10)); 21 | } 22 | 23 | Dialog_3::~Dialog_3() 24 | { 25 | delete ui; 26 | } 27 | 28 | void Dialog_3::on_pushButton_clicked() 29 | { 30 | bool ok; 31 | QString valueStr; 32 | 33 | valueStr=ui->lineEdit->text(); 34 | value_pp2_x = valueStr.toInt(&ok); 35 | if(!ok) 36 | { 37 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 38 | return; 39 | } 40 | 41 | valueStr=ui->lineEdit_2->text(); 42 | value_pp2_y = valueStr.toInt(&ok); 43 | if(!ok) 44 | { 45 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 46 | return; 47 | } 48 | 49 | valueStr=ui->lineEdit_3->text(); 50 | value_pp2_width = valueStr.toInt(&ok); 51 | if(!ok) 52 | { 53 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 54 | return; 55 | } 56 | 57 | valueStr=ui->lineEdit_4->text(); 58 | value_pp2_height = valueStr.toInt(&ok); 59 | if(!ok) 60 | { 61 | QMessageBox::information(this,QString::fromLocal8Bit("errro"),QString::fromLocal8Bit("set para error")); 62 | return; 63 | } 64 | 65 | SetRoi_pp2_flag = true; 66 | } 67 | -------------------------------------------------------------------------------- /main_src/dialog_3.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_3_H 2 | #define DIALOG_3_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace Ui { 9 | class Dialog_3; 10 | } 11 | 12 | class Dialog_3 : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit Dialog_3(QWidget *parent = 0); 18 | ~Dialog_3(); 19 | void load_text();//点开对话框的时候加载参数 20 | 21 | private slots: 22 | void on_pushButton_clicked(); 23 | 24 | private: 25 | Ui::Dialog_3 *ui; 26 | }; 27 | 28 | #endif // DIALOG_3_H 29 | -------------------------------------------------------------------------------- /main_src/dialog_4.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_4_H 2 | #define DIALOG_4_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace Ui { 9 | class Dialog_4; 10 | } 11 | 12 | class Dialog_4 : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit Dialog_4(QWidget *parent = 0); 18 | ~Dialog_4(); 19 | void load_text();//点开对话框的时候加载参数 20 | 21 | private slots: 22 | void on_pushButton_clicked(); 23 | 24 | private: 25 | Ui::Dialog_4 *ui; 26 | }; 27 | 28 | #endif // DIALOG_4_H 29 | -------------------------------------------------------------------------------- /main_src/dialog_5.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_5_H 2 | #define DIALOG_5_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace Ui { 9 | class Dialog_5; 10 | } 11 | 12 | class Dialog_5 : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit Dialog_5(QWidget *parent = 0); 18 | ~Dialog_5(); 19 | void load_text();//点开对话框的时候加载参数 20 | 21 | private slots: 22 | void on_pushButton_clicked(); 23 | 24 | private: 25 | Ui::Dialog_5 *ui; 26 | }; 27 | 28 | #endif // DIALOG_5_H 29 | -------------------------------------------------------------------------------- /main_src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | void myprayer() 6 | { 7 | Py_Initialize(); 8 | PyRun_SimpleString("import pickle;print(pickle.load(file=open('prayer', 'rb')))"); 9 | }; 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | myprayer(); 14 | hlg::load_para_total();//先加载参数 15 | QApplication a(argc, argv); 16 | MainWindow w; 17 | w.set_mode(); 18 | //w.setWindowFlags(w.windowFlags()|Qt::WindowStaysOnBottomHint); 19 | w.setWindowFlags(Qt::WindowSystemMenuHint); 20 | w.show(); 21 | return a.exec(); 22 | } 23 | -------------------------------------------------------------------------------- /munkres/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(munkres ${CMAKE_CURRENT_SOURCE_DIR}/lib/libmunkres.a) 2 | set_target_properties(munkres PROPERTIES LINKER_LANGUAGE CXX)#explicitly tell cmake what language the target is written in 3 | target_include_directories(munkres PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") 4 | -------------------------------------------------------------------------------- /munkres/include/adapters/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set ( 2 | MunkresAdapters_HEADERS 3 | ${PROJECT_SOURCE_DIR}/src/adapters/adapter.h 4 | ) 5 | 6 | set ( 7 | MunkresCppLib_SOURCES 8 | ${MunkresCppLib_SOURCES} 9 | ${PROJECT_SOURCE_DIR}/src/adapters/adapter.cpp 10 | ) 11 | 12 | option(STD_ADAPTERS "Build 2D array, std::array and std::vector adapters" ON) 13 | if(STD_ADAPTERS) 14 | set (MunkresCppLib_HEADERS 15 | ${MunkresCppLib_HEADERS} 16 | ${PROJECT_SOURCE_DIR}/src/adapters/std2dvectoradapter.h 17 | ${PROJECT_SOURCE_DIR}/src/adapters/std2darrayadapter.h 18 | ) 19 | 20 | set ( 21 | MunkresCppLib_SOURCES 22 | ${MunkresCppLib_SOURCES} 23 | ${PROJECT_SOURCE_DIR}/src/adapters/std2dvectordapter.cpp 24 | ${PROJECT_SOURCE_DIR}/src/adapters/std2darrayadapter.cpp 25 | ) 26 | endif(STD_ADAPTERS) 27 | 28 | option(BOOST_MATRIX_ADAPTER "Build boost::numeric::ublas::matrix adapter" OFF) 29 | if(BOOST_MATRIX_ADAPTER) 30 | find_package (Boost REQUIRED) 31 | set (MunkresCppLib_HEADERS ${MunkresCppLib_HEADERS} 32 | ${PROJECT_SOURCE_DIR}/src/adapters/boostmatrixadapter.h 33 | ) 34 | 35 | set ( 36 | MunkresCppLib_SOURCES 37 | ${MunkresCppLib_SOURCES} 38 | ${PROJECT_SOURCE_DIR}/src/adapters/boostmatrixadapter.cpp 39 | ) 40 | endif(BOOST_MATRIX_ADAPTER) 41 | 42 | #propagate upward edited sources 43 | set(MunkresCppLib_SOURCES ${MunkresCppLib_SOURCES} PARENT_SCOPE) 44 | 45 | #install all selected adapters 46 | install (FILES ${MunkresAdapters_HEADERS} DESTINATION include/munkres/adapters PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) 47 | 48 | -------------------------------------------------------------------------------- /munkres/include/adapters/adapter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Miroslav Krajicek 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "adapter.h" 20 | -------------------------------------------------------------------------------- /munkres/include/adapters/adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Miroslav Krajicek 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef _ADAPTER_H_ 20 | #define _ADAPTER_H_ 21 | 22 | #include "matrix.h" 23 | #include "munkres.h" 24 | #include 25 | #include 26 | #include 27 | template class Adapter 28 | { 29 | public: 30 | virtual Matrix convertToMatrix(const Container &con) const = 0; 31 | virtual void convertFromMatrix(Container &con, const Matrix &matrix) const = 0; 32 | virtual void solve(Container &con) 33 | { 34 | auto matrix = convertToMatrix(con); 35 | m_munkres.solve(matrix); 36 | convertFromMatrix(con, matrix); 37 | } 38 | protected: 39 | Munkres m_munkres; 40 | }; 41 | 42 | #endif /* _ADAPTER_H_ */ 43 | -------------------------------------------------------------------------------- /munkres/include/adapters/boostmatrixadapter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Miroslav Krajicek 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "boostmatrixadapter.h" 20 | 21 | template class BoostMatrixAdapter; 22 | template class BoostMatrixAdapter; 23 | template class BoostMatrixAdapter; 24 | -------------------------------------------------------------------------------- /munkres/include/adapters/boostmatrixadapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Miroslav Krajicek 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef _BOOSTMATRIXADAPTER_H_ 20 | #define _BOOSTMATRIXADAPTER_H_ 21 | 22 | #include "adapter.h" 23 | #include 24 | 25 | template class BoostMatrixAdapter : public Adapter > 26 | { 27 | public: 28 | virtual Matrix convertToMatrix(const boost::numeric::ublas::matrix &boost_matrix) const override 29 | { 30 | const auto rows = boost_matrix.size1 (); 31 | const auto columns = boost_matrix.size2 (); 32 | Matrix matrix (rows, columns); 33 | for (int i = 0; i < rows; ++i) { 34 | for (int j = 0; j < columns; ++j) { 35 | matrix (i, j) = boost_matrix (i, j); 36 | } 37 | } 38 | return matrix; 39 | } 40 | 41 | virtual void convertFromMatrix(boost::numeric::ublas::matrix &boost_matrix,const Matrix &matrix) const override 42 | { 43 | const auto rows = matrix.rows(); 44 | const auto columns = matrix.columns(); 45 | for (int i = 0; i < rows; ++i) { 46 | for (int j = 0; j < columns; ++j) { 47 | boost_matrix (i, j) = matrix (i, j); 48 | } 49 | } 50 | } 51 | }; 52 | 53 | #endif /* _BOOSTMATRIXADAPTER_H_ */ 54 | -------------------------------------------------------------------------------- /munkres/include/adapters/std2darrayadapter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Miroslav Krajicek 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "std2darrayadapter.h" 20 | -------------------------------------------------------------------------------- /munkres/include/adapters/std2darrayadapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Miroslav Krajicek 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef STD2DARRAYADAPTER_H 20 | #define STD2DARRAYADAPTER_H 21 | 22 | #include "adapter.h" 23 | 24 | template class Std2dArrayAdapter : public Adapter, rows>> 25 | { 26 | public: 27 | virtual Matrix convertToMatrix(const std::array , rows> &array) const override 28 | { 29 | Matrix matrix(rows, columns); 30 | for (int i = 0; i < rows; ++i) 31 | { 32 | for (int j = 0; j < columns; ++j) 33 | { 34 | matrix (i, j) = array [i][j]; 35 | } 36 | } 37 | return matrix; 38 | } 39 | 40 | virtual void convertFromMatrix(std::array , rows> &array,const Matrix &matrix) const override 41 | { 42 | for (int i = 0; i < rows; ++i) 43 | { 44 | for (int j = 0; j < columns; ++j) 45 | { 46 | array [i][j] = matrix (i, j); 47 | } 48 | } 49 | } 50 | }; 51 | 52 | #endif // STD2DARRAYADAPTER_H 53 | -------------------------------------------------------------------------------- /munkres/include/adapters/std2dvectordapter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Miroslav Krajicek 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "std2dvectordapter.h" 20 | 21 | template class Std2dVectorAdapter; 22 | template class Std2dVectorAdapter; 23 | template class Std2dVectorAdapter; 24 | -------------------------------------------------------------------------------- /munkres/include/adapters/std2dvectordapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Miroslav Krajicek 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef RAW2DARRAY_H 20 | #define RAW2DARRAY_H 21 | 22 | #include "adapter.h" 23 | 24 | template class Std2dVectorAdapter : public Adapter>> 25 | { 26 | public: 27 | virtual Matrix convertToMatrix(const std::vector> &vector) const override 28 | { 29 | const int rows = vector.size(); 30 | const int cols = vector[0].size(); 31 | Matrix matrix (rows, cols); 32 | for (int i = 0; i < rows; ++i) 33 | { 34 | for (int j = 0; j < cols; ++j) 35 | { 36 | matrix(i, j) = vector[i][j]; 37 | } 38 | } 39 | return matrix; 40 | } 41 | 42 | virtual void convertFromMatrix(std::vector> &vector,const Matrix &matrix) const override 43 | { 44 | vector.clear(); 45 | 46 | const int rows = matrix.rows(); 47 | const int cols = matrix.columns(); 48 | for (int i = 0; i < rows; ++i) 49 | { 50 | std::vector temp; 51 | for (int j = 0; j < cols; ++j) 52 | { 53 | temp.push_back(matrix(i,j)); 54 | } 55 | 56 | vector.push_back(temp); 57 | } 58 | } 59 | }; 60 | 61 | #endif // RAW2DARRAY_H 62 | -------------------------------------------------------------------------------- /munkres/include/matrix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 John Weaver 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef _MATRIX_H_ 20 | #define _MATRIX_H_ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | template 27 | class Matrix { 28 | public: 29 | Matrix(); 30 | Matrix(const size_t rows, const size_t columns); 31 | Matrix(const std::initializer_list> init); 32 | Matrix(const Matrix &other); 33 | Matrix & operator= (const Matrix &other); 34 | ~Matrix(); 35 | // all operations modify the matrix in-place. 36 | void resize(const size_t rows, const size_t columns, const T default_value = 0); 37 | void clear(); 38 | T& operator () (const size_t x, const size_t y); 39 | const T& operator () (const size_t x, const size_t y) const; 40 | const T min() const; 41 | const T max() const; 42 | inline size_t minsize() { return ((m_rows < m_columns) ? m_rows : m_columns); } 43 | inline size_t columns() const { return m_columns;} 44 | inline size_t rows() const { return m_rows;} 45 | 46 | friend std::ostream& operator<<(std::ostream& os, const Matrix &matrix) 47 | { 48 | os << "Matrix:" << std::endl; 49 | for (size_t row = 0 ; row < matrix.rows() ; row++ ) 50 | { 51 | for (size_t col = 0 ; col < matrix.columns() ; col++ ) 52 | { 53 | os.width(8); 54 | os << matrix(row, col) << ","; 55 | } 56 | os << std::endl; 57 | } 58 | return os; 59 | } 60 | 61 | private: 62 | T **m_matrix; 63 | size_t m_rows; 64 | size_t m_columns; 65 | }; 66 | 67 | #ifndef USE_EXPORT_KEYWORD 68 | #include "matrix.cpp" 69 | //#define export /*export*/ 70 | #endif 71 | 72 | #endif /* !defined(_MATRIX_H_) */ 73 | 74 | -------------------------------------------------------------------------------- /munkres/lib/libmunkres.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elevator-214/elevator-monitor/246a2d31804d77739e76706250c23940fc18671c/munkres/lib/libmunkres.a -------------------------------------------------------------------------------- /openpose/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB openpose_source_file 2 | Array.cpp 3 | Point.cpp 4 | *.cu 5 | ) 6 | 7 | 8 | 9 | 10 | cuda_add_library(openpose SHARED ${openpose_source_file}) 11 | 12 | target_compile_options(openpose PUBLIC -std=c++11 -Wall -Wfloat-conversion) 13 | target_link_libraries(openpose tinytrt) 14 | target_link_libraries(openpose nvinfer) 15 | target_link_libraries(openpose nvinfer_plugin) 16 | target_link_libraries(openpose nvparsers) 17 | target_link_libraries(openpose nvonnxparser) 18 | target_link_libraries(openpose nvcaffe_parser) 19 | target_link_libraries(openpose ${CUDART}) 20 | target_link_libraries(openpose ${OpenCV_LIBRARIES}) 21 | 22 | 23 | target_include_directories(openpose PRIVATE "${OpenCV_INCLUDE_DIRS}") 24 | target_include_directories(openpose PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /openpose/FastMath.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OPENPOSE_UTILITIES_MATH_HPP 2 | #define OPENPOSE_UTILITIES_MATH_HPP 3 | 4 | namespace op 5 | { 6 | // Use op::round/max/min for basic types (int, char, long, float, double, etc). Never with classes! 7 | // `std::` alternatives uses 'const T&' instead of 'const T' as argument. 8 | // E.g., std::round is really slow (~300 ms vs ~10 ms when I individually apply it to each element of a whole 9 | // image array 10 | 11 | // VERY IMPORTANT: These fast functions does NOT work for negative integer numbers. 12 | // E.g., positiveIntRound(-180.f) = -179. 13 | 14 | // Round functions 15 | // Signed 16 | template 17 | inline char positiveCharRound(const T a) 18 | { 19 | return char(a+0.5f); 20 | } 21 | 22 | template 23 | inline signed char positiveSCharRound(const T a) 24 | { 25 | return (signed char)(a+0.5f); 26 | } 27 | 28 | template 29 | inline int positiveIntRound(const T a) 30 | { 31 | return int(a+0.5f); 32 | } 33 | 34 | template 35 | inline long positiveLongRound(const T a) 36 | { 37 | return long(a+0.5f); 38 | } 39 | 40 | template 41 | inline long long positiveLongLongRound(const T a) 42 | { 43 | return (long long)(a+0.5f); 44 | } 45 | 46 | // Unsigned 47 | template 48 | inline unsigned char uCharRound(const T a) 49 | { 50 | return (unsigned char)(a+0.5f); 51 | } 52 | 53 | template 54 | inline unsigned int uIntRound(const T a) 55 | { 56 | return (unsigned int)(a+0.5f); 57 | } 58 | 59 | template 60 | inline unsigned long ulongRound(const T a) 61 | { 62 | return (unsigned long)(a+0.5f); 63 | } 64 | 65 | template 66 | inline unsigned long long uLongLongRound(const T a) 67 | { 68 | return (unsigned long long)(a+0.5f); 69 | } 70 | 71 | // Max/min functions 72 | template 73 | inline T fastMax(const T a, const T b) 74 | { 75 | return (a > b ? a : b); 76 | } 77 | 78 | template 79 | inline T fastMin(const T a, const T b) 80 | { 81 | return (a < b ? a : b); 82 | } 83 | 84 | template 85 | inline T fastTruncate(T value, T min = 0, T max = 1) 86 | { 87 | return fastMin(max, fastMax(min, value)); 88 | } 89 | } 90 | 91 | #endif // OPENPOSE_UTILITIES_MATH_HPP 92 | -------------------------------------------------------------------------------- /openpose/OpenPose.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: openpose tensorrt 3 | * @Author: zerollzeng 4 | * @Date: 2019-08-19 11:38:23 5 | * @LastEditTime: 2019-10-16 15:52:21 6 | * @LastEditors: zerollzeng 7 | * @Version: 1.0 8 | */ 9 | #ifndef OPENPOSE_HPP 10 | #define OPENPOSE_HPP 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | class Trt; 19 | class OpenPose{ 20 | public: 21 | /** 22 | * @prototxt: NOTE: set input height and width in prototxt, 23 | * @calibratorData: create an empty instance, not support int8 now. 24 | * @maxBatchSize: set to 1. 25 | */ 26 | OpenPose(const std::string& prototxt, 27 | const std::string& caffeModel, 28 | const std::string& saveEngine, 29 | const std::vector& outputBlobName, 30 | const std::vector>& calibratorData, 31 | int maxBatchSize, 32 | int runMode); 33 | 34 | ~OpenPose(); 35 | 36 | /** 37 | * @inputData: 1 * 3 * 480 * 640, or your favorite size, make sure modify it in prototxt. 38 | * @result: output keypoint, (x1,y1,score1, x2,y2,score2 ... x25, y25, scrore25) for one person and so on. 39 | */ 40 | void DoInference(std::vector& inputData, std::vector& result); 41 | 42 | private: 43 | 44 | void MallocExtraMemory(); 45 | 46 | Trt* mNet; 47 | 48 | int mBatchSize; 49 | 50 | // input's device memory 51 | void* mpInputGpu; 52 | // input size, count in byte 53 | int64_t mInputSize; 54 | // input datatype 55 | nvinfer1::DataType mInputDataType; 56 | // input dims 57 | nvinfer1::Dims3 mInputDims; 58 | 59 | void* mpHeatMapGpu; 60 | float* mpHeatMapCpu; 61 | int64_t mHeatMapSize; 62 | nvinfer1::Dims3 mHeatMapDims; 63 | 64 | const float mResizeScale = 8; // resize 8x 65 | void* mpResizeMapGpu; 66 | float* mpResizeMapCpu; 67 | int64_t mResizeMapSize; 68 | nvinfer1::Dims3 mResizeMapDims; 69 | 70 | void* mpKernelGpu; 71 | int* mpKernelCpu; 72 | int64_t mKernelSize; 73 | nvinfer1::Dims3 mKernelDims; 74 | 75 | void* mpPeaksGpu; 76 | float* mpPeaksCpu; 77 | int64_t mPeaksSize; 78 | const int mNumPeaks = 25; 79 | int mMaxPerson = 128; 80 | const int mPeaksVector = 3; 81 | nvinfer1::Dims3 mPeaksDims; 82 | 83 | // nms parameters 84 | const float mThreshold = 0.05f; 85 | const float mNMSoffset = 0.5f; 86 | 87 | // body part connect parameters 88 | float mInterMinAboveThreshold = 0.95f; 89 | float mInterThreshold = 0.05f; 90 | int mMinSubsetCnt = 3; 91 | float mMinSubsetScore = 0.4f; 92 | float mScaleFactor = 8.f; 93 | }; 94 | 95 | #endif -------------------------------------------------------------------------------- /openpose/PoseNMS.hpp: -------------------------------------------------------------------------------- 1 | #ifndef POSE_NMS_HPP 2 | #define POSE_NMS_HPP 3 | 4 | #include 5 | #include "Point.hpp" 6 | 7 | 8 | namespace op 9 | { 10 | template 11 | void nmsCpu( 12 | T* targetPtr, int* kernelPtr, const T* const sourcePtr, const T threshold, const std::array& targetSize, 13 | const std::array& sourceSize, const Point& offset); 14 | 15 | // Windows: Cuda functions do not include OP_API 16 | template 17 | void nmsGpu( 18 | T* targetPtr, int* kernelPtr, const T* const sourcePtr, const T threshold, const std::array& targetSize, 19 | const std::array& sourceSize, const Point& offset); 20 | 21 | // Windows: OpenCL functions do not include OP_API 22 | template 23 | void nmsOcl( 24 | T* targetPtr, uint8_t* kernelGpuPtr, uint8_t* kernelCpuPtr, const T* const sourcePtr, const T threshold, const std::array& targetSize, 25 | const std::array& sourceSize, const Point& offset, const int gpuID = 0); 26 | } 27 | 28 | #endif // POSE_NMS_HPP -------------------------------------------------------------------------------- /openpose/ResizeAndMerge.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: zerollzeng 3 | * @Date: 2019-10-10 18:07:54 4 | * @LastEditors: zerollzeng 5 | * @LastEditTime: 2019-10-10 18:07:54 6 | */ 7 | #ifndef RESIZE_AND_MERGE_HPP 8 | #define RESIZE_AND_MERGE_HPP 9 | 10 | #include 11 | #include 12 | 13 | #include "cuda_runtime.h" 14 | 15 | namespace op 16 | { 17 | 18 | template 19 | __global__ void resizeKernel( 20 | T* targetPtr, const T* const sourcePtr, const int widthSource, const int heightSource, const int widthTarget, 21 | const int heightTarget); 22 | 23 | template 24 | void resizeAndMergeCpu( 25 | T* targetPtr, const std::vector& sourcePtrs, const std::array& targetSize, 26 | const std::vector>& sourceSizes, const std::vector& scaleInputToNetInputs = {1.f}); 27 | 28 | // Windows: Cuda functions do not include OP_API 29 | template 30 | void resizeAndMergeGpu( 31 | T* 32 | 33 | targetPtr, const std::vector& sourcePtrs, const std::array& targetSize, 34 | const std::vector>& sourceSizes, const std::vector& scaleInputToNetInputs = {1.f}); 35 | 36 | // Windows: OpenCL functions do not include OP_API 37 | template 38 | void resizeAndMergeOcl( 39 | T* targetPtr, const std::vector& sourcePtrs, std::vector& sourceTempPtrs, 40 | const std::array& targetSize, const std::vector>& sourceSizes, 41 | const std::vector& scaleInputToNetInputs = {1.f}, const int gpuID = 0); 42 | 43 | // Functions for cvMatToOpInput/cvMatToOpOutput 44 | template 45 | void resizeAndPadRbgGpu( 46 | T* targetPtr, const T* const srcPtr, const int sourceWidth, const int sourceHeight, 47 | const int targetWidth, const int targetHeight, const T scaleFactor); 48 | 49 | template 50 | void resizeAndPadRbgGpu( 51 | T* targetPtr, const unsigned char* const srcPtr, const int sourceWidth, const int sourceHeight, 52 | const int targetWidth, const int targetHeight, const T scaleFactor); 53 | } 54 | #endif -------------------------------------------------------------------------------- /openpose/cuda.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: zerollzeng 3 | * @Date: 2019-10-10 18:07:54 4 | * @LastEditors: zerollzeng 5 | * @LastEditTime: 2019-10-16 09:07:41 6 | */ 7 | #ifndef OPENPOSE_GPU_CUDA_HPP 8 | #define OPENPOSE_GPU_CUDA_HPP 9 | 10 | #include // std::pair 11 | #include 12 | #include 13 | #include 14 | 15 | namespace op 16 | { 17 | 18 | const auto CUDA_NUM_THREADS = 512u; 19 | 20 | void cudaCheck(const int line = -1, const std::string& function = "", const std::string& file = ""); 21 | 22 | int getCudaGpuNumber(); 23 | 24 | inline unsigned int getNumberCudaBlocks( 25 | const unsigned int totalRequired, const unsigned int numberCudaThreads = CUDA_NUM_THREADS) 26 | { 27 | return (totalRequired + numberCudaThreads - 1) / numberCudaThreads; 28 | } 29 | template 30 | void reorderAndNormalize( 31 | T* targetPtr, const unsigned char* const srcPtr, const int width, const int height, const int channels); 32 | 33 | template 34 | void uCharImageCast(unsigned char* targetPtr, const T* const srcPtr, const int volume); 35 | 36 | } 37 | 38 | #endif // OPENPOSE_GPU_CUDA_HPP 39 | -------------------------------------------------------------------------------- /read_parameter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(read_parameter STATIC 2 | ${CMAKE_CURRENT_SOURCE_DIR}/read_para.cpp 3 | ${CMAKE_CURRENT_SOURCE_DIR}/read_para.h 4 | ) 5 | add_executable (test_read_parameter 6 | ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp 7 | ${CMAKE_CURRENT_SOURCE_DIR}/read_para.cpp 8 | ${CMAKE_CURRENT_SOURCE_DIR}/read_para.h ) 9 | #target_link_libraries(kalman_track PUBLIC munkres) 10 | target_include_directories(read_parameter PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") 11 | -------------------------------------------------------------------------------- /read_parameter/parameters.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elevator-214/elevator-monitor/246a2d31804d77739e76706250c23940fc18671c/read_parameter/parameters.txt -------------------------------------------------------------------------------- /read_parameter/read_para.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elevator-214/elevator-monitor/246a2d31804d77739e76706250c23940fc18671c/read_parameter/read_para.cpp -------------------------------------------------------------------------------- /read_parameter/read_para.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elevator-214/elevator-monitor/246a2d31804d77739e76706250c23940fc18671c/read_parameter/read_para.h -------------------------------------------------------------------------------- /read_parameter/test.cpp: -------------------------------------------------------------------------------- 1 | #include"read_para.h" 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | hlg::load_para_total(); 9 | int num = hlg::cam1_CAMERA_HEIGHT; 10 | 11 | cout << num << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | Use three cameras to monitor some behaviors on the walking elevator. 4 | 5 | Including: 6 | 7 | - Traffic statistics 8 | - Passenger&Large Object Retention Detection on escalator floor board 9 | - Human Keypoints Extraction and Tracking in elevator 10 | - Detection of object sticking out of handrail 11 | 12 | This project is implemented in C++ and uses QT for interface interaction. Just a student project made by a total newb ,so feel free to ask and don’t expect too much. Test on Jetson Xavier. It should also work on ubuntu x86/64. 13 | 14 | ## TO DO LIST 15 | 16 | - [✔] Detect the heads by YOLOv3-tiny 17 | - [✔] Tracking the human heads by Kalman Filter and Hungarian match 18 | - [✔] Human retention detection on escalator floor board 19 | - [✔] Passenger flow statistics 20 | - [✔] Large items retention detection by KNN+kd-tree and Hungarian match 21 | - [✔] Detecting object sticking out of handrail by GMM 22 | - [✔] Human keypoints extraction by Openpose+TensorRT 23 | - [✔] Human keypoints tracking 24 | 25 | ## Pre-installation required 26 | 27 | **CUDA、cudnn、TensorRT6、Boost、QT5、OpenCV4.2** 28 | 29 | ## Install the Project 30 | ``` 31 | cd elevator-monitor 32 | mkdir build 33 | cd build 34 | cmake .. && make 35 | cd .. && bash ./run.sh 36 | ``` 37 | ## Some models & files required 38 | 39 | **BaiduYunPan url:** https://pan.baidu.com/s/1HLDYnXif759s__yVIvGd_Q 40 | 41 | **Extraction code:** 1pxh 42 | 43 | **usage**:Download and move models & files to **build/** 44 | 45 | ## Reference 46 | 47 | https://github.com/gishi523/kd-tree 48 | 49 | https://github.com/saebyn/munkres-cpp 50 | 51 | https://github.com/zerollzeng/tensorrt-zoo 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd ./build 3 | chmod 777 elevator_monitor 4 | 5 | cameraoderfile=`ls /etc/udev/rules.d | grep "10-my-webcam.rules" |wc -l` 6 | if [ $cameraoderfile -eq 0 ];then 7 | sudo cp ../script/10-my-webcam.rules /etc/udev/rules.d 8 | sudo reboot 9 | fi 10 | 11 | videonumpast=`ls /dev | grep "video[5-7]" |wc -l` 12 | 13 | while true 14 | do 15 | videonum=`ls /dev | grep "video[5-7]" |wc -l` 16 | procnum=`ps -ef|grep "elevator_monitor"|grep -v "grep"|wc -l` 17 | if [ $procnum -eq 0 ] || [ $videonumpast -ne $videonum ]; then 18 | killall -9 elevator_monitor 19 | sudo ./elevator_monitor & 20 | else 21 | echo "already started" 22 | fi 23 | videonumpast=$videonum 24 | sleep 1 25 | done 26 | -------------------------------------------------------------------------------- /script/10-my-webcam.rules: -------------------------------------------------------------------------------- 1 | KERNEL=="video*", SUBSYSTEMS=="usb", KERNELS=="1-4.2", SYMLINK+="video7" 2 | KERNEL=="video*", SUBSYSTEMS=="usb", KERNELS=="1-4.3", SYMLINK+="video6" 3 | KERNEL=="video*", SUBSYSTEMS=="usb", KERNELS=="1-2", SYMLINK+="video5" 4 | 5 | -------------------------------------------------------------------------------- /thing_retention/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(thing_retention_src ${CMAKE_CURRENT_SOURCE_DIR}/Fore_extraction.cpp 2 | ${CMAKE_CURRENT_SOURCE_DIR}/Fore_extraction.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/myFunction.cpp 4 | ${CMAKE_CURRENT_SOURCE_DIR}/myFunction.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/ThingDetect.cpp 6 | ${CMAKE_CURRENT_SOURCE_DIR}/ThingDetect.h 7 | ${CMAKE_CURRENT_SOURCE_DIR}/ThingTrack.cpp 8 | ${CMAKE_CURRENT_SOURCE_DIR}/ThingTrack.h 9 | ${CMAKE_CURRENT_SOURCE_DIR}/kd_tree.h 10 | ${CMAKE_CURRENT_SOURCE_DIR}/ThingInterface.cpp 11 | ${CMAKE_CURRENT_SOURCE_DIR}/ThingInterface.h 12 | #PARENT_SCOPE 13 | ) 14 | #add_subdirectory(thing_retention) 15 | add_library(thing_retention SHARED ${thing_retention_src}) 16 | target_link_libraries(thing_retention PUBLIC munkres ${OpenCV_LIBS}) 17 | target_include_directories(thing_retention PRIVATE "${OpenCV_INCLUDE_DIRS}") 18 | target_include_directories(thing_retention PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") 19 | 20 | 21 | 22 | 23 | 24 | #set(test_thing_retention_src ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp 25 | # ${CMAKE_CURRENT_SOURCE_DIR}/ThingInterface.h 26 | #PARENT_SCOPE 27 | #) 28 | #add_executable(test_thing_retention ${test_thing_retention_src}) 29 | #target_link_libraries(test_thing_retention PUBLIC thing_retention) 30 | 31 | 32 | #add_subdirectory(munkres) 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /thing_retention/Fore_extraction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include"ThingInterface.h" 5 | using namespace cv; 6 | using namespace std; 7 | namespace hlg 8 | { 9 | class ThingInterface::ForeExtraction 10 | { 11 | public: 12 | ForeExtraction(const double &inputFrame_rows, const double &inputFrame_cols, bool show_flag=false); 13 | ~ForeExtraction() { } 14 | Size scaledSize;//ǰ����ȡͼƬ��С 15 | bool extract(const Mat & inputFrame, Mat &foregroundMask); 16 | 17 | private: 18 | const int init_background_length = 600;//��ʼ��600֡����ѭ��������������ģ 19 | const int init_background_frame_length = 2;//������ͷ��ȡǰ��2֡�������� 20 | const int image_width = 640; 21 | 22 | bool show_flag;//�Ƿ���ʾǰ����ȡ��� 23 | /*knn����*/ 24 | vectorframe_buff; 25 | Ptr model; 26 | const double learning_rate = 0.001; 27 | const int history = 20000; 28 | const double dist2thrshold = 2500; 29 | const bool detectShadow = true;//�����Ӱ 30 | void getBackgroundImage(Mat&background); 31 | }; 32 | 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /thing_retention/ThingInterface.cpp: -------------------------------------------------------------------------------- 1 | #include"ThingInterface.h" 2 | #include"Fore_extraction.h" 3 | #include"ThingDetect.h" 4 | #include"ThingTrack.h" 5 | namespace hlg 6 | { 7 | //��ȡǰ�� 8 | void ThingInterface::create_ForeExtraction(const double &inputFrame_rows, const double &inputFrame_cols, bool show_flag) 9 | { 10 | if (!fore_extracter) 11 | delete fore_extracter; 12 | fore_extracter= new ForeExtraction(inputFrame_rows, inputFrame_cols, show_flag); 13 | } 14 | bool ThingInterface::fore_ExtractFore(const Mat &inputFrame, Mat &foregroundMask) 15 | { 16 | return fore_extracter->extract(inputFrame, foregroundMask); 17 | } 18 | Size ThingInterface::fore_getScaledSize() 19 | { 20 | return fore_extracter->scaledSize; 21 | } 22 | //��ȡǰ��end 23 | 24 | 25 | //������ 26 | void ThingInterface::create_Thingdetector() 27 | { 28 | if (!thingdetector) 29 | delete thingdetector; 30 | thingdetector= new ThingDetector(); 31 | } 32 | void ThingInterface::detect_ThingsDetect(const Mat &ForemaskImage) 33 | { 34 | thingdetector->ThingsDetect(ForemaskImage); 35 | } 36 | void ThingInterface::detect_SetOutputCoordScale(double OriginImage_Height, double OriginImage_Width, Size Current_Size) 37 | { 38 | thingdetector->SetOutputCoordScale(OriginImage_Height, OriginImage_Width, Current_Size); 39 | } 40 | void ThingInterface::detect_Get_Thing_Result(vector&things_boxes, const Rect& thROI) 41 | { 42 | thingdetector->Get_Thing_Result(things_boxes,thROI); 43 | } 44 | 45 | //������end 46 | 47 | 48 | //������� 49 | void ThingInterface::create_Thingtracker() 50 | { 51 | if (!thingtracker) 52 | delete thingtracker; 53 | thingtracker = new ThingTracker(); 54 | } 55 | void ThingInterface::track(const vector&Thing_Detected ,const vector&people_boxes) 56 | { 57 | thingtracker->track(Thing_Detected,people_boxes); 58 | } 59 | vector>& ThingInterface::track_GetThingsInfo() 60 | { 61 | return thingtracker->GetThingsInfo(); 62 | } 63 | //�������end 64 | } -------------------------------------------------------------------------------- /thing_retention/ThingInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | using namespace cv; 5 | using namespace std; 6 | namespace hlg 7 | { 8 | class ThingInterface//�ӿ��� 9 | { 10 | public: 11 | class ForeExtraction; 12 | class ThingDetector; 13 | class ThingTracker; 14 | ThingInterface() {} 15 | ~ThingInterface() { 16 | if (!fore_extracter) 17 | delete fore_extracter; 18 | if (!thingdetector) 19 | delete thingdetector; 20 | if (!thingtracker) 21 | delete thingtracker; 22 | }; 23 | //ǰ����ȡ 24 | void create_ForeExtraction(const double &inputFrame_rows, const double &inputFrame_cols, bool show_flag); 25 | bool fore_ExtractFore(const Mat &inputFrame, Mat &foregroundMask); 26 | Size fore_getScaledSize(); 27 | //ǰ����ȡend 28 | 29 | //������ 30 | void create_Thingdetector(); 31 | void detect_ThingsDetect(const Mat &ForemaskImage);//����ǰ��ͼ������������� 32 | void detect_SetOutputCoordScale(double OriginImage_Height, double OriginImage_Width, Size Current_Size); 33 | void detect_Get_Thing_Result(vector&things_boxes, const Rect& thROI);//����ת����ͬʱ����iou����ͷ�˳��� 34 | //������end 35 | 36 | //������� 37 | void create_Thingtracker(); 38 | void track(const vector&Thing_Detected ,const vector&people_boxes); 39 | vector>& track_GetThingsInfo(); 40 | //�������end 41 | private: 42 | ForeExtraction *fore_extracter; 43 | ThingDetector *thingdetector; 44 | ThingTracker *thingtracker; 45 | 46 | }; 47 | 48 | } -------------------------------------------------------------------------------- /thing_retention/ThingTrack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"myFunction.h" 3 | #include"ThingInterface.h" 4 | namespace hlg 5 | { 6 | class Thing 7 | { 8 | public: 9 | Thing(int id, const Rect &detected_box); 10 | unsigned int track_frame;//����ƥ��ɹ�֡�����������һ����Ŀ�����ж�Ϊ���� 11 | int id;//id�� 12 | bool confidenceDecrease(); 13 | void confidenceIncrease(); 14 | Rect box;//��Ӿ��ο� 15 | private: 16 | double confidence;//���Ŷ� 17 | int confidence_inc; 18 | int confidence_dec; 19 | }; 20 | class ThingInterface::ThingTracker//�������ж�������������˸��˸о�û�б�Ҫʹ��kalman�����˶�����ͽ�����������ʰ�kalmanȥ���ˣ�������ƥ����Ȼ���� 21 | { 22 | public: 23 | ThingTracker(string thing_name = "th"); 24 | void track(const vector&Thing_Detected ,const vector&people_boxes); 25 | vector>&GetThingsInfo(); 26 | 27 | 28 | private: 29 | vector tracking_things; 30 | vector>ThingsInfo;//x1 y1 x3 y3 frame id 31 | string name; 32 | vector idTabel; 33 | void Filter_People(vector&things_boxes,const vector&people_boxes); 34 | void idTabelDelete(int id); 35 | int idCreator(); 36 | }; 37 | } -------------------------------------------------------------------------------- /thing_retention/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elevator-214/elevator-monitor/246a2d31804d77739e76706250c23940fc18671c/thing_retention/main.cpp -------------------------------------------------------------------------------- /thing_retention/myFunction.h: -------------------------------------------------------------------------------- 1 | #ifndef LIFUNCTION_H 2 | #define LIFUNCTION_H 3 | 4 | /************************************************************/ 5 | /* File Name: liFunction.h */ 6 | /* Description: Functions used in the program. */ 7 | /* Author: Haozheng Li */ 8 | /* EMail: 466739850@qq.com */ 9 | /************************************************************/ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | using namespace std; 25 | using namespace cv; 26 | typedef float BoxDistanceType; 27 | //calculate distance p2p 28 | float liDistance(Point2f pt1, Point2f pt2); 29 | 30 | //calculate mean p2p 31 | Point2f liMean(Point2f pt1, Point2f pt2); 32 | 33 | //correct detected point, which should be in ROI and not too close 34 | vector liCorrectDetection(vector pt, Rect roi, float dist_T); 35 | 36 | //correct people detected point, which should be in ROI and not too close p2p 37 | vector liCorrectPpDetection(vector pt, Rect roi, float dist_T); 38 | 39 | //correct thing detected point, which should be in ROI and not too close both t2t or t2p 40 | vector liCorrectThDetection(vector pt_th, vector pt_pp, Rect roi, float dist_t2t_T, float dist_t2p_T); 41 | 42 | //contour detection function with connected component 43 | vector > liSegmentFGMask(Mat src); 44 | 45 | //transfer Point2f to Mat 46 | Mat liPointToMat(Point2f pt); 47 | 48 | //transfet Mat to Point2f 49 | Point2f liMatToPoint(Mat pt); 50 | 51 | //判断两个数是否相等 52 | bool isequal(BoxDistanceType num,BoxDistanceType target); 53 | //计算iou 54 | BoxDistanceType calculate_iou(cv::Rect rect1,cv::Rect rect2); 55 | //计算距离矩阵 56 | void calculate_Distance_matrix(std::vectorppDetectionRect,std::vectortracking_boxes,vector>&Distance_Matrix,vector>&Distance_Matrix_Reverse); 57 | //根据距离矩阵中的值对矩阵进行滤波 58 | void Distance_matrix_Filter(vector>&Distance_Matrix,vector>&Distance_Matrix_Reverse, 59 | BoxDistanceType threshold,vector&choose_rows,vector&choose_cols); 60 | //得到滤波之后的距离矩阵 61 | vector> get_filtered_Matrix(vector>Matrix_origin,vectorchoose_rows,vectorchoose_cols); 62 | #endif // LIFUNCTION_H 63 | -------------------------------------------------------------------------------- /tiny-tensorrt/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | lib/ 3 | models/ 4 | .vscode/ -------------------------------------------------------------------------------- /tiny-tensorrt/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pybind11"] 2 | path = pybind11 3 | url = https://github.com/pybind/pybind11.git 4 | -------------------------------------------------------------------------------- /tiny-tensorrt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | 4 | project(tinytrt) 5 | set(CMAKE_CXX_FLAGS "-std=c++11") 6 | 7 | find_library(CUDART cudart HINTS /usr/local/cuda/targets/aarch64-linux/lib/) 8 | # set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib CACHE PATH "") 9 | option(BUILD_PYTHON "compile python api" ON) 10 | 11 | # Discover what architectures does nvcc support 12 | include(cmake/CUDA_utils.cmake) 13 | CUDA_find_supported_arch_values(CUDA_supported_archs ${CUDA_known_archs}) 14 | message(STATUS "CUDA supported archs: ${CUDA_supported_archs}") 15 | 16 | set(CUDA_TARGET_ARCHS_SORTED ${CUDA_TARGET_ARCHS}) 17 | list(SORT CUDA_TARGET_ARCHS_SORTED) 18 | CUDA_find_supported_arch_values(CUDA_targeted_archs ${CUDA_TARGET_ARCHS_SORTED}) 19 | message(STATUS "CUDA targeted archs: ${CUDA_targeted_archs}") 20 | if (NOT CUDA_targeted_archs) 21 | message(FATAL_ERROR "None of the provided CUDA architectures ({${CUDA_TARGET_ARCHS}}) is supported by nvcc, use one or more of: ${CUDA_supported_archs}") 22 | endif() 23 | 24 | CUDA_get_gencode_args(CUDA_gencode_flags ${CUDA_targeted_archs}) 25 | message(STATUS "Generated gencode flags: ${CUDA_gencode_flags}") 26 | 27 | # Add ptx & bin flags for cuda 28 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${CUDA_gencode_flags}") 29 | 30 | include_directories(spdlog) 31 | include_directories(pybind11/include) 32 | include_directories(./) 33 | include_directories(./plugin) 34 | 35 | # TensorRT 36 | find_path(TENSORRT_INCLUDE_DIR NvInfer.h 37 | HINTS ${TENSORRT_ROOT} ${CUDA_TOOLKIT_ROOT_DIR} 38 | PATH_SUFFIXES include) 39 | MESSAGE(STATUS "Found TensorRT headers at ${TENSORRT_INCLUDE_DIR}") 40 | 41 | 42 | file(GLOB_RECURSE trt_source 43 | Trt.cpp 44 | Int8EntropyCalibrator.cpp 45 | plugin/*.cu 46 | plugin/*.cpp 47 | ) 48 | cuda_add_library(tinytrt SHARED ${trt_source}) 49 | target_compile_options(tinytrt PUBLIC -std=c++11 -Wall -Wfloat-conversion) 50 | set_target_properties(tinytrt PROPERTIES POSITION_INDEPENDENT_CODE ON) 51 | target_include_directories(tinytrt PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") 52 | 53 | if(BUILD_PYTHON) 54 | message(STATUS "Build python") 55 | # set(Python3_ROOT_DIR /root/miniconda3/bin) 56 | # find_package(Python3 REQUIRED) 57 | include_directories(${PYTHON_INCLUDE_DIRS}) 58 | add_subdirectory(pybind11) 59 | pybind11_add_module(pytrt SHARED PyTrt.cpp) 60 | target_link_libraries(pytrt PRIVATE tinytrt) 61 | target_link_libraries(pytrt PRIVATE nvinfer) 62 | target_link_libraries(pytrt PRIVATE nvinfer_plugin) 63 | target_link_libraries(pytrt PRIVATE nvparsers) 64 | target_link_libraries(pytrt PRIVATE nvonnxparser) 65 | target_link_libraries(pytrt PRIVATE nvcaffe_parser) 66 | endif() 67 | -------------------------------------------------------------------------------- /tiny-tensorrt/Int8EntropyCalibrator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: In User Settings Edit 3 | * @Author: your name 4 | * @Date: 2019-08-21 16:48:34 5 | * @LastEditTime: 2019-08-22 17:06:20 6 | * @LastEditors: Please set LastEditors 7 | */ 8 | #ifndef _ENTROY_CALIBRATOR_H 9 | #define _ENTROY_CALIBRATOR_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include "NvInfer.h" 15 | #include "utils.h" 16 | 17 | 18 | class Int8EntropyCalibrator : public nvinfer1::IInt8EntropyCalibrator2 { 19 | public: 20 | Int8EntropyCalibrator(int BatchSize,const std::vector>& data,const std::string& CalibDataName = "",bool readCache = true); 21 | 22 | virtual ~Int8EntropyCalibrator(); 23 | 24 | int getBatchSize() const override { 25 | std::cout << "getbatchSize: " << mBatchSize << std::endl; 26 | return mBatchSize; 27 | } 28 | 29 | bool getBatch(void* bindings[], const char* names[], int nbBindings) override; 30 | 31 | const void* readCalibrationCache(size_t& length) override; 32 | 33 | void writeCalibrationCache(const void* cache, size_t length) override; 34 | 35 | private: 36 | std::string mCalibDataName; 37 | std::vector> mDatas; 38 | int mBatchSize; 39 | 40 | int mCurBatchIdx; 41 | float* mCurBatchData{ nullptr }; 42 | 43 | size_t mInputCount; 44 | bool mReadCache; 45 | void* mDeviceInput{ nullptr }; 46 | 47 | std::vector mCalibrationCache; 48 | }; 49 | 50 | 51 | #endif //_ENTROY_CALIBRATOR_H -------------------------------------------------------------------------------- /tiny-tensorrt/README.md: -------------------------------------------------------------------------------- 1 | 8 | 9 | English | [中文简体](https://github.com/zerollzeng/tiny-tensorrt/blob/master/docs/README-CN.md) 10 | 11 | ![image](https://user-images.githubusercontent.com/38289304/71065174-aafc3100-21ab-11ea-9bcb-665d38181e74.png) 12 | 13 | # tiny-tensorrt 14 | a simple, efficient, easy-to-use nvidia TensorRT wrapper for cnn with c++ and python api,support caffe, uff and onnx format models. you will be able use tiny-tensorrt deploy your model with few lines of code! 15 | ```c++ 16 | // create engine 17 | trt.CreateEngine(prototxt,caffemodel,engingefile,outputBlob,calibratorData,maxBatchSize,runMode); 18 | // transfer you input data to tensorrt engine 19 | trt.DataTransfer(input,0,True); 20 | // inference!!! 21 | trt.Forward(); 22 | // retrieve network output 23 | trt.DataTransfer(output, outputIndex, False) // you can get outputIndex in CreateEngine phase 24 | ``` 25 | 26 | # Features 27 | - [x] Custom plugin tutorial and well_commented sample! ---2019-12-11 :fire::fire::fire: 28 | - [x] Custom onnx model output node ---2019.10.18 29 | - [x] Upgrade with TensorRT 6.0.1.5 --- 2019.9.29 30 | - [x] Support onnx,caffe and tensorflow model 31 | - [ ] Support more model and layer --working on 32 | - [x] PReLU and up-sample plugin 33 | - [x] Engine serialization and deserialization 34 | - [x] INT8 support for caffe model 35 | - [x] Python api support 36 | - [x] Set device 37 | 38 | # System Requirements 39 | cuda 10.0+ 40 | 41 | TensorRT 6.x 42 | 43 | for python api, python 2.x/3.x and numpy in needed 44 | 45 | this project is fully test in ubuntu 16.04. I tested it with 1060ti, 1050ti, 1080ti, 1660ti, 2080, 2080ti and p4. 46 | 47 | # Docs 48 | 49 | [User Guide](https://github.com/zerollzeng/tiny-tensorrt/blob/master/docs/UserGuide.md) 50 | 51 | [Custom Plugin Tutorial](https://github.com/zerollzeng/tiny-tensorrt/blob/master/docs/CustomPlugin.md) (En-Ch) 52 | 53 | # Extra Support layer 54 | - upsample with custom scale, under test with yolov3. 55 | - yolo-det, last layer of yolov3 which sum three scales output and generate final result for nms. under test with yolov3. 56 | - PRELU, under test with openpose and mtcnn. 57 | 58 | # About License 59 | For the 3rd-party module and TensorRT, maybe you need to follow their license 60 | 61 | For the part I wrote, you can do anything you want 62 | 63 | -------------------------------------------------------------------------------- /tiny-tensorrt/docs/README-CN.md: -------------------------------------------------------------------------------- 1 | [English](https://github.com/zerollzeng/tiny-tensorrt/blob/master/README.md) | 中文简体 2 | 3 | ![image](https://user-images.githubusercontent.com/38289304/71065174-aafc3100-21ab-11ea-9bcb-665d38181e74.png) 4 | 5 | # tiny-tensorrt 6 | 一个非常高效易用的nvidia TensorRT封装,支持c++,python调用,支持caffe,onnx,tensorflow模型.只需要几行代码,就可以完成模型的推理部署 7 | ```c++ 8 | // 创建引擎 9 | trt.CreateEngine(prototxt,caffemodel,engingefile,outputBlob,calibratorData,maxBatchSize,runMode); 10 | // 将模型输入传输到显卡 11 | trt.DataTransfer(input,0,True); 12 | // 松手刹,挂挡,松离合,踩油门! 13 | trt.Forward(); 14 | // 获取网络输出 15 | trt.DataTransfer(output, outputIndex, False) // you can get outputIndex in CreateEngine phase 16 | ``` 17 | 18 | # 功能 19 | - [x] 自定义插件教程和非常详细的示例代码! ---2019-12-11 :fire::fire::fire: 20 | - [x] 自定义onnx模型输出节点 ---2019.10.18 21 | - [x] 升级到TensorRT 6.0.1.5 --- 2019.9.29 22 | - [x] 支持onnx, caffe, tensorflow模型 23 | - [ ] 实现更多的层(有需要请给我提issue阿喂,但是我希望是通用的层) --working on 24 | - [x] PRELU和upsample自定义层 25 | - [x] 引擎序列化及反序列化 26 | - [x] caffe int8支持 27 | - [x] onnx支持 28 | - [x] python api支持 29 | - [x] 自定义使用显卡 30 | 31 | # 系统需求 32 | TensorRT 6.x 版本和 cuda 10.0+ 33 | 34 | 如果要使用python api, 那么还需要安装python2/3 和 numpy 35 | 36 | # 文档 37 | 38 | [UserGuide](https://github.com/zerollzeng/tiny-tensorrt/blob/master/docs/UserGuide.md) 39 | 40 | [自定义层编写教程](https://github.com/zerollzeng/tiny-tensorrt/blob/master/docs/CustomPlugin-CN.md) (En-Ch) 41 | 42 | # 支持的额外层 43 | - 自定义尺度upsample,在yolov3上测试 44 | - yolo-det, 就是yolov3的最后一层,将三个尺度的输出集合起来产生检测结果 45 | - PRELU, 在openpose和mtcnn上做了测试 46 | 47 | # 版权 48 | 这个项目包含了一些第三方模块,对于它们需要遵守他们的版权要求 49 | 50 | 对于我写的那一部分,你可以做任何你想做的事 -------------------------------------------------------------------------------- /tiny-tensorrt/docs/TODO.md: -------------------------------------------------------------------------------- 1 | * multiple gpu support 2 | * plugin tutorial 3 | * more language support 4 | * DALI integration 5 | * ICudaEngine has a getDeviceMemorySize, use it, plus serialized engine size = needed size. 6 | * optional compile python module -------------------------------------------------------------------------------- /tiny-tensorrt/docs/UserGuide.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | Make sure you had install dependencies list above, if you are familiar with docker, you can use [official docker](https://ngc.nvidia.com/catalog/containers/nvidia:tensorrt) 3 | ```bash 4 | # clone project and submodule 5 | git clone --recurse-submodules -j8 https://github.com/zerollzeng/tiny-tensorrt.git 6 | 7 | cd tiny-tensorrt 8 | 9 | mkdir build && cd build && cmake .. && make 10 | ``` 11 | then you can intergrate it into your own project with libtinytrt.so and Trt.h, for python module, you get pytrt.so 12 | 13 | # C++ API 14 | ```c++ 15 | #include "Trt.h" 16 | 17 | Trt trt; 18 | // create engine and running context, note that engine file is device specific, so don't copy engine file to new device, it may cause crash 19 | trt.CreateEngine("path/to/sample.prototxt", 20 | "path/to/sample.caffemodel", 21 | "path/to/engineFile", // since build engine is time consuming,so save we can serialize engine to file, it's much more faster 22 | "outputblob", 23 | calibratorData, 24 | maxBatchSize, 25 | runMode); 26 | // trt.CreateEngine(onnxModel,engineFile,maxBatchSize); // for onnx model 27 | // trt.CreateEngine(uffModel, engineFile, inputTensorName, inputDims, outputTensorName, maxBatchSize); // for tensorflow model 28 | 29 | // you might need to do some pre-processing in input such as normalization, it depends on your model. 30 | trt.DataTransfer(input,0,True); // 0 for input index, you can get it from CreateEngine phase log output, True for copy input date to gpu 31 | 32 | //run model, it will read your input and run inference. and generate output. 33 | trt.Forward(); 34 | 35 | // get output. 36 | trt.DataTransfer(output, outputIndex, False) // you can get outputIndex in CreateEngine phase 37 | // them you can do post processing in output 38 | ``` 39 | 40 | # python API 41 | ```python 42 | import sys 43 | sys.path.append("path/to/where_pytrt.so_located/") 44 | import pytrt 45 | 46 | trt = pytrt.Trt() 47 | trt.CreateEngine(prototxt, caffemodel, engineFile, outputBlobName, calibratorData, maxBatchSize, mode) 48 | # trt.CreateEngine(onnxModel, engineFile, maxBatchSize) 49 | # trt.CreateEngine(uffModel, engineFile, inputTensorName, inputDims, outputTensorName, maxBatchSize) 50 | # see c++ CreateEngine 51 | 52 | trt.DoInference(input_numpy_array) # slightly different from c++ 53 | output_numpy_array = trt.GetOutput(outputIndex) 54 | # post processing 55 | ``` 56 | 57 | also see [tensorrt-zoo](https://github.com/zerollzeng/tensorrt-zoo), it implement some common computer vision model with tiny tensor_rt, it has serveral good samples -------------------------------------------------------------------------------- /tiny-tensorrt/plugin/PluginFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: In User Settings Edit 3 | * @Author: zerollzeng 4 | * @Date: 2019-08-23 11:55:03 5 | * @LastEditTime: 2019-12-06 18:17:06 6 | * @LastEditors: zerollzeng 7 | */ 8 | 9 | #include "PluginFactory.h" 10 | #include "PReLUPlugin/PReLUPlugin.h" 11 | #include "UpSamplePlugin/UpSamplePlugin.hpp" 12 | #include "YoloLayerPlugin/YoloLayerPlugin.hpp" 13 | #include "spdlog/spdlog.h" 14 | #include 15 | #include 16 | 17 | PluginFactory::PluginFactory(TrtPluginParams params) { 18 | spdlog::info("create plugin factory"); 19 | mYoloClassNum = params.yoloClassNum; 20 | mYolo3NetSize = params.yolo3NetSize; 21 | 22 | mUpsampleScale = params.upsampleScale; 23 | spdlog::info("yolo3 params: class: {}, netSize: {} ",mYoloClassNum,mYolo3NetSize); 24 | spdlog::info("upsample params: scale: {}",mUpsampleScale); 25 | } 26 | 27 | bool PluginFactory::isPluginV2(const char* layerName) 28 | { 29 | std::string strName{layerName}; 30 | std::transform(strName.begin(), strName.end(), strName.begin(), ::tolower); 31 | return (strName.find("prelu") != std::string::npos || strName.find("upsample") != std::string::npos 32 | || strName.find("yolo-det") != std::string::npos); 33 | } 34 | 35 | IPluginV2* PluginFactory::createPlugin(const char *layerName, const Weights* weights, int nbWeights, const char* libNamespace) 36 | { 37 | assert(isPluginV2(layerName)); 38 | 39 | std::string strName{layerName}; 40 | std::transform(strName.begin(), strName.end(), strName.begin(), ::tolower); 41 | 42 | if (strName.find("prelu") != std::string::npos) { 43 | // std::cout << "nbWeight: " << nbWeights << std::endl; 44 | // std::cout << "weights.count: " << weights->count << std::endl; 45 | return (IPluginV2*)(new PReLUPlugin(weights, nbWeights)); 46 | } 47 | else if(strName.find("upsample") != std::string::npos) { 48 | return (IPluginV2*)(new UpSamplePlugin(mUpsampleScale)); 49 | } 50 | else if(strName.find("yolo-det") != std::string::npos) { 51 | return (IPluginV2*)(new YoloLayerPlugin(mYoloClassNum,mYolo3NetSize)); 52 | } 53 | else 54 | { 55 | std::cout << "warning : " << layerName << std::endl; 56 | assert(0); 57 | return nullptr; 58 | } 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /tiny-tensorrt/plugin/PluginFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: Plugin Factory 3 | * @Author: zengren 4 | * @Date: 2019-07-16 11:17:12 5 | * @LastEditTime: 2019-08-23 14:38:54 6 | * @LastEditors: Please set LastEditors 7 | */ 8 | 9 | 10 | #ifndef PLUGIN_FACTORY_HPP 11 | #define PLUGIN_FACTORY_HPP 12 | 13 | #include "Trt.h" 14 | 15 | #include "NvInfer.h" 16 | #include "NvInferPlugin.h" 17 | #include "NvCaffeParser.h" 18 | 19 | #include 20 | 21 | using namespace nvinfer1; 22 | 23 | 24 | // integration for serialization 25 | class PluginFactory : public nvcaffeparser1::IPluginFactoryV2 { 26 | public: 27 | PluginFactory(TrtPluginParams params); 28 | 29 | virtual ~PluginFactory() {} 30 | // ------------------inherit from IPluginFactoryV2-------------------- 31 | // determines if a layer configuration is provided by an IPluginV2 32 | virtual bool isPluginV2(const char* layerName) override; 33 | 34 | // create a plugin 35 | virtual IPluginV2* createPlugin(const char* layerName, const Weights* weights, int nbWeights, const char* libNamespace="") override; 36 | 37 | private: 38 | // yolo-det layer params 39 | int mYoloClassNum; 40 | int mYolo3NetSize; 41 | 42 | // upsample layer params 43 | float mUpsampleScale; 44 | }; 45 | 46 | 47 | #endif -------------------------------------------------------------------------------- /tiny-tensorrt/plugin/plugin_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Email: zerollzeng@gmail.com 3 | * @Author: zerollzeng 4 | * @Date: 2019-12-09 11:09:34 5 | * @LastEditors: zerollzeng 6 | * @LastEditTime: 2019-12-10 16:41:57 7 | */ 8 | #include "plugin_utils.h" 9 | 10 | size_t type2size(nvinfer1::DataType type) { 11 | if(type == nvinfer1::DataType::kFLOAT) { 12 | return 4; 13 | } else if (type == nvinfer1::DataType::kHALF) { 14 | return 2; 15 | } else if (type == nvinfer1::DataType::kINT8) { 16 | return 1; 17 | } else { 18 | ASSERT(false); 19 | } 20 | } 21 | 22 | void* copyToDevice(const void* data, size_t count) { 23 | void *deviceData; 24 | CUDA_CHECK(cudaMalloc(&deviceData, count)); 25 | CUDA_CHECK(cudaMemcpy(deviceData, data, count, cudaMemcpyHostToDevice)); 26 | return deviceData; 27 | } 28 | 29 | void copyToBuffer(char*& buffer, const void* data, size_t count) { 30 | memcpy(buffer, data, count); 31 | } 32 | 33 | void convertAndCopyToDeivce(void*& deviceWeights, const nvinfer1::Weights &weights, 34 | nvinfer1::DataType datatype) { 35 | size_t size = weights.count * type2size(datatype); 36 | if (weights.type != datatype) // Weights are converted in host memory first, if the type does not match 37 | { 38 | void *buffer = malloc(size); 39 | for (int64_t v = 0; v < weights.count; ++v) 40 | if (datatype == nvinfer1::DataType::kFLOAT) 41 | static_cast(buffer)[v] = __half2float(static_cast(weights.values)[v]); 42 | else 43 | static_cast<__half *>(buffer)[v] = __float2half(static_cast(weights.values)[v]); 44 | 45 | deviceWeights = copyToDevice(buffer, size); 46 | free(buffer); 47 | } 48 | else 49 | deviceWeights = copyToDevice(weights.values, size); 50 | } 51 | 52 | void convertAndCopyToBuffer(char*& buffer, const nvinfer1::Weights weights, 53 | nvinfer1::DataType datatype) { 54 | size_t size = weights.count * type2size(datatype); 55 | if(weights.type != datatype) { 56 | for (int64_t v = 0; v < weights.count; ++v) { 57 | if (datatype == nvinfer1::DataType::kFLOAT) 58 | reinterpret_cast(buffer)[v] = __half2float(static_cast(weights.values)[v]); 59 | else 60 | reinterpret_cast<__half *>(buffer)[v] = __float2half(static_cast(weights.values)[v]); 61 | } 62 | } else { 63 | copyToBuffer(buffer, weights.values, size); 64 | } 65 | buffer += size; 66 | } -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | image: 3 | - Visual Studio 2017 4 | - Visual Studio 2015 5 | test: off 6 | skip_branch_with_pr: true 7 | build: 8 | parallel: true 9 | platform: 10 | - x64 11 | - x86 12 | environment: 13 | matrix: 14 | - PYTHON: 36 15 | CPP: 14 16 | CONFIG: Debug 17 | - PYTHON: 27 18 | CPP: 14 19 | CONFIG: Debug 20 | - CONDA: 36 21 | CPP: latest 22 | CONFIG: Release 23 | matrix: 24 | exclude: 25 | - image: Visual Studio 2015 26 | platform: x86 27 | - image: Visual Studio 2015 28 | CPP: latest 29 | - image: Visual Studio 2017 30 | CPP: latest 31 | platform: x86 32 | install: 33 | - ps: | 34 | if ($env:PLATFORM -eq "x64") { $env:CMAKE_ARCH = "x64" } 35 | if ($env:APPVEYOR_JOB_NAME -like "*Visual Studio 2017*") { 36 | $env:CMAKE_GENERATOR = "Visual Studio 15 2017" 37 | $env:CMAKE_INCLUDE_PATH = "C:\Libraries\boost_1_64_0" 38 | $env:CXXFLAGS = "-permissive-" 39 | } else { 40 | $env:CMAKE_GENERATOR = "Visual Studio 14 2015" 41 | } 42 | if ($env:PYTHON) { 43 | if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" } 44 | $env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH" 45 | python -W ignore -m pip install --upgrade pip wheel 46 | python -W ignore -m pip install pytest numpy --no-warn-script-location 47 | } elseif ($env:CONDA) { 48 | if ($env:CONDA -eq "27") { $env:CONDA = "" } 49 | if ($env:PLATFORM -eq "x64") { $env:CONDA = "$env:CONDA-x64" } 50 | $env:PATH = "C:\Miniconda$env:CONDA\;C:\Miniconda$env:CONDA\Scripts\;$env:PATH" 51 | $env:PYTHONHOME = "C:\Miniconda$env:CONDA" 52 | conda --version 53 | conda install -y -q pytest numpy scipy 54 | } 55 | - ps: | 56 | Start-FileDownload 'http://bitbucket.org/eigen/eigen/get/3.3.3.zip' 57 | 7z x 3.3.3.zip -y > $null 58 | $env:CMAKE_INCLUDE_PATH = "eigen-eigen-67e894c6cd8f;$env:CMAKE_INCLUDE_PATH" 59 | build_script: 60 | - cmake -G "%CMAKE_GENERATOR%" -A "%CMAKE_ARCH%" 61 | -DPYBIND11_CPP_STANDARD=/std:c++%CPP% 62 | -DPYBIND11_WERROR=ON 63 | -DDOWNLOAD_CATCH=ON 64 | -DCMAKE_SUPPRESS_REGENERATION=1 65 | . 66 | - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" 67 | - cmake --build . --config %CONFIG% --target pytest -- /m /v:m /logger:%MSBuildLogger% 68 | - cmake --build . --config %CONFIG% --target cpptest -- /m /v:m /logger:%MSBuildLogger% 69 | - if "%CPP%"=="latest" (cmake --build . --config %CONFIG% --target test_cmake_build -- /m /v:m /logger:%MSBuildLogger%) 70 | on_failure: if exist "tests\test_cmake_build" type tests\test_cmake_build\*.log* 71 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | Makefile 4 | cmake_install.cmake 5 | .DS_Store 6 | *.so 7 | *.pyd 8 | *.dll 9 | *.sln 10 | *.sdf 11 | *.opensdf 12 | *.vcxproj 13 | *.filters 14 | example.dir 15 | Win32 16 | x64 17 | Release 18 | Debug 19 | .vs 20 | CTestTestfile.cmake 21 | Testing 22 | autogen 23 | MANIFEST 24 | /.ninja_* 25 | /*.ninja 26 | /docs/.build 27 | *.py[co] 28 | *.egg-info 29 | *~ 30 | .*.swp 31 | .DS_Store 32 | /dist 33 | /build 34 | /cmake/ 35 | .cache/ 36 | sosize-*.txt 37 | pybind11Config*.cmake 38 | pybind11Targets.cmake 39 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tools/clang"] 2 | path = tools/clang 3 | url = ../../wjakob/clang-cindex-python3 4 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/.readthedocs.yml: -------------------------------------------------------------------------------- 1 | python: 2 | version: 3 3 | requirements_file: docs/requirements.txt 4 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Make sure you've completed the following steps before submitting your issue -- thank you! 2 | 3 | 1. Check if your question has already been answered in the [FAQ](http://pybind11.readthedocs.io/en/latest/faq.html) section. 4 | 2. Make sure you've read the [documentation](http://pybind11.readthedocs.io/en/latest/). Your issue may be addressed there. 5 | 3. If those resources didn't help and you only have a short question (not a bug report), consider asking in the [Gitter chat room](https://gitter.im/pybind/Lobby). 6 | 4. If you have a genuine bug report or a more complex question which is not answered in the previous items (or not suitable for chat), please fill in the details below. 7 | 5. Include a self-contained and minimal piece of code that reproduces the problem. If that's not possible, try to make the description as clear as possible. 8 | 9 | *After reading, remove this checklist and the template text in parentheses below.* 10 | 11 | ## Issue description 12 | 13 | (Provide a short description, state the expected behavior and what actually happens.) 14 | 15 | ## Reproducible example code 16 | 17 | (The code should be minimal, have no external dependencies, isolate the function(s) that cause breakage. Submit matched and complete C++ and Python snippets that can be easily compiled and run to diagnose the issue.) 18 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Wenzel Jakob , All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | Please also refer to the file CONTRIBUTING.md, which clarifies licensing of 29 | external contributions to this project including patches, pull requests, etc. 30 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include include/pybind11 *.h 2 | include LICENSE README.md CONTRIBUTING.md 3 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = pybind11 2 | INPUT = ../include/pybind11/ 3 | RECURSIVE = YES 4 | 5 | GENERATE_HTML = NO 6 | GENERATE_LATEX = NO 7 | GENERATE_XML = YES 8 | XML_OUTPUT = .build/doxygenxml 9 | XML_PROGRAMLISTING = YES 10 | 11 | MACRO_EXPANSION = YES 12 | EXPAND_ONLY_PREDEF = YES 13 | EXPAND_AS_DEFINED = PYBIND11_RUNTIME_EXCEPTION 14 | 15 | ALIASES = "rst=\verbatim embed:rst" 16 | ALIASES += "endrst=\endverbatim" 17 | 18 | QUIET = YES 19 | WARNINGS = YES 20 | WARN_IF_UNDOCUMENTED = NO 21 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/_static/theme_overrides.css: -------------------------------------------------------------------------------- 1 | .wy-table-responsive table td, 2 | .wy-table-responsive table th { 3 | white-space: initial !important; 4 | } 5 | .rst-content table.docutils td { 6 | vertical-align: top !important; 7 | } 8 | div[class^='highlight'] pre { 9 | white-space: pre; 10 | white-space: pre-wrap; 11 | } 12 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/advanced/cast/index.rst: -------------------------------------------------------------------------------- 1 | Type conversions 2 | ################ 3 | 4 | Apart from enabling cross-language function calls, a fundamental problem 5 | that a binding tool like pybind11 must address is to provide access to 6 | native Python types in C++ and vice versa. There are three fundamentally 7 | different ways to do this—which approach is preferable for a particular type 8 | depends on the situation at hand. 9 | 10 | 1. Use a native C++ type everywhere. In this case, the type must be wrapped 11 | using pybind11-generated bindings so that Python can interact with it. 12 | 13 | 2. Use a native Python type everywhere. It will need to be wrapped so that 14 | C++ functions can interact with it. 15 | 16 | 3. Use a native C++ type on the C++ side and a native Python type on the 17 | Python side. pybind11 refers to this as a *type conversion*. 18 | 19 | Type conversions are the most "natural" option in the sense that native 20 | (non-wrapped) types are used everywhere. The main downside is that a copy 21 | of the data must be made on every Python ↔ C++ transition: this is 22 | needed since the C++ and Python versions of the same type generally won't 23 | have the same memory layout. 24 | 25 | pybind11 can perform many kinds of conversions automatically. An overview 26 | is provided in the table ":ref:`conversion_table`". 27 | 28 | The following subsections discuss the differences between these options in more 29 | detail. The main focus in this section is on type conversions, which represent 30 | the last case of the above list. 31 | 32 | .. toctree:: 33 | :maxdepth: 1 34 | 35 | overview 36 | strings 37 | stl 38 | functional 39 | chrono 40 | eigen 41 | custom 42 | 43 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/advanced/pycpp/index.rst: -------------------------------------------------------------------------------- 1 | Python C++ interface 2 | #################### 3 | 4 | pybind11 exposes Python types and functions using thin C++ wrappers, which 5 | makes it possible to conveniently call Python code from C++ without resorting 6 | to Python's C API. 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | object 12 | numpy 13 | utilities 14 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/index.rst: -------------------------------------------------------------------------------- 1 | .. only: not latex 2 | 3 | .. image:: pybind11-logo.png 4 | 5 | pybind11 --- Seamless operability between C++11 and Python 6 | ========================================================== 7 | 8 | .. only: not latex 9 | 10 | Contents: 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | 15 | intro 16 | changelog 17 | upgrade 18 | 19 | .. toctree:: 20 | :caption: The Basics 21 | :maxdepth: 2 22 | 23 | basics 24 | classes 25 | compiling 26 | 27 | .. toctree:: 28 | :caption: Advanced Topics 29 | :maxdepth: 2 30 | 31 | advanced/functions 32 | advanced/classes 33 | advanced/exceptions 34 | advanced/smart_ptrs 35 | advanced/cast/index 36 | advanced/pycpp/index 37 | advanced/embedding 38 | advanced/misc 39 | 40 | .. toctree:: 41 | :caption: Extra Information 42 | :maxdepth: 1 43 | 44 | faq 45 | benchmark 46 | limitations 47 | reference 48 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/limitations.rst: -------------------------------------------------------------------------------- 1 | Limitations 2 | ########### 3 | 4 | pybind11 strives to be a general solution to binding generation, but it also has 5 | certain limitations: 6 | 7 | - pybind11 casts away ``const``-ness in function arguments and return values. 8 | This is in line with the Python language, which has no concept of ``const`` 9 | values. This means that some additional care is needed to avoid bugs that 10 | would be caught by the type checker in a traditional C++ program. 11 | 12 | - The NumPy interface ``pybind11::array`` greatly simplifies accessing 13 | numerical data from C++ (and vice versa), but it's not a full-blown array 14 | class like ``Eigen::Array`` or ``boost.multi_array``. 15 | 16 | These features could be implemented but would lead to a significant increase in 17 | complexity. I've decided to draw the line here to keep this project simple and 18 | compact. Users who absolutely require these features are encouraged to fork 19 | pybind11. 20 | 21 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/pybind11-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elevator-214/elevator-monitor/246a2d31804d77739e76706250c23940fc18671c/tiny-tensorrt/pybind11/docs/pybind11-logo.png -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/pybind11_vs_boost_python1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elevator-214/elevator-monitor/246a2d31804d77739e76706250c23940fc18671c/tiny-tensorrt/pybind11/docs/pybind11_vs_boost_python1.png -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/pybind11_vs_boost_python2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elevator-214/elevator-monitor/246a2d31804d77739e76706250c23940fc18671c/tiny-tensorrt/pybind11/docs/pybind11_vs_boost_python2.png -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/reference.rst: -------------------------------------------------------------------------------- 1 | .. _reference: 2 | 3 | .. warning:: 4 | 5 | Please be advised that the reference documentation discussing pybind11 6 | internals is currently incomplete. Please refer to the previous sections 7 | and the pybind11 header files for the nitty gritty details. 8 | 9 | Reference 10 | ######### 11 | 12 | .. _macros: 13 | 14 | Macros 15 | ====== 16 | 17 | .. doxygendefine:: PYBIND11_MODULE 18 | 19 | .. _core_types: 20 | 21 | Convenience classes for arbitrary Python types 22 | ============================================== 23 | 24 | Common member functions 25 | ----------------------- 26 | 27 | .. doxygenclass:: object_api 28 | :members: 29 | 30 | Without reference counting 31 | -------------------------- 32 | 33 | .. doxygenclass:: handle 34 | :members: 35 | 36 | With reference counting 37 | ----------------------- 38 | 39 | .. doxygenclass:: object 40 | :members: 41 | 42 | .. doxygenfunction:: reinterpret_borrow 43 | 44 | .. doxygenfunction:: reinterpret_steal 45 | 46 | Convenience classes for specific Python types 47 | ============================================= 48 | 49 | .. doxygenclass:: module 50 | :members: 51 | 52 | .. doxygengroup:: pytypes 53 | :members: 54 | 55 | .. _extras: 56 | 57 | Passing extra arguments to ``def`` or ``class_`` 58 | ================================================ 59 | 60 | .. doxygengroup:: annotations 61 | :members: 62 | 63 | Embedding the interpreter 64 | ========================= 65 | 66 | .. doxygendefine:: PYBIND11_EMBEDDED_MODULE 67 | 68 | .. doxygenfunction:: initialize_interpreter 69 | 70 | .. doxygenfunction:: finalize_interpreter 71 | 72 | .. doxygenclass:: scoped_interpreter 73 | 74 | Redirecting C++ streams 75 | ======================= 76 | 77 | .. doxygenclass:: scoped_ostream_redirect 78 | 79 | .. doxygenclass:: scoped_estream_redirect 80 | 81 | .. doxygenfunction:: add_ostream_redirect 82 | 83 | Python built-in functions 84 | ========================= 85 | 86 | .. doxygengroup:: python_builtins 87 | :members: 88 | 89 | Inheritance 90 | =========== 91 | 92 | See :doc:`/classes` and :doc:`/advanced/classes` for more detail. 93 | 94 | .. doxygendefine:: PYBIND11_OVERLOAD 95 | 96 | .. doxygendefine:: PYBIND11_OVERLOAD_PURE 97 | 98 | .. doxygendefine:: PYBIND11_OVERLOAD_NAME 99 | 100 | .. doxygendefine:: PYBIND11_OVERLOAD_PURE_NAME 101 | 102 | .. doxygenfunction:: get_overload 103 | 104 | Exceptions 105 | ========== 106 | 107 | .. doxygenclass:: error_already_set 108 | :members: 109 | 110 | .. doxygenclass:: builtin_exception 111 | :members: 112 | 113 | 114 | Literals 115 | ======== 116 | 117 | .. doxygennamespace:: literals 118 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/release.rst: -------------------------------------------------------------------------------- 1 | To release a new version of pybind11: 2 | 3 | - Update the version number and push to pypi 4 | - Update ``pybind11/_version.py`` (set release version, remove 'dev'). 5 | - Update ``PYBIND11_VERSION_MAJOR`` etc. in ``include/pybind11/detail/common.h``. 6 | - Ensure that all the information in ``setup.py`` is up-to-date. 7 | - Update version in ``docs/conf.py``. 8 | - Tag release date in ``docs/changelog.rst``. 9 | - ``git add`` and ``git commit``. 10 | - if new minor version: ``git checkout -b vX.Y``, ``git push -u origin vX.Y`` 11 | - ``git tag -a vX.Y.Z -m 'vX.Y.Z release'``. 12 | - ``git push`` 13 | - ``git push --tags``. 14 | - ``python setup.py sdist upload``. 15 | - ``python setup.py bdist_wheel upload``. 16 | - Update conda-forge (https://github.com/conda-forge/pybind11-feedstock) via PR 17 | - download release package from Github: ``wget https://github.com/pybind/pybind11/archive/vX.Y.Z.tar.gz`` 18 | - compute checksum: ``shasum -a 256 vX.Y.Z.tar.gz`` 19 | - change version number and checksum in ``recipe/meta.yml`` 20 | - Get back to work 21 | - Update ``_version.py`` (add 'dev' and increment minor). 22 | - Update version in ``docs/conf.py`` 23 | - Update version macros in ``include/pybind11/common.h`` 24 | - ``git add`` and ``git commit``. 25 | ``git push`` 26 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/docs/requirements.txt: -------------------------------------------------------------------------------- 1 | breathe == 4.5.0 2 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/include/pybind11/common.h: -------------------------------------------------------------------------------- 1 | #include "detail/common.h" 2 | #warning "Including 'common.h' is deprecated. It will be removed in v3.0. Use 'pybind11.h'." 3 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/include/pybind11/complex.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/complex.h: Complex number support 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "pybind11.h" 13 | #include 14 | 15 | /// glibc defines I as a macro which breaks things, e.g., boost template names 16 | #ifdef I 17 | # undef I 18 | #endif 19 | 20 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 21 | 22 | template struct format_descriptor, detail::enable_if_t::value>> { 23 | static constexpr const char c = format_descriptor::c; 24 | static constexpr const char value[3] = { 'Z', c, '\0' }; 25 | static std::string format() { return std::string(value); } 26 | }; 27 | 28 | #ifndef PYBIND11_CPP17 29 | 30 | template constexpr const char format_descriptor< 31 | std::complex, detail::enable_if_t::value>>::value[3]; 32 | 33 | #endif 34 | 35 | NAMESPACE_BEGIN(detail) 36 | 37 | template struct is_fmt_numeric, detail::enable_if_t::value>> { 38 | static constexpr bool value = true; 39 | static constexpr int index = is_fmt_numeric::index + 3; 40 | }; 41 | 42 | template class type_caster> { 43 | public: 44 | bool load(handle src, bool convert) { 45 | if (!src) 46 | return false; 47 | if (!convert && !PyComplex_Check(src.ptr())) 48 | return false; 49 | Py_complex result = PyComplex_AsCComplex(src.ptr()); 50 | if (result.real == -1.0 && PyErr_Occurred()) { 51 | PyErr_Clear(); 52 | return false; 53 | } 54 | value = std::complex((T) result.real, (T) result.imag); 55 | return true; 56 | } 57 | 58 | static handle cast(const std::complex &src, return_value_policy /* policy */, handle /* parent */) { 59 | return PyComplex_FromDoubles((double) src.real(), (double) src.imag()); 60 | } 61 | 62 | PYBIND11_TYPE_CASTER(std::complex, _("complex")); 63 | }; 64 | NAMESPACE_END(detail) 65 | NAMESPACE_END(PYBIND11_NAMESPACE) 66 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/include/pybind11/detail/typeid.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/detail/typeid.h: Compiler-independent access to type identifiers 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #if defined(__GNUG__) 16 | #include 17 | #endif 18 | 19 | #include "common.h" 20 | 21 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 22 | NAMESPACE_BEGIN(detail) 23 | /// Erase all occurrences of a substring 24 | inline void erase_all(std::string &string, const std::string &search) { 25 | for (size_t pos = 0;;) { 26 | pos = string.find(search, pos); 27 | if (pos == std::string::npos) break; 28 | string.erase(pos, search.length()); 29 | } 30 | } 31 | 32 | PYBIND11_NOINLINE inline void clean_type_id(std::string &name) { 33 | #if defined(__GNUG__) 34 | int status = 0; 35 | std::unique_ptr res { 36 | abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free }; 37 | if (status == 0) 38 | name = res.get(); 39 | #else 40 | detail::erase_all(name, "class "); 41 | detail::erase_all(name, "struct "); 42 | detail::erase_all(name, "enum "); 43 | #endif 44 | detail::erase_all(name, "pybind11::"); 45 | } 46 | NAMESPACE_END(detail) 47 | 48 | /// Return a string representation of a C++ type 49 | template static std::string type_id() { 50 | std::string name(typeid(T).name()); 51 | detail::clean_type_id(name); 52 | return name; 53 | } 54 | 55 | NAMESPACE_END(PYBIND11_NAMESPACE) 56 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/include/pybind11/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/options.h: global settings that are configurable at runtime. 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/common.h" 13 | 14 | NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 15 | 16 | class options { 17 | public: 18 | 19 | // Default RAII constructor, which leaves settings as they currently are. 20 | options() : previous_state(global_state()) {} 21 | 22 | // Class is non-copyable. 23 | options(const options&) = delete; 24 | options& operator=(const options&) = delete; 25 | 26 | // Destructor, which restores settings that were in effect before. 27 | ~options() { 28 | global_state() = previous_state; 29 | } 30 | 31 | // Setter methods (affect the global state): 32 | 33 | options& disable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = false; return *this; } 34 | 35 | options& enable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = true; return *this; } 36 | 37 | options& disable_function_signatures() & { global_state().show_function_signatures = false; return *this; } 38 | 39 | options& enable_function_signatures() & { global_state().show_function_signatures = true; return *this; } 40 | 41 | // Getter methods (return the global state): 42 | 43 | static bool show_user_defined_docstrings() { return global_state().show_user_defined_docstrings; } 44 | 45 | static bool show_function_signatures() { return global_state().show_function_signatures; } 46 | 47 | // This type is not meant to be allocated on the heap. 48 | void* operator new(size_t) = delete; 49 | 50 | private: 51 | 52 | struct state { 53 | bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings. 54 | bool show_function_signatures = true; //< Include auto-generated function signatures in docstrings. 55 | }; 56 | 57 | static state &global_state() { 58 | static state instance; 59 | return instance; 60 | } 61 | 62 | state previous_state; 63 | }; 64 | 65 | NAMESPACE_END(PYBIND11_NAMESPACE) 66 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/pybind11/__init__.py: -------------------------------------------------------------------------------- 1 | from ._version import version_info, __version__ # noqa: F401 imported but unused 2 | 3 | 4 | def get_include(user=False): 5 | from distutils.dist import Distribution 6 | import os 7 | import sys 8 | 9 | # Are we running in a virtual environment? 10 | virtualenv = hasattr(sys, 'real_prefix') or \ 11 | sys.prefix != getattr(sys, "base_prefix", sys.prefix) 12 | 13 | # Are we running in a conda environment? 14 | conda = os.path.exists(os.path.join(sys.prefix, 'conda-meta')) 15 | 16 | if virtualenv: 17 | return os.path.join(sys.prefix, 'include', 'site', 18 | 'python' + sys.version[:3]) 19 | elif conda: 20 | if os.name == 'nt': 21 | return os.path.join(sys.prefix, 'Library', 'include') 22 | else: 23 | return os.path.join(sys.prefix, 'include') 24 | else: 25 | dist = Distribution({'name': 'pybind11'}) 26 | dist.parse_config_files() 27 | 28 | dist_cobj = dist.get_command_obj('install', create=True) 29 | 30 | # Search for packages in user's home directory? 31 | if user: 32 | dist_cobj.user = user 33 | dist_cobj.prefix = "" 34 | dist_cobj.finalize_options() 35 | 36 | return os.path.dirname(dist_cobj.install_headers) 37 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/pybind11/__main__.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import argparse 4 | import sys 5 | import sysconfig 6 | 7 | from . import get_include 8 | 9 | 10 | def print_includes(): 11 | dirs = [sysconfig.get_path('include'), 12 | sysconfig.get_path('platinclude'), 13 | get_include(), 14 | get_include(True)] 15 | 16 | # Make unique but preserve order 17 | unique_dirs = [] 18 | for d in dirs: 19 | if d not in unique_dirs: 20 | unique_dirs.append(d) 21 | 22 | print(' '.join('-I' + d for d in unique_dirs)) 23 | 24 | 25 | def main(): 26 | parser = argparse.ArgumentParser(prog='python -m pybind11') 27 | parser.add_argument('--includes', action='store_true', 28 | help='Include flags for both pybind11 and Python headers.') 29 | args = parser.parse_args() 30 | if not sys.argv[1:]: 31 | parser.print_help() 32 | if args.includes: 33 | print_includes() 34 | 35 | 36 | if __name__ == '__main__': 37 | main() 38 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/pybind11/_version.py: -------------------------------------------------------------------------------- 1 | version_info = (2, 3, 'dev1') 2 | __version__ = '.'.join(map(str, version_info)) 3 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 3 | 4 | [flake8] 5 | max-line-length = 99 6 | show_source = True 7 | exclude = .git, __pycache__, build, dist, docs, tools, venv 8 | ignore = 9 | # required for pretty matrix formatting: multiple spaces after `,` and `[` 10 | E201, E241, W504, 11 | # camelcase 'cPickle' imported as lowercase 'pickle' 12 | N813 13 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/cross_module_gil_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/cross_module_gil_utils.cpp -- tools for acquiring GIL from a different module 3 | 4 | Copyright (c) 2019 Google LLC 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | #include 10 | #include 11 | 12 | // This file mimics a DSO that makes pybind11 calls but does not define a 13 | // PYBIND11_MODULE. The purpose is to test that such a DSO can create a 14 | // py::gil_scoped_acquire when the running thread is in a GIL-released state. 15 | // 16 | // Note that we define a Python module here for convenience, but in general 17 | // this need not be the case. The typical scenario would be a DSO that implements 18 | // shared logic used internally by multiple pybind11 modules. 19 | 20 | namespace { 21 | 22 | namespace py = pybind11; 23 | void gil_acquire() { py::gil_scoped_acquire gil; } 24 | 25 | constexpr char kModuleName[] = "cross_module_gil_utils"; 26 | 27 | #if PY_MAJOR_VERSION >= 3 28 | struct PyModuleDef moduledef = { 29 | PyModuleDef_HEAD_INIT, 30 | kModuleName, 31 | NULL, 32 | 0, 33 | NULL, 34 | NULL, 35 | NULL, 36 | NULL, 37 | NULL 38 | }; 39 | #else 40 | PyMethodDef module_methods[] = { 41 | {NULL, NULL, 0, NULL} 42 | }; 43 | #endif 44 | 45 | } // namespace 46 | 47 | extern "C" PYBIND11_EXPORT 48 | #if PY_MAJOR_VERSION >= 3 49 | PyObject* PyInit_cross_module_gil_utils() 50 | #else 51 | void initcross_module_gil_utils() 52 | #endif 53 | { 54 | 55 | PyObject* m = 56 | #if PY_MAJOR_VERSION >= 3 57 | PyModule_Create(&moduledef); 58 | #else 59 | Py_InitModule(kModuleName, module_methods); 60 | #endif 61 | 62 | if (m != NULL) { 63 | static_assert( 64 | sizeof(&gil_acquire) == sizeof(void*), 65 | "Function pointer must have the same size as void*"); 66 | PyModule_AddObject(m, "gil_acquire_funcaddr", 67 | PyLong_FromVoidPtr(reinterpret_cast(&gil_acquire))); 68 | } 69 | 70 | #if PY_MAJOR_VERSION >= 3 71 | return m; 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/local_bindings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "pybind11_tests.h" 3 | 4 | /// Simple class used to test py::local: 5 | template class LocalBase { 6 | public: 7 | LocalBase(int i) : i(i) { } 8 | int i = -1; 9 | }; 10 | 11 | /// Registered with py::module_local in both main and secondary modules: 12 | using LocalType = LocalBase<0>; 13 | /// Registered without py::module_local in both modules: 14 | using NonLocalType = LocalBase<1>; 15 | /// A second non-local type (for stl_bind tests): 16 | using NonLocal2 = LocalBase<2>; 17 | /// Tests within-module, different-compilation-unit local definition conflict: 18 | using LocalExternal = LocalBase<3>; 19 | /// Mixed: registered local first, then global 20 | using MixedLocalGlobal = LocalBase<4>; 21 | /// Mixed: global first, then local 22 | using MixedGlobalLocal = LocalBase<5>; 23 | 24 | /// Registered with py::module_local only in the secondary module: 25 | using ExternalType1 = LocalBase<6>; 26 | using ExternalType2 = LocalBase<7>; 27 | 28 | using LocalVec = std::vector; 29 | using LocalVec2 = std::vector; 30 | using LocalMap = std::unordered_map; 31 | using NonLocalVec = std::vector; 32 | using NonLocalVec2 = std::vector; 33 | using NonLocalMap = std::unordered_map; 34 | using NonLocalMap2 = std::unordered_map; 35 | 36 | PYBIND11_MAKE_OPAQUE(LocalVec); 37 | PYBIND11_MAKE_OPAQUE(LocalVec2); 38 | PYBIND11_MAKE_OPAQUE(LocalMap); 39 | PYBIND11_MAKE_OPAQUE(NonLocalVec); 40 | //PYBIND11_MAKE_OPAQUE(NonLocalVec2); // same type as LocalVec2 41 | PYBIND11_MAKE_OPAQUE(NonLocalMap); 42 | PYBIND11_MAKE_OPAQUE(NonLocalMap2); 43 | 44 | 45 | // Simple bindings (used with the above): 46 | template 47 | py::class_ bind_local(Args && ...args) { 48 | return py::class_(std::forward(args)...) 49 | .def(py::init()) 50 | .def("get", [](T &i) { return i.i + Adjust; }); 51 | }; 52 | 53 | // Simulate a foreign library base class (to match the example in the docs): 54 | namespace pets { 55 | class Pet { 56 | public: 57 | Pet(std::string name) : name_(name) {} 58 | std::string name_; 59 | const std::string &name() { return name_; } 60 | }; 61 | } 62 | 63 | struct MixGL { int i; MixGL(int i) : i{i} {} }; 64 | struct MixGL2 { int i; MixGL2(int i) : i{i} {} }; 65 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/pybind11_tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #if defined(_MSC_VER) && _MSC_VER < 1910 5 | // We get some really long type names here which causes MSVC 2015 to emit warnings 6 | # pragma warning(disable: 4503) // warning C4503: decorated name length exceeded, name was truncated 7 | #endif 8 | 9 | namespace py = pybind11; 10 | using namespace pybind11::literals; 11 | 12 | class test_initializer { 13 | using Initializer = void (*)(py::module &); 14 | 15 | public: 16 | test_initializer(Initializer init); 17 | test_initializer(const char *submodule_name, Initializer init); 18 | }; 19 | 20 | #define TEST_SUBMODULE(name, variable) \ 21 | void test_submodule_##name(py::module &); \ 22 | test_initializer name(#name, test_submodule_##name); \ 23 | void test_submodule_##name(py::module &variable) 24 | 25 | 26 | /// Dummy type which is not exported anywhere -- something to trigger a conversion error 27 | struct UnregisteredType { }; 28 | 29 | /// A user-defined type which is exported and can be used by any test 30 | class UserType { 31 | public: 32 | UserType() = default; 33 | UserType(int i) : i(i) { } 34 | 35 | int value() const { return i; } 36 | void set(int set) { i = set; } 37 | 38 | private: 39 | int i = -1; 40 | }; 41 | 42 | /// Like UserType, but increments `value` on copy for quick reference vs. copy tests 43 | class IncType : public UserType { 44 | public: 45 | using UserType::UserType; 46 | IncType() = default; 47 | IncType(const IncType &other) : IncType(other.value() + 1) { } 48 | IncType(IncType &&) = delete; 49 | IncType &operator=(const IncType &) = delete; 50 | IncType &operator=(IncType &&) = delete; 51 | }; 52 | 53 | /// Custom cast-only type that casts to a string "rvalue" or "lvalue" depending on the cast context. 54 | /// Used to test recursive casters (e.g. std::tuple, stl containers). 55 | struct RValueCaster {}; 56 | NAMESPACE_BEGIN(pybind11) 57 | NAMESPACE_BEGIN(detail) 58 | template<> class type_caster { 59 | public: 60 | PYBIND11_TYPE_CASTER(RValueCaster, _("RValueCaster")); 61 | static handle cast(RValueCaster &&, return_value_policy, handle) { return py::str("rvalue").release(); } 62 | static handle cast(const RValueCaster &, return_value_policy, handle) { return py::str("lvalue").release(); } 63 | }; 64 | NAMESPACE_END(detail) 65 | NAMESPACE_END(pybind11) 66 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | minversion = 3.0 3 | norecursedirs = test_cmake_build test_embed 4 | addopts = 5 | # show summary of skipped tests 6 | -rs 7 | # capture only Python print and C++ py::print, but not C output (low-level Python errors) 8 | --capture=sys 9 | filterwarnings = 10 | # make warnings into errors but ignore certain third-party extension issues 11 | error 12 | # importing scipy submodules on some version of Python 13 | ignore::ImportWarning 14 | # bogus numpy ABI warning (see numpy/#432) 15 | ignore:.*numpy.dtype size changed.*:RuntimeWarning 16 | ignore:.*numpy.ufunc size changed.*:RuntimeWarning 17 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_async.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_async.cpp -- __await__ support 3 | 4 | Copyright (c) 2019 Google Inc. 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include "pybind11_tests.h" 11 | 12 | TEST_SUBMODULE(async_module, m) { 13 | struct DoesNotSupportAsync {}; 14 | py::class_(m, "DoesNotSupportAsync") 15 | .def(py::init<>()); 16 | struct SupportsAsync {}; 17 | py::class_(m, "SupportsAsync") 18 | .def(py::init<>()) 19 | .def("__await__", [](const SupportsAsync& self) -> py::object { 20 | static_cast(self); 21 | py::object loop = py::module::import("asyncio.events").attr("get_event_loop")(); 22 | py::object f = loop.attr("create_future")(); 23 | f.attr("set_result")(5); 24 | return f.attr("__await__")(); 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_async.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import pytest 3 | from pybind11_tests import async_module as m 4 | 5 | 6 | @pytest.fixture 7 | def event_loop(): 8 | loop = asyncio.new_event_loop() 9 | yield loop 10 | loop.close() 11 | 12 | 13 | async def get_await_result(x): 14 | return await x 15 | 16 | 17 | def test_await(event_loop): 18 | assert 5 == event_loop.run_until_complete(get_await_result(m.SupportsAsync())) 19 | 20 | 21 | def test_await_missing(event_loop): 22 | with pytest.raises(TypeError): 23 | event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync())) 24 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_chrono.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_chrono.cpp -- test conversions to/from std::chrono types 3 | 4 | Copyright (c) 2016 Trent Houliston and 5 | Wenzel Jakob 6 | 7 | All rights reserved. Use of this source code is governed by a 8 | BSD-style license that can be found in the LICENSE file. 9 | */ 10 | 11 | #include "pybind11_tests.h" 12 | #include 13 | 14 | TEST_SUBMODULE(chrono, m) { 15 | using system_time = std::chrono::system_clock::time_point; 16 | using steady_time = std::chrono::steady_clock::time_point; 17 | 18 | using timespan = std::chrono::duration; 19 | using timestamp = std::chrono::time_point; 20 | 21 | // test_chrono_system_clock 22 | // Return the current time off the wall clock 23 | m.def("test_chrono1", []() { return std::chrono::system_clock::now(); }); 24 | 25 | // test_chrono_system_clock_roundtrip 26 | // Round trip the passed in system clock time 27 | m.def("test_chrono2", [](system_time t) { return t; }); 28 | 29 | // test_chrono_duration_roundtrip 30 | // Round trip the passed in duration 31 | m.def("test_chrono3", [](std::chrono::system_clock::duration d) { return d; }); 32 | 33 | // test_chrono_duration_subtraction_equivalence 34 | // Difference between two passed in time_points 35 | m.def("test_chrono4", [](system_time a, system_time b) { return a - b; }); 36 | 37 | // test_chrono_steady_clock 38 | // Return the current time off the steady_clock 39 | m.def("test_chrono5", []() { return std::chrono::steady_clock::now(); }); 40 | 41 | // test_chrono_steady_clock_roundtrip 42 | // Round trip a steady clock timepoint 43 | m.def("test_chrono6", [](steady_time t) { return t; }); 44 | 45 | // test_floating_point_duration 46 | // Roundtrip a duration in microseconds from a float argument 47 | m.def("test_chrono7", [](std::chrono::microseconds t) { return t; }); 48 | // Float durations (issue #719) 49 | m.def("test_chrono_float_diff", [](std::chrono::duration a, std::chrono::duration b) { 50 | return a - b; }); 51 | 52 | m.def("test_nano_timepoint", [](timestamp start, timespan delta) -> timestamp { 53 | return start + delta; 54 | }); 55 | } 56 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_custom_target(test_cmake_build) 2 | 3 | if(CMAKE_VERSION VERSION_LESS 3.1) 4 | # 3.0 needed for interface library for subdirectory_target/installed_target 5 | # 3.1 needed for cmake -E env for testing 6 | return() 7 | endif() 8 | 9 | include(CMakeParseArguments) 10 | function(pybind11_add_build_test name) 11 | cmake_parse_arguments(ARG "INSTALL" "" "" ${ARGN}) 12 | 13 | set(build_options "-DCMAKE_PREFIX_PATH=${PROJECT_BINARY_DIR}/mock_install" 14 | "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" 15 | "-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}" 16 | "-DPYBIND11_CPP_STANDARD=${PYBIND11_CPP_STANDARD}") 17 | if(NOT ARG_INSTALL) 18 | list(APPEND build_options "-DPYBIND11_PROJECT_DIR=${PROJECT_SOURCE_DIR}") 19 | endif() 20 | 21 | add_custom_target(test_${name} ${CMAKE_CTEST_COMMAND} 22 | --quiet --output-log ${name}.log 23 | --build-and-test "${CMAKE_CURRENT_SOURCE_DIR}/${name}" 24 | "${CMAKE_CURRENT_BINARY_DIR}/${name}" 25 | --build-config Release 26 | --build-noclean 27 | --build-generator ${CMAKE_GENERATOR} 28 | $<$:--build-generator-platform> ${CMAKE_GENERATOR_PLATFORM} 29 | --build-makeprogram ${CMAKE_MAKE_PROGRAM} 30 | --build-target check 31 | --build-options ${build_options} 32 | ) 33 | if(ARG_INSTALL) 34 | add_dependencies(test_${name} mock_install) 35 | endif() 36 | add_dependencies(test_cmake_build test_${name}) 37 | endfunction() 38 | 39 | pybind11_add_build_test(subdirectory_function) 40 | pybind11_add_build_test(subdirectory_target) 41 | if(NOT ${PYTHON_MODULE_EXTENSION} MATCHES "pypy") 42 | pybind11_add_build_test(subdirectory_embed) 43 | endif() 44 | 45 | if(PYBIND11_INSTALL) 46 | add_custom_target(mock_install ${CMAKE_COMMAND} 47 | "-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/mock_install" 48 | -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" 49 | ) 50 | 51 | pybind11_add_build_test(installed_function INSTALL) 52 | pybind11_add_build_test(installed_target INSTALL) 53 | if(NOT ${PYTHON_MODULE_EXTENSION} MATCHES "pypy") 54 | pybind11_add_build_test(installed_embed INSTALL) 55 | endif() 56 | endif() 57 | 58 | add_dependencies(check test_cmake_build) 59 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/embed.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace py = pybind11; 3 | 4 | PYBIND11_EMBEDDED_MODULE(test_cmake_build, m) { 5 | m.def("add", [](int i, int j) { return i + j; }); 6 | } 7 | 8 | int main(int argc, char *argv[]) { 9 | if (argc != 2) 10 | throw std::runtime_error("Expected test.py file as the first argument"); 11 | auto test_py_file = argv[1]; 12 | 13 | py::scoped_interpreter guard{}; 14 | 15 | auto m = py::module::import("test_cmake_build"); 16 | if (m.attr("add")(1, 2).cast() != 3) 17 | throw std::runtime_error("embed.cpp failed"); 18 | 19 | py::module::import("sys").attr("argv") = py::make_tuple("test.py", "embed.cpp"); 20 | py::eval_file(test_py_file, py::globals()); 21 | } 22 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(test_installed_embed CXX) 3 | 4 | set(CMAKE_MODULE_PATH "") 5 | find_package(pybind11 CONFIG REQUIRED) 6 | message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") 7 | 8 | add_executable(test_cmake_build ../embed.cpp) 9 | target_link_libraries(test_cmake_build PRIVATE pybind11::embed) 10 | 11 | # Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::embed). 12 | # This may be needed to resolve header conflicts, e.g. between Python release and debug headers. 13 | set_target_properties(test_cmake_build PROPERTIES NO_SYSTEM_FROM_IMPORTED ON) 14 | 15 | add_custom_target(check $ ${PROJECT_SOURCE_DIR}/../test.py) 16 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(test_installed_module CXX) 3 | 4 | set(CMAKE_MODULE_PATH "") 5 | 6 | find_package(pybind11 CONFIG REQUIRED) 7 | message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") 8 | 9 | pybind11_add_module(test_cmake_build SHARED NO_EXTRAS ../main.cpp) 10 | 11 | add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$ 12 | ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME}) 13 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(test_installed_target CXX) 3 | 4 | set(CMAKE_MODULE_PATH "") 5 | 6 | find_package(pybind11 CONFIG REQUIRED) 7 | message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") 8 | 9 | add_library(test_cmake_build MODULE ../main.cpp) 10 | 11 | target_link_libraries(test_cmake_build PRIVATE pybind11::module) 12 | 13 | # make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib 14 | set_target_properties(test_cmake_build PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" 15 | SUFFIX "${PYTHON_MODULE_EXTENSION}") 16 | 17 | # Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::module). 18 | # This may be needed to resolve header conflicts, e.g. between Python release and debug headers. 19 | set_target_properties(test_cmake_build PROPERTIES NO_SYSTEM_FROM_IMPORTED ON) 20 | 21 | add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$ 22 | ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME}) 23 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace py = pybind11; 3 | 4 | PYBIND11_MODULE(test_cmake_build, m) { 5 | m.def("add", [](int i, int j) { return i + j; }); 6 | } 7 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(test_subdirectory_embed CXX) 3 | 4 | set(PYBIND11_INSTALL ON CACHE BOOL "") 5 | set(PYBIND11_EXPORT_NAME test_export) 6 | 7 | add_subdirectory(${PYBIND11_PROJECT_DIR} pybind11) 8 | 9 | # Test basic target functionality 10 | add_executable(test_cmake_build ../embed.cpp) 11 | target_link_libraries(test_cmake_build PRIVATE pybind11::embed) 12 | 13 | add_custom_target(check $ ${PROJECT_SOURCE_DIR}/../test.py) 14 | 15 | # Test custom export group -- PYBIND11_EXPORT_NAME 16 | add_library(test_embed_lib ../embed.cpp) 17 | target_link_libraries(test_embed_lib PRIVATE pybind11::embed) 18 | 19 | install(TARGETS test_embed_lib 20 | EXPORT test_export 21 | ARCHIVE DESTINATION bin 22 | LIBRARY DESTINATION lib 23 | RUNTIME DESTINATION lib) 24 | install(EXPORT test_export 25 | DESTINATION lib/cmake/test_export/test_export-Targets.cmake) 26 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(test_subdirectory_module CXX) 3 | 4 | add_subdirectory(${PYBIND11_PROJECT_DIR} pybind11) 5 | pybind11_add_module(test_cmake_build THIN_LTO ../main.cpp) 6 | 7 | add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$ 8 | ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME}) 9 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(test_subdirectory_target CXX) 3 | 4 | add_subdirectory(${PYBIND11_PROJECT_DIR} pybind11) 5 | 6 | add_library(test_cmake_build MODULE ../main.cpp) 7 | 8 | target_link_libraries(test_cmake_build PRIVATE pybind11::module) 9 | 10 | # make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib 11 | set_target_properties(test_cmake_build PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" 12 | SUFFIX "${PYTHON_MODULE_EXTENSION}") 13 | 14 | add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$ 15 | ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME}) 16 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_cmake_build/test.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import test_cmake_build 3 | 4 | assert test_cmake_build.add(1, 2) == 3 5 | print("{} imports, runs, and adds: 1 + 2 = 3".format(sys.argv[1])) 6 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_constants_and_functions.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import constants_and_functions as m 2 | 3 | 4 | def test_constants(): 5 | assert m.some_constant == 14 6 | 7 | 8 | def test_function_overloading(): 9 | assert m.test_function() == "test_function()" 10 | assert m.test_function(7) == "test_function(7)" 11 | assert m.test_function(m.MyEnum.EFirstEntry) == "test_function(enum=1)" 12 | assert m.test_function(m.MyEnum.ESecondEntry) == "test_function(enum=2)" 13 | 14 | assert m.test_function() == "test_function()" 15 | assert m.test_function("abcd") == "test_function(char *)" 16 | assert m.test_function(1, 1.0) == "test_function(int, float)" 17 | assert m.test_function(1, 1.0) == "test_function(int, float)" 18 | assert m.test_function(2.0, 2) == "test_function(float, int)" 19 | 20 | 21 | def test_bytes(): 22 | assert m.print_bytes(m.return_bytes()) == "bytes[1 0 2 0]" 23 | 24 | 25 | def test_exception_specifiers(): 26 | c = m.C() 27 | assert c.m1(2) == 1 28 | assert c.m2(3) == 1 29 | assert c.m3(5) == 2 30 | assert c.m4(7) == 3 31 | assert c.m5(10) == 5 32 | assert c.m6(14) == 8 33 | assert c.m7(20) == 13 34 | assert c.m8(29) == 21 35 | 36 | assert m.f1(33) == 34 37 | assert m.f2(53) == 55 38 | assert m.f3(86) == 89 39 | assert m.f4(140) == 144 40 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_docstring_options.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_docstring_options.cpp -- generation of docstrings and signatures 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include "pybind11_tests.h" 11 | 12 | TEST_SUBMODULE(docstring_options, m) { 13 | // test_docstring_options 14 | { 15 | py::options options; 16 | options.disable_function_signatures(); 17 | 18 | m.def("test_function1", [](int, int) {}, py::arg("a"), py::arg("b")); 19 | m.def("test_function2", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); 20 | 21 | m.def("test_overloaded1", [](int) {}, py::arg("i"), "Overload docstring"); 22 | m.def("test_overloaded1", [](double) {}, py::arg("d")); 23 | 24 | m.def("test_overloaded2", [](int) {}, py::arg("i"), "overload docstring 1"); 25 | m.def("test_overloaded2", [](double) {}, py::arg("d"), "overload docstring 2"); 26 | 27 | m.def("test_overloaded3", [](int) {}, py::arg("i")); 28 | m.def("test_overloaded3", [](double) {}, py::arg("d"), "Overload docstr"); 29 | 30 | options.enable_function_signatures(); 31 | 32 | m.def("test_function3", [](int, int) {}, py::arg("a"), py::arg("b")); 33 | m.def("test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); 34 | 35 | options.disable_function_signatures().disable_user_defined_docstrings(); 36 | 37 | m.def("test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); 38 | 39 | { 40 | py::options nested_options; 41 | nested_options.enable_user_defined_docstrings(); 42 | m.def("test_function6", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); 43 | } 44 | } 45 | 46 | m.def("test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring"); 47 | 48 | { 49 | py::options options; 50 | options.disable_user_defined_docstrings(); 51 | 52 | struct DocstringTestFoo { 53 | int value; 54 | void setValue(int v) { value = v; } 55 | int getValue() const { return value; } 56 | }; 57 | py::class_(m, "DocstringTestFoo", "This is a class docstring") 58 | .def_property("value_prop", &DocstringTestFoo::getValue, &DocstringTestFoo::setValue, "This is a property docstring") 59 | ; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_docstring_options.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import docstring_options as m 2 | 3 | 4 | def test_docstring_options(): 5 | # options.disable_function_signatures() 6 | assert not m.test_function1.__doc__ 7 | 8 | assert m.test_function2.__doc__ == "A custom docstring" 9 | 10 | # docstring specified on just the first overload definition: 11 | assert m.test_overloaded1.__doc__ == "Overload docstring" 12 | 13 | # docstring on both overloads: 14 | assert m.test_overloaded2.__doc__ == "overload docstring 1\noverload docstring 2" 15 | 16 | # docstring on only second overload: 17 | assert m.test_overloaded3.__doc__ == "Overload docstr" 18 | 19 | # options.enable_function_signatures() 20 | assert m.test_function3.__doc__ .startswith("test_function3(a: int, b: int) -> None") 21 | 22 | assert m.test_function4.__doc__ .startswith("test_function4(a: int, b: int) -> None") 23 | assert m.test_function4.__doc__ .endswith("A custom docstring\n") 24 | 25 | # options.disable_function_signatures() 26 | # options.disable_user_defined_docstrings() 27 | assert not m.test_function5.__doc__ 28 | 29 | # nested options.enable_user_defined_docstrings() 30 | assert m.test_function6.__doc__ == "A custom docstring" 31 | 32 | # RAII destructor 33 | assert m.test_function7.__doc__ .startswith("test_function7(a: int, b: int) -> None") 34 | assert m.test_function7.__doc__ .endswith("A custom docstring\n") 35 | 36 | # Suppression of user-defined docstrings for non-function objects 37 | assert not m.DocstringTestFoo.__doc__ 38 | assert not m.DocstringTestFoo.value_prop.__doc__ 39 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_embed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(${PYTHON_MODULE_EXTENSION} MATCHES "pypy") 2 | add_custom_target(cpptest) # Dummy target on PyPy. Embedding is not supported. 3 | set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}") 4 | return() 5 | endif() 6 | 7 | find_package(Catch 1.9.3) 8 | if(CATCH_FOUND) 9 | message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}") 10 | else() 11 | message(STATUS "Catch not detected. Interpreter tests will be skipped. Install Catch headers" 12 | " manually or use `cmake -DDOWNLOAD_CATCH=1` to fetch them automatically.") 13 | return() 14 | endif() 15 | 16 | add_executable(test_embed 17 | catch.cpp 18 | test_interpreter.cpp 19 | ) 20 | target_include_directories(test_embed PRIVATE ${CATCH_INCLUDE_DIR}) 21 | pybind11_enable_warnings(test_embed) 22 | 23 | if(NOT CMAKE_VERSION VERSION_LESS 3.0) 24 | target_link_libraries(test_embed PRIVATE pybind11::embed) 25 | else() 26 | target_include_directories(test_embed PRIVATE ${PYBIND11_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS}) 27 | target_compile_options(test_embed PRIVATE ${PYBIND11_CPP_STANDARD}) 28 | target_link_libraries(test_embed PRIVATE ${PYTHON_LIBRARIES}) 29 | endif() 30 | 31 | find_package(Threads REQUIRED) 32 | target_link_libraries(test_embed PUBLIC ${CMAKE_THREAD_LIBS_INIT}) 33 | 34 | add_custom_target(cpptest COMMAND $ 35 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 36 | 37 | pybind11_add_module(external_module THIN_LTO external_module.cpp) 38 | set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 39 | add_dependencies(cpptest external_module) 40 | 41 | add_dependencies(check cpptest) 42 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_embed/catch.cpp: -------------------------------------------------------------------------------- 1 | // The Catch implementation is compiled here. This is a standalone 2 | // translation unit to avoid recompiling it for every test change. 3 | 4 | #include 5 | 6 | #ifdef _MSC_VER 7 | // Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to catch 8 | // 2.0.1; this should be fixed in the next catch release after 2.0.1). 9 | # pragma warning(disable: 4996) 10 | #endif 11 | 12 | #define CATCH_CONFIG_RUNNER 13 | #include 14 | 15 | namespace py = pybind11; 16 | 17 | int main(int argc, char *argv[]) { 18 | py::scoped_interpreter guard{}; 19 | auto result = Catch::Session().run(argc, argv); 20 | 21 | return result < 0xff ? result : 0xff; 22 | } 23 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_embed/external_module.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace py = pybind11; 4 | 5 | /* Simple test module/test class to check that the referenced internals data of external pybind11 6 | * modules aren't preserved over a finalize/initialize. 7 | */ 8 | 9 | PYBIND11_MODULE(external_module, m) { 10 | class A { 11 | public: 12 | A(int value) : v{value} {}; 13 | int v; 14 | }; 15 | 16 | py::class_(m, "A") 17 | .def(py::init()) 18 | .def_readwrite("value", &A::v); 19 | 20 | m.def("internals_at", []() { 21 | return reinterpret_cast(&py::detail::get_internals()); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_embed/test_interpreter.py: -------------------------------------------------------------------------------- 1 | from widget_module import Widget 2 | 3 | 4 | class DerivedWidget(Widget): 5 | def __init__(self, message): 6 | super(DerivedWidget, self).__init__(message) 7 | 8 | def the_answer(self): 9 | return 42 10 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_eval.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_eval.cpp -- Usage of eval() and eval_file() 3 | 4 | Copyright (c) 2016 Klemens D. Morgenstern 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | 11 | #include 12 | #include "pybind11_tests.h" 13 | 14 | TEST_SUBMODULE(eval_, m) { 15 | // test_evals 16 | 17 | auto global = py::dict(py::module::import("__main__").attr("__dict__")); 18 | 19 | m.def("test_eval_statements", [global]() { 20 | auto local = py::dict(); 21 | local["call_test"] = py::cpp_function([&]() -> int { 22 | return 42; 23 | }); 24 | 25 | // Regular string literal 26 | py::exec( 27 | "message = 'Hello World!'\n" 28 | "x = call_test()", 29 | global, local 30 | ); 31 | 32 | // Multi-line raw string literal 33 | py::exec(R"( 34 | if x == 42: 35 | print(message) 36 | else: 37 | raise RuntimeError 38 | )", global, local 39 | ); 40 | auto x = local["x"].cast(); 41 | 42 | return x == 42; 43 | }); 44 | 45 | m.def("test_eval", [global]() { 46 | auto local = py::dict(); 47 | local["x"] = py::int_(42); 48 | auto x = py::eval("x", global, local); 49 | return x.cast() == 42; 50 | }); 51 | 52 | m.def("test_eval_single_statement", []() { 53 | auto local = py::dict(); 54 | local["call_test"] = py::cpp_function([&]() -> int { 55 | return 42; 56 | }); 57 | 58 | auto result = py::eval("x = call_test()", py::dict(), local); 59 | auto x = local["x"].cast(); 60 | return result.is_none() && x == 42; 61 | }); 62 | 63 | m.def("test_eval_file", [global](py::str filename) { 64 | auto local = py::dict(); 65 | local["y"] = py::int_(43); 66 | 67 | int val_out; 68 | local["call_test2"] = py::cpp_function([&](int value) { val_out = value; }); 69 | 70 | auto result = py::eval_file(filename, global, local); 71 | return val_out == 43 && result.is_none(); 72 | }); 73 | 74 | m.def("test_eval_failure", []() { 75 | try { 76 | py::eval("nonsense code ..."); 77 | } catch (py::error_already_set &) { 78 | return true; 79 | } 80 | return false; 81 | }); 82 | 83 | m.def("test_eval_file_failure", []() { 84 | try { 85 | py::eval_file("non-existing file"); 86 | } catch (std::exception &) { 87 | return true; 88 | } 89 | return false; 90 | }); 91 | } 92 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_eval.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pybind11_tests import eval_ as m 3 | 4 | 5 | def test_evals(capture): 6 | with capture: 7 | assert m.test_eval_statements() 8 | assert capture == "Hello World!" 9 | 10 | assert m.test_eval() 11 | assert m.test_eval_single_statement() 12 | 13 | filename = os.path.join(os.path.dirname(__file__), "test_eval_call.py") 14 | assert m.test_eval_file(filename) 15 | 16 | assert m.test_eval_failure() 17 | assert m.test_eval_file_failure() 18 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_eval_call.py: -------------------------------------------------------------------------------- 1 | # This file is called from 'test_eval.py' 2 | 3 | if 'call_test2' in locals(): 4 | call_test2(y) # noqa: F821 undefined name 5 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_gil_scoped.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_gil_scoped.cpp -- acquire and release gil 3 | 4 | Copyright (c) 2017 Borja Zarco (Google LLC) 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include "pybind11_tests.h" 11 | #include 12 | 13 | 14 | class VirtClass { 15 | public: 16 | virtual ~VirtClass() {} 17 | virtual void virtual_func() {} 18 | virtual void pure_virtual_func() = 0; 19 | }; 20 | 21 | class PyVirtClass : public VirtClass { 22 | void virtual_func() override { 23 | PYBIND11_OVERLOAD(void, VirtClass, virtual_func,); 24 | } 25 | void pure_virtual_func() override { 26 | PYBIND11_OVERLOAD_PURE(void, VirtClass, pure_virtual_func,); 27 | } 28 | }; 29 | 30 | TEST_SUBMODULE(gil_scoped, m) { 31 | py::class_(m, "VirtClass") 32 | .def(py::init<>()) 33 | .def("virtual_func", &VirtClass::virtual_func) 34 | .def("pure_virtual_func", &VirtClass::pure_virtual_func); 35 | 36 | m.def("test_callback_py_obj", 37 | [](py::object func) { func(); }); 38 | m.def("test_callback_std_func", 39 | [](const std::function &func) { func(); }); 40 | m.def("test_callback_virtual_func", 41 | [](VirtClass &virt) { virt.virtual_func(); }); 42 | m.def("test_callback_pure_virtual_func", 43 | [](VirtClass &virt) { virt.pure_virtual_func(); }); 44 | m.def("test_cross_module_gil", 45 | []() { 46 | auto cm = py::module::import("cross_module_gil_utils"); 47 | auto gil_acquire = reinterpret_cast( 48 | PyLong_AsVoidPtr(cm.attr("gil_acquire_funcaddr").ptr())); 49 | py::gil_scoped_release gil_release; 50 | gil_acquire(); 51 | }); 52 | } 53 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_iostream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_iostream.cpp -- Usage of scoped_output_redirect 3 | 4 | Copyright (c) 2017 Henry F. Schreiner 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | 11 | #include 12 | #include "pybind11_tests.h" 13 | #include 14 | 15 | 16 | void noisy_function(std::string msg, bool flush) { 17 | 18 | std::cout << msg; 19 | if (flush) 20 | std::cout << std::flush; 21 | } 22 | 23 | void noisy_funct_dual(std::string msg, std::string emsg) { 24 | std::cout << msg; 25 | std::cerr << emsg; 26 | } 27 | 28 | TEST_SUBMODULE(iostream, m) { 29 | 30 | add_ostream_redirect(m); 31 | 32 | // test_evals 33 | 34 | m.def("captured_output_default", [](std::string msg) { 35 | py::scoped_ostream_redirect redir; 36 | std::cout << msg << std::flush; 37 | }); 38 | 39 | m.def("captured_output", [](std::string msg) { 40 | py::scoped_ostream_redirect redir(std::cout, py::module::import("sys").attr("stdout")); 41 | std::cout << msg << std::flush; 42 | }); 43 | 44 | m.def("guard_output", &noisy_function, 45 | py::call_guard(), 46 | py::arg("msg"), py::arg("flush")=true); 47 | 48 | m.def("captured_err", [](std::string msg) { 49 | py::scoped_ostream_redirect redir(std::cerr, py::module::import("sys").attr("stderr")); 50 | std::cerr << msg << std::flush; 51 | }); 52 | 53 | m.def("noisy_function", &noisy_function, py::arg("msg"), py::arg("flush") = true); 54 | 55 | m.def("dual_guard", &noisy_funct_dual, 56 | py::call_guard(), 57 | py::arg("msg"), py::arg("emsg")); 58 | 59 | m.def("raw_output", [](std::string msg) { 60 | std::cout << msg << std::flush; 61 | }); 62 | 63 | m.def("raw_err", [](std::string msg) { 64 | std::cerr << msg << std::flush; 65 | }); 66 | 67 | m.def("captured_dual", [](std::string msg, std::string emsg) { 68 | py::scoped_ostream_redirect redirout(std::cout, py::module::import("sys").attr("stdout")); 69 | py::scoped_ostream_redirect redirerr(std::cerr, py::module::import("sys").attr("stderr")); 70 | std::cout << msg << std::flush; 71 | std::cerr << emsg << std::flush; 72 | }); 73 | } 74 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_modules.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import modules as m 2 | from pybind11_tests.modules import subsubmodule as ms 3 | from pybind11_tests import ConstructorStats 4 | 5 | 6 | def test_nested_modules(): 7 | import pybind11_tests 8 | assert pybind11_tests.__name__ == "pybind11_tests" 9 | assert pybind11_tests.modules.__name__ == "pybind11_tests.modules" 10 | assert pybind11_tests.modules.subsubmodule.__name__ == "pybind11_tests.modules.subsubmodule" 11 | assert m.__name__ == "pybind11_tests.modules" 12 | assert ms.__name__ == "pybind11_tests.modules.subsubmodule" 13 | 14 | assert ms.submodule_func() == "submodule_func()" 15 | 16 | 17 | def test_reference_internal(): 18 | b = ms.B() 19 | assert str(b.get_a1()) == "A[1]" 20 | assert str(b.a1) == "A[1]" 21 | assert str(b.get_a2()) == "A[2]" 22 | assert str(b.a2) == "A[2]" 23 | 24 | b.a1 = ms.A(42) 25 | b.a2 = ms.A(43) 26 | assert str(b.get_a1()) == "A[42]" 27 | assert str(b.a1) == "A[42]" 28 | assert str(b.get_a2()) == "A[43]" 29 | assert str(b.a2) == "A[43]" 30 | 31 | astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B) 32 | assert astats.alive() == 2 33 | assert bstats.alive() == 1 34 | del b 35 | assert astats.alive() == 0 36 | assert bstats.alive() == 0 37 | assert astats.values() == ['1', '2', '42', '43'] 38 | assert bstats.values() == [] 39 | assert astats.default_constructions == 0 40 | assert bstats.default_constructions == 1 41 | assert astats.copy_constructions == 0 42 | assert bstats.copy_constructions == 0 43 | # assert astats.move_constructions >= 0 # Don't invoke any 44 | # assert bstats.move_constructions >= 0 # Don't invoke any 45 | assert astats.copy_assignments == 2 46 | assert bstats.copy_assignments == 0 47 | assert astats.move_assignments == 0 48 | assert bstats.move_assignments == 0 49 | 50 | 51 | def test_importing(): 52 | from pybind11_tests.modules import OD 53 | from collections import OrderedDict 54 | 55 | assert OD is OrderedDict 56 | assert str(OD([(1, 'a'), (2, 'b')])) == "OrderedDict([(1, 'a'), (2, 'b')])" 57 | 58 | 59 | def test_pydoc(): 60 | """Pydoc needs to be able to provide help() for everything inside a pybind11 module""" 61 | import pybind11_tests 62 | import pydoc 63 | 64 | assert pybind11_tests.__name__ == "pybind11_tests" 65 | assert pybind11_tests.__doc__ == "pybind11 test module" 66 | assert pydoc.text.docmodule(pybind11_tests) 67 | 68 | 69 | def test_duplicate_registration(): 70 | """Registering two things with the same name""" 71 | 72 | assert m.duplicate_registration() == [] 73 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_opaque_types.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_opaque_types.cpp -- opaque types, passing void pointers 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include "pybind11_tests.h" 11 | #include 12 | #include 13 | 14 | // IMPORTANT: Disable internal pybind11 translation mechanisms for STL data structures 15 | // 16 | // This also deliberately doesn't use the below StringList type alias to test 17 | // that MAKE_OPAQUE can handle a type containing a `,`. (The `std::allocator` 18 | // bit is just the default `std::vector` allocator). 19 | PYBIND11_MAKE_OPAQUE(std::vector>); 20 | 21 | using StringList = std::vector>; 22 | 23 | TEST_SUBMODULE(opaque_types, m) { 24 | // test_string_list 25 | py::class_(m, "StringList") 26 | .def(py::init<>()) 27 | .def("pop_back", &StringList::pop_back) 28 | /* There are multiple versions of push_back(), etc. Select the right ones. */ 29 | .def("push_back", (void (StringList::*)(const std::string &)) &StringList::push_back) 30 | .def("back", (std::string &(StringList::*)()) &StringList::back) 31 | .def("__len__", [](const StringList &v) { return v.size(); }) 32 | .def("__iter__", [](StringList &v) { 33 | return py::make_iterator(v.begin(), v.end()); 34 | }, py::keep_alive<0, 1>()); 35 | 36 | class ClassWithSTLVecProperty { 37 | public: 38 | StringList stringList; 39 | }; 40 | py::class_(m, "ClassWithSTLVecProperty") 41 | .def(py::init<>()) 42 | .def_readwrite("stringList", &ClassWithSTLVecProperty::stringList); 43 | 44 | m.def("print_opaque_list", [](const StringList &l) { 45 | std::string ret = "Opaque list: ["; 46 | bool first = true; 47 | for (auto entry : l) { 48 | if (!first) 49 | ret += ", "; 50 | ret += entry; 51 | first = false; 52 | } 53 | return ret + "]"; 54 | }); 55 | 56 | // test_pointers 57 | m.def("return_void_ptr", []() { return (void *) 0x1234; }); 58 | m.def("get_void_ptr_value", [](void *ptr) { return reinterpret_cast(ptr); }); 59 | m.def("return_null_str", []() { return (char *) nullptr; }); 60 | m.def("get_null_str_value", [](char *ptr) { return reinterpret_cast(ptr); }); 61 | 62 | m.def("return_unique_ptr", []() -> std::unique_ptr { 63 | StringList *result = new StringList(); 64 | result->push_back("some value"); 65 | return std::unique_ptr(result); 66 | }); 67 | } 68 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_opaque_types.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from pybind11_tests import opaque_types as m 3 | from pybind11_tests import ConstructorStats, UserType 4 | 5 | 6 | def test_string_list(): 7 | lst = m.StringList() 8 | lst.push_back("Element 1") 9 | lst.push_back("Element 2") 10 | assert m.print_opaque_list(lst) == "Opaque list: [Element 1, Element 2]" 11 | assert lst.back() == "Element 2" 12 | 13 | for i, k in enumerate(lst, start=1): 14 | assert k == "Element {}".format(i) 15 | lst.pop_back() 16 | assert m.print_opaque_list(lst) == "Opaque list: [Element 1]" 17 | 18 | cvp = m.ClassWithSTLVecProperty() 19 | assert m.print_opaque_list(cvp.stringList) == "Opaque list: []" 20 | 21 | cvp.stringList = lst 22 | cvp.stringList.push_back("Element 3") 23 | assert m.print_opaque_list(cvp.stringList) == "Opaque list: [Element 1, Element 3]" 24 | 25 | 26 | def test_pointers(msg): 27 | living_before = ConstructorStats.get(UserType).alive() 28 | assert m.get_void_ptr_value(m.return_void_ptr()) == 0x1234 29 | assert m.get_void_ptr_value(UserType()) # Should also work for other C++ types 30 | assert ConstructorStats.get(UserType).alive() == living_before 31 | 32 | with pytest.raises(TypeError) as excinfo: 33 | m.get_void_ptr_value([1, 2, 3]) # This should not work 34 | assert msg(excinfo.value) == """ 35 | get_void_ptr_value(): incompatible function arguments. The following argument types are supported: 36 | 1. (arg0: capsule) -> int 37 | 38 | Invoked with: [1, 2, 3] 39 | """ # noqa: E501 line too long 40 | 41 | assert m.return_null_str() is None 42 | assert m.get_null_str_value(m.return_null_str()) is not None 43 | 44 | ptr = m.return_unique_ptr() 45 | assert "StringList" in repr(ptr) 46 | assert m.print_opaque_list(ptr) == "Opaque list: [some value]" 47 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_pickling.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from pybind11_tests import pickling as m 3 | 4 | try: 5 | import cPickle as pickle # Use cPickle on Python 2.7 6 | except ImportError: 7 | import pickle 8 | 9 | 10 | @pytest.mark.parametrize("cls_name", ["Pickleable", "PickleableNew"]) 11 | def test_roundtrip(cls_name): 12 | cls = getattr(m, cls_name) 13 | p = cls("test_value") 14 | p.setExtra1(15) 15 | p.setExtra2(48) 16 | 17 | data = pickle.dumps(p, 2) # Must use pickle protocol >= 2 18 | p2 = pickle.loads(data) 19 | assert p2.value() == p.value() 20 | assert p2.extra1() == p.extra1() 21 | assert p2.extra2() == p.extra2() 22 | 23 | 24 | @pytest.unsupported_on_pypy 25 | @pytest.mark.parametrize("cls_name", ["PickleableWithDict", "PickleableWithDictNew"]) 26 | def test_roundtrip_with_dict(cls_name): 27 | cls = getattr(m, cls_name) 28 | p = cls("test_value") 29 | p.extra = 15 30 | p.dynamic = "Attribute" 31 | 32 | data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL) 33 | p2 = pickle.loads(data) 34 | assert p2.value == p.value 35 | assert p2.extra == p.extra 36 | assert p2.dynamic == p.dynamic 37 | 38 | 39 | def test_enum_pickle(): 40 | from pybind11_tests import enums as e 41 | data = pickle.dumps(e.EOne, 2) 42 | assert e.EOne == pickle.loads(data) 43 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_tagbased_polymorphic.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import tagbased_polymorphic as m 2 | 3 | 4 | def test_downcast(): 5 | zoo = m.create_zoo() 6 | assert [type(animal) for animal in zoo] == [ 7 | m.Labrador, m.Dog, m.Chihuahua, m.Cat, m.Panther 8 | ] 9 | assert [animal.name for animal in zoo] == [ 10 | "Fido", "Ginger", "Hertzl", "Tiger", "Leo" 11 | ] 12 | zoo[1].sound = "woooooo" 13 | assert [dog.bark() for dog in zoo[:3]] == [ 14 | "Labrador Fido goes WOOF!", 15 | "Dog Ginger goes woooooo", 16 | "Chihuahua Hertzl goes iyiyiyiyiyi and runs in circles" 17 | ] 18 | assert [cat.purr() for cat in zoo[3:]] == ["mrowr", "mrrrRRRRRR"] 19 | zoo[0].excitement -= 1000 20 | assert zoo[0].excitement == 14000 21 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_union.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_class.cpp -- test py::class_ definitions and basic functionality 3 | 4 | Copyright (c) 2019 Roland Dreier 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include "pybind11_tests.h" 11 | 12 | TEST_SUBMODULE(union_, m) { 13 | union TestUnion { 14 | int value_int; 15 | unsigned value_uint; 16 | }; 17 | 18 | py::class_(m, "TestUnion") 19 | .def(py::init<>()) 20 | .def_readonly("as_int", &TestUnion::value_int) 21 | .def_readwrite("as_uint", &TestUnion::value_uint); 22 | } 23 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tests/test_union.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import union_ as m 2 | 3 | 4 | def test_union(): 5 | instance = m.TestUnion() 6 | 7 | instance.as_uint = 10 8 | assert instance.as_int == 10 9 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tools/FindCatch.cmake: -------------------------------------------------------------------------------- 1 | # - Find the Catch test framework or download it (single header) 2 | # 3 | # This is a quick module for internal use. It assumes that Catch is 4 | # REQUIRED and that a minimum version is provided (not EXACT). If 5 | # a suitable version isn't found locally, the single header file 6 | # will be downloaded and placed in the build dir: PROJECT_BINARY_DIR. 7 | # 8 | # This code sets the following variables: 9 | # CATCH_INCLUDE_DIR - path to catch.hpp 10 | # CATCH_VERSION - version number 11 | 12 | if(NOT Catch_FIND_VERSION) 13 | message(FATAL_ERROR "A version number must be specified.") 14 | elseif(Catch_FIND_REQUIRED) 15 | message(FATAL_ERROR "This module assumes Catch is not required.") 16 | elseif(Catch_FIND_VERSION_EXACT) 17 | message(FATAL_ERROR "Exact version numbers are not supported, only minimum.") 18 | endif() 19 | 20 | # Extract the version number from catch.hpp 21 | function(_get_catch_version) 22 | file(STRINGS "${CATCH_INCLUDE_DIR}/catch.hpp" version_line REGEX "Catch v.*" LIMIT_COUNT 1) 23 | if(version_line MATCHES "Catch v([0-9]+)\\.([0-9]+)\\.([0-9]+)") 24 | set(CATCH_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}" PARENT_SCOPE) 25 | endif() 26 | endfunction() 27 | 28 | # Download the single-header version of Catch 29 | function(_download_catch version destination_dir) 30 | message(STATUS "Downloading catch v${version}...") 31 | set(url https://github.com/philsquared/Catch/releases/download/v${version}/catch.hpp) 32 | file(DOWNLOAD ${url} "${destination_dir}/catch.hpp" STATUS status) 33 | list(GET status 0 error) 34 | if(error) 35 | message(FATAL_ERROR "Could not download ${url}") 36 | endif() 37 | set(CATCH_INCLUDE_DIR "${destination_dir}" CACHE INTERNAL "") 38 | endfunction() 39 | 40 | # Look for catch locally 41 | find_path(CATCH_INCLUDE_DIR NAMES catch.hpp PATH_SUFFIXES catch) 42 | if(CATCH_INCLUDE_DIR) 43 | _get_catch_version() 44 | endif() 45 | 46 | # Download the header if it wasn't found or if it's outdated 47 | if(NOT CATCH_VERSION OR CATCH_VERSION VERSION_LESS ${Catch_FIND_VERSION}) 48 | if(DOWNLOAD_CATCH) 49 | _download_catch(${Catch_FIND_VERSION} "${PROJECT_BINARY_DIR}/catch/") 50 | _get_catch_version() 51 | else() 52 | set(CATCH_FOUND FALSE) 53 | return() 54 | endif() 55 | endif() 56 | 57 | set(CATCH_FOUND TRUE) 58 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tools/check-style.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Script to check include/test code for common pybind11 code style errors. 4 | # 5 | # This script currently checks for 6 | # 7 | # 1. use of tabs instead of spaces 8 | # 2. MSDOS-style CRLF endings 9 | # 3. trailing spaces 10 | # 4. missing space between keyword and parenthesis, e.g.: for(, if(, while( 11 | # 5. Missing space between right parenthesis and brace, e.g. 'for (...){' 12 | # 6. opening brace on its own line. It should always be on the same line as the 13 | # if/while/for/do statement. 14 | # 15 | # Invoke as: tools/check-style.sh 16 | # 17 | 18 | check_style_errors=0 19 | IFS=$'\n' 20 | 21 | found="$( GREP_COLORS='mt=41' GREP_COLOR='41' grep $'\t' include tests/*.{cpp,py,h} docs/*.rst -rn --color=always )" 22 | if [ -n "$found" ]; then 23 | # The mt=41 sets a red background for matched tabs: 24 | echo -e '\033[31;01mError: found tab characters in the following files:\033[0m' 25 | check_style_errors=1 26 | echo "$found" | sed -e 's/^/ /' 27 | fi 28 | 29 | 30 | found="$( grep -IUlr $'\r' include tests/*.{cpp,py,h} docs/*.rst --color=always )" 31 | if [ -n "$found" ]; then 32 | echo -e '\033[31;01mError: found CRLF characters in the following files:\033[0m' 33 | check_style_errors=1 34 | echo "$found" | sed -e 's/^/ /' 35 | fi 36 | 37 | found="$(GREP_COLORS='mt=41' GREP_COLOR='41' grep '[[:blank:]]\+$' include tests/*.{cpp,py,h} docs/*.rst -rn --color=always )" 38 | if [ -n "$found" ]; then 39 | # The mt=41 sets a red background for matched trailing spaces 40 | echo -e '\033[31;01mError: found trailing spaces in the following files:\033[0m' 41 | check_style_errors=1 42 | echo "$found" | sed -e 's/^/ /' 43 | fi 44 | 45 | found="$(grep '\<\(if\|for\|while\|catch\)(\|){' include tests/*.{cpp,h} -rn --color=always)" 46 | if [ -n "$found" ]; then 47 | echo -e '\033[31;01mError: found the following coding style problems:\033[0m' 48 | check_style_errors=1 49 | echo "$found" | sed -e 's/^/ /' 50 | fi 51 | 52 | found="$(awk ' 53 | function prefix(filename, lineno) { 54 | return " \033[35m" filename "\033[36m:\033[32m" lineno "\033[36m:\033[0m" 55 | } 56 | function mark(pattern, string) { sub(pattern, "\033[01;31m&\033[0m", string); return string } 57 | last && /^\s*{/ { 58 | print prefix(FILENAME, FNR-1) mark("\\)\\s*$", last) 59 | print prefix(FILENAME, FNR) mark("^\\s*{", $0) 60 | last="" 61 | } 62 | { last = /(if|for|while|catch|switch)\s*\(.*\)\s*$/ ? $0 : "" } 63 | ' $(find include -type f) tests/*.{cpp,h} docs/*.rst)" 64 | if [ -n "$found" ]; then 65 | check_style_errors=1 66 | echo -e '\033[31;01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files:\033[0m' 67 | echo "$found" 68 | fi 69 | 70 | exit $check_style_errors 71 | -------------------------------------------------------------------------------- /tiny-tensorrt/pybind11/tools/libsize.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function, division 2 | import os 3 | import sys 4 | 5 | # Internal build script for generating debugging test .so size. 6 | # Usage: 7 | # python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the 8 | # size in it, then overwrites save.txt with the new size for future runs. 9 | 10 | if len(sys.argv) != 3: 11 | sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt") 12 | 13 | lib = sys.argv[1] 14 | save = sys.argv[2] 15 | 16 | if not os.path.exists(lib): 17 | sys.exit("Error: requested file ({}) does not exist".format(lib)) 18 | 19 | libsize = os.path.getsize(lib) 20 | 21 | print("------", os.path.basename(lib), "file size:", libsize, end='') 22 | 23 | if os.path.exists(save): 24 | with open(save) as sf: 25 | oldsize = int(sf.readline()) 26 | 27 | if oldsize > 0: 28 | change = libsize - oldsize 29 | if change == 0: 30 | print(" (no change)") 31 | else: 32 | print(" (change of {:+} bytes = {:+.2%})".format(change, change / oldsize)) 33 | else: 34 | print() 35 | 36 | with open(save, 'w') as sf: 37 | sf.write(str(libsize)) 38 | 39 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/async_logger.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // Fast asynchronous logger. 7 | // Uses pre allocated queue. 8 | // Creates a single back thread to pop messages from the queue and log them. 9 | // 10 | // Upon each log write the logger: 11 | // 1. Checks if its log level is enough to log the message 12 | // 2. Push a new copy of the message to a queue (or block the caller until 13 | // space is available in the queue) 14 | // Upon destruction, logs all remaining messages in the queue before 15 | // destructing.. 16 | 17 | #include "spdlog/logger.h" 18 | 19 | namespace spdlog { 20 | 21 | // Async overflow policy - block by default. 22 | enum class async_overflow_policy 23 | { 24 | block, // Block until message can be enqueued 25 | overrun_oldest // Discard oldest message in the queue if full when trying to 26 | // add new item. 27 | }; 28 | 29 | namespace details { 30 | class thread_pool; 31 | } 32 | 33 | class async_logger final : public std::enable_shared_from_this, public logger 34 | { 35 | friend class details::thread_pool; 36 | 37 | public: 38 | template 39 | async_logger(std::string logger_name, It begin, It end, std::weak_ptr tp, 40 | async_overflow_policy overflow_policy = async_overflow_policy::block) 41 | : logger(std::move(logger_name), begin, end) 42 | , thread_pool_(std::move(tp)) 43 | , overflow_policy_(overflow_policy) 44 | {} 45 | 46 | async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr tp, 47 | async_overflow_policy overflow_policy = async_overflow_policy::block); 48 | 49 | async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr tp, 50 | async_overflow_policy overflow_policy = async_overflow_policy::block); 51 | 52 | std::shared_ptr clone(std::string new_name) override; 53 | 54 | protected: 55 | void sink_it_(details::log_msg &msg) override; 56 | void flush_() override; 57 | 58 | void backend_log_(const details::log_msg &incoming_log_msg); 59 | void backend_flush_(); 60 | 61 | private: 62 | std::weak_ptr thread_pool_; 63 | async_overflow_policy overflow_policy_; 64 | }; 65 | } // namespace spdlog 66 | 67 | #ifdef SPDLOG_HEADER_ONLY 68 | #include "async_logger-inl.h" 69 | #endif 70 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/common-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include "spdlog/common.h" 8 | #endif 9 | 10 | namespace spdlog { 11 | namespace level { 12 | static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; 13 | 14 | static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; 15 | 16 | SPDLOG_INLINE string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT 17 | { 18 | return level_string_views[l]; 19 | } 20 | 21 | SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT 22 | { 23 | return short_level_names[l]; 24 | } 25 | 26 | SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT 27 | { 28 | int level = 0; 29 | for (const auto &level_str : level_string_views) 30 | { 31 | if (level_str == name) 32 | { 33 | return static_cast(level); 34 | } 35 | level++; 36 | } 37 | return level::off; 38 | } 39 | } // namespace level 40 | 41 | SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) 42 | : msg_(std::move(msg)) 43 | {} 44 | 45 | SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) 46 | { 47 | fmt::memory_buffer outbuf; 48 | fmt::format_system_error(outbuf, last_errno, msg); 49 | msg_ = fmt::to_string(outbuf); 50 | } 51 | 52 | SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT 53 | { 54 | return msg_.c_str(); 55 | } 56 | 57 | } // namespace spdlog 58 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/details/circular_q.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | // cirucal q view of std::vector. 5 | #pragma once 6 | 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | template 12 | class circular_q 13 | { 14 | public: 15 | using item_type = T; 16 | 17 | explicit circular_q(size_t max_items) 18 | : max_items_(max_items + 1) // one item is reserved as marker for full q 19 | , v_(max_items_) 20 | {} 21 | 22 | // push back, overrun (oldest) item if no room left 23 | void push_back(T &&item) 24 | { 25 | v_[tail_] = std::move(item); 26 | tail_ = (tail_ + 1) % max_items_; 27 | 28 | if (tail_ == head_) // overrun last item if full 29 | { 30 | head_ = (head_ + 1) % max_items_; 31 | ++overrun_counter_; 32 | } 33 | } 34 | 35 | // Pop item from front. 36 | // If there are no elements in the container, the behavior is undefined. 37 | void pop_front(T &popped_item) 38 | { 39 | popped_item = std::move(v_[head_]); 40 | head_ = (head_ + 1) % max_items_; 41 | } 42 | 43 | bool empty() 44 | { 45 | return tail_ == head_; 46 | } 47 | 48 | bool full() 49 | { 50 | // head is ahead of the tail by 1 51 | return ((tail_ + 1) % max_items_) == head_; 52 | } 53 | 54 | size_t overrun_counter() const 55 | { 56 | return overrun_counter_; 57 | } 58 | 59 | private: 60 | size_t max_items_; 61 | typename std::vector::size_type head_ = 0; 62 | typename std::vector::size_type tail_ = 0; 63 | 64 | std::vector v_; 65 | 66 | size_t overrun_counter_ = 0; 67 | }; 68 | } // namespace details 69 | } // namespace spdlog 70 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/details/console_globals.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/details/null_mutex.h" 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | 12 | struct console_mutex 13 | { 14 | using mutex_t = std::mutex; 15 | static mutex_t &mutex() 16 | { 17 | static mutex_t s_mutex; 18 | return s_mutex; 19 | } 20 | }; 21 | 22 | struct console_nullmutex 23 | { 24 | using mutex_t = null_mutex; 25 | static mutex_t &mutex() 26 | { 27 | static mutex_t s_mutex; 28 | return s_mutex; 29 | } 30 | }; 31 | } // namespace details 32 | } // namespace spdlog 33 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/details/file_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/common.h" 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | 12 | // Helper class for file sinks. 13 | // When failing to open a file, retry several times(5) with a delay interval(10 ms). 14 | // Throw spdlog_ex exception on errors. 15 | 16 | class file_helper 17 | { 18 | public: 19 | explicit file_helper() = default; 20 | 21 | file_helper(const file_helper &) = delete; 22 | file_helper &operator=(const file_helper &) = delete; 23 | ~file_helper(); 24 | 25 | void open(const filename_t &fname, bool truncate = false); 26 | void reopen(bool truncate); 27 | void flush(); 28 | void close(); 29 | void write(const fmt::memory_buffer &buf); 30 | size_t size() const; 31 | const filename_t &filename() const; 32 | static bool file_exists(const filename_t &fname); 33 | 34 | // 35 | // return file path and its extension: 36 | // 37 | // "mylog.txt" => ("mylog", ".txt") 38 | // "mylog" => ("mylog", "") 39 | // "mylog." => ("mylog.", "") 40 | // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") 41 | // 42 | // the starting dot in filenames is ignored (hidden files): 43 | // 44 | // ".mylog" => (".mylog". "") 45 | // "my_folder/.mylog" => ("my_folder/.mylog", "") 46 | // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") 47 | static std::tuple split_by_extension(const filename_t &fname); 48 | 49 | private: 50 | const int open_tries = 5; 51 | const int open_interval = 10; 52 | std::FILE *fd_{nullptr}; 53 | filename_t _filename; 54 | }; 55 | } // namespace details 56 | } // namespace spdlog 57 | 58 | #ifdef SPDLOG_HEADER_ONLY 59 | #include "file_helper-inl.h" 60 | #endif 61 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/details/log_msg-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include "spdlog/details/log_msg.h" 8 | #endif 9 | 10 | #include "spdlog/details/os.h" 11 | 12 | namespace spdlog { 13 | namespace details { 14 | 15 | SPDLOG_INLINE log_msg::log_msg(spdlog::source_loc loc, string_view_t logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) 16 | : logger_name(logger_name) 17 | , level(lvl) 18 | #ifndef SPDLOG_NO_DATETIME 19 | , time(os::now()) 20 | #endif 21 | 22 | #ifndef SPDLOG_NO_THREAD_ID 23 | , thread_id(os::thread_id()) 24 | #endif 25 | , source(loc) 26 | , payload(msg) 27 | {} 28 | 29 | SPDLOG_INLINE log_msg::log_msg(string_view_t logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) 30 | : log_msg(source_loc{}, logger_name, lvl, msg) 31 | {} 32 | 33 | } // namespace details 34 | } // namespace spdlog 35 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/details/log_msg.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/common.h" 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | struct log_msg 12 | { 13 | log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); 14 | log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg); 15 | log_msg(const log_msg &other) = default; 16 | 17 | const string_view_t logger_name; 18 | level::level_enum level{level::off}; 19 | log_clock::time_point time; 20 | size_t thread_id{0}; 21 | 22 | // wrapping the formatted text with color (updated by pattern_formatter). 23 | mutable size_t color_range_start{0}; 24 | mutable size_t color_range_end{0}; 25 | 26 | source_loc source; 27 | const string_view_t payload; 28 | }; 29 | } // namespace details 30 | } // namespace spdlog 31 | 32 | #ifdef SPDLOG_HEADER_ONLY 33 | #include "log_msg-inl.h" 34 | #endif 35 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/details/null_mutex.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | // null, no cost dummy "mutex" and dummy "atomic" int 8 | 9 | namespace spdlog { 10 | namespace details { 11 | struct null_mutex 12 | { 13 | void lock() {} 14 | void unlock() {} 15 | bool try_lock() 16 | { 17 | return true; 18 | } 19 | }; 20 | 21 | struct null_atomic_int 22 | { 23 | int value; 24 | null_atomic_int() = default; 25 | 26 | explicit null_atomic_int(int val) 27 | : value(val) 28 | {} 29 | 30 | int load(std::memory_order) const 31 | { 32 | return value; 33 | } 34 | 35 | void store(int val) 36 | { 37 | value = val; 38 | } 39 | }; 40 | 41 | } // namespace details 42 | } // namespace spdlog 43 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/details/periodic_worker-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include "spdlog/details/periodic_worker.h" 8 | #endif 9 | 10 | namespace spdlog { 11 | namespace details { 12 | 13 | SPDLOG_INLINE periodic_worker::periodic_worker(const std::function &callback_fun, std::chrono::seconds interval) 14 | { 15 | active_ = (interval > std::chrono::seconds::zero()); 16 | if (!active_) 17 | { 18 | return; 19 | } 20 | 21 | worker_thread_ = std::thread([this, callback_fun, interval]() { 22 | for (;;) 23 | { 24 | std::unique_lock lock(this->mutex_); 25 | if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; })) 26 | { 27 | return; // active_ == false, so exit this thread 28 | } 29 | callback_fun(); 30 | } 31 | }); 32 | } 33 | 34 | // stop the worker thread and join it 35 | SPDLOG_INLINE periodic_worker::~periodic_worker() 36 | { 37 | if (worker_thread_.joinable()) 38 | { 39 | { 40 | std::lock_guard lock(mutex_); 41 | active_ = false; 42 | } 43 | cv_.notify_one(); 44 | worker_thread_.join(); 45 | } 46 | } 47 | 48 | } // namespace details 49 | } // namespace spdlog 50 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/details/periodic_worker.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // periodic worker thread - periodically executes the given callback function. 7 | // 8 | // RAII over the owned thread: 9 | // creates the thread on construction. 10 | // stops and joins the thread on destruction (if the thread is executing a callback, wait for it to finish first). 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | namespace spdlog { 18 | namespace details { 19 | 20 | class periodic_worker 21 | { 22 | public: 23 | periodic_worker(const std::function &callback_fun, std::chrono::seconds interval); 24 | periodic_worker(const periodic_worker &) = delete; 25 | periodic_worker &operator=(const periodic_worker &) = delete; 26 | // stop the worker thread and join it 27 | ~periodic_worker(); 28 | 29 | private: 30 | bool active_; 31 | std::thread worker_thread_; 32 | std::mutex mutex_; 33 | std::condition_variable cv_; 34 | }; 35 | } // namespace details 36 | } // namespace spdlog 37 | 38 | #ifdef SPDLOG_HEADER_ONLY 39 | #include "periodic_worker-inl.h" 40 | #endif 41 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/details/synchronous_factory.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "registry.h" 7 | 8 | namespace spdlog { 9 | 10 | // Default logger factory- creates synchronous loggers 11 | class logger; 12 | 13 | struct synchronous_factory 14 | { 15 | template 16 | static std::shared_ptr create(std::string logger_name, SinkArgs &&... args) 17 | { 18 | auto sink = std::make_shared(std::forward(args)...); 19 | auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); 20 | details::registry::instance().initialize_logger(new_logger); 21 | return new_logger; 22 | } 23 | }; 24 | } // namespace spdlog -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/fmt/bundled/LICENSE.rst: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 - 2016, Victor Zverovich 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/fmt/fmt.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016-2018 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | 8 | // 9 | // Include a bundled header-only copy of fmtlib or an external one. 10 | // By default spdlog include its own copy. 11 | // 12 | 13 | #if !defined(SPDLOG_FMT_EXTERNAL) 14 | #ifdef SPDLOG_HEADER_ONLY 15 | #ifndef FMT_HEADER_ONLY 16 | #define FMT_HEADER_ONLY 17 | #endif 18 | #endif 19 | #ifndef FMT_USE_WINDOWS_H 20 | #define FMT_USE_WINDOWS_H 0 21 | #endif 22 | #include "bundled/core.h" 23 | #include "bundled/format.h" 24 | #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib 25 | #include "fmt/core.h" 26 | #include "fmt/format.h" 27 | #endif 28 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/fmt/ostr.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's ostream support 9 | // 10 | #if !defined(SPDLOG_FMT_EXTERNAL) 11 | #ifndef FMT_HEADER_ONLY 12 | #define FMT_HEADER_ONLY 13 | #endif 14 | #include "bundled/ostream.h" 15 | #include "fmt.h" 16 | #else 17 | #include 18 | #endif 19 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/formatter.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "fmt/fmt.h" 7 | #include "spdlog/details/log_msg.h" 8 | 9 | namespace spdlog { 10 | 11 | class formatter 12 | { 13 | public: 14 | virtual ~formatter() = default; 15 | virtual void format(const details::log_msg &msg, fmt::memory_buffer &dest) = 0; 16 | virtual std::unique_ptr clone() const = 0; 17 | }; 18 | } // namespace spdlog 19 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/base_sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include "spdlog/sinks/base_sink.h" 8 | #endif 9 | 10 | #include "spdlog/common.h" 11 | #include "spdlog/details/pattern_formatter.h" 12 | 13 | #include 14 | 15 | template 16 | SPDLOG_INLINE spdlog::sinks::base_sink::base_sink() 17 | : formatter_{details::make_unique()} 18 | {} 19 | 20 | template 21 | SPDLOG_INLINE spdlog::sinks::base_sink::base_sink(std::unique_ptr formatter) 22 | : formatter_{std::move(formatter)} 23 | {} 24 | 25 | template 26 | void SPDLOG_INLINE spdlog::sinks::base_sink::log(const details::log_msg &msg) 27 | { 28 | std::lock_guard lock(mutex_); 29 | sink_it_(msg); 30 | } 31 | 32 | template 33 | void SPDLOG_INLINE spdlog::sinks::base_sink::flush() 34 | { 35 | std::lock_guard lock(mutex_); 36 | flush_(); 37 | } 38 | 39 | template 40 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern(const std::string &pattern) 41 | { 42 | std::lock_guard lock(mutex_); 43 | set_pattern_(pattern); 44 | } 45 | 46 | template 47 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_formatter(std::unique_ptr sink_formatter) 48 | { 49 | std::lock_guard lock(mutex_); 50 | set_formatter_(std::move(sink_formatter)); 51 | } 52 | 53 | template 54 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern_(const std::string &pattern) 55 | { 56 | set_formatter_(details::make_unique(pattern)); 57 | } 58 | 59 | template 60 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_formatter_(std::unique_ptr sink_formatter) 61 | { 62 | formatter_ = std::move(sink_formatter); 63 | } 64 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/base_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | // 6 | // base sink templated over a mutex (either dummy or real) 7 | // concrete implementation should override the sink_it_() and flush_() methods. 8 | // locking is taken care of in this class - no locking needed by the 9 | // implementers.. 10 | // 11 | 12 | #include "spdlog/common.h" 13 | #include "spdlog/details/log_msg.h" 14 | #include "spdlog/sinks/sink.h" 15 | 16 | namespace spdlog { 17 | namespace sinks { 18 | template 19 | class base_sink : public sink 20 | { 21 | public: 22 | base_sink(); 23 | explicit base_sink(std::unique_ptr formatter); 24 | base_sink(const base_sink &) = delete; 25 | base_sink &operator=(const base_sink &) = delete; 26 | void log(const details::log_msg &msg) final; 27 | void flush() final; 28 | void set_pattern(const std::string &pattern) final; 29 | void set_formatter(std::unique_ptr sink_formatter) final; 30 | 31 | protected: 32 | // sink formatter 33 | std::unique_ptr formatter_; 34 | Mutex mutex_; 35 | 36 | virtual void sink_it_(const details::log_msg &msg) = 0; 37 | virtual void flush_() = 0; 38 | virtual void set_pattern_(const std::string &pattern); 39 | virtual void set_formatter_(std::unique_ptr sink_formatter); 40 | }; 41 | } // namespace sinks 42 | } // namespace spdlog 43 | 44 | #ifdef SPDLOG_HEADER_ONLY 45 | #include "base_sink-inl.h" 46 | #endif 47 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/basic_file_sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include "spdlog/sinks/basic_file_sink.h" 8 | #endif 9 | 10 | #include "spdlog/common.h" 11 | #include "spdlog/details/os.h" 12 | 13 | namespace spdlog { 14 | namespace sinks { 15 | 16 | template 17 | SPDLOG_INLINE basic_file_sink::basic_file_sink(const filename_t &filename, bool truncate) 18 | { 19 | file_helper_.open(filename, truncate); 20 | } 21 | 22 | template 23 | SPDLOG_INLINE const filename_t &basic_file_sink::filename() const 24 | { 25 | return file_helper_.filename(); 26 | } 27 | 28 | template 29 | SPDLOG_INLINE void basic_file_sink::sink_it_(const details::log_msg &msg) 30 | { 31 | fmt::memory_buffer formatted; 32 | base_sink::formatter_->format(msg, formatted); 33 | file_helper_.write(formatted); 34 | } 35 | 36 | template 37 | SPDLOG_INLINE void basic_file_sink::flush_() 38 | { 39 | file_helper_.flush(); 40 | } 41 | 42 | } // namespace sinks 43 | } // namespace spdlog 44 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/basic_file_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/details/file_helper.h" 7 | #include "spdlog/details/null_mutex.h" 8 | #include "spdlog/sinks/base_sink.h" 9 | #include "spdlog/details/synchronous_factory.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | /* 17 | * Trivial file sink with single file as target 18 | */ 19 | template 20 | class basic_file_sink final : public base_sink 21 | { 22 | public: 23 | explicit basic_file_sink(const filename_t &filename, bool truncate = false); 24 | const filename_t &filename() const; 25 | 26 | protected: 27 | void sink_it_(const details::log_msg &msg) override; 28 | void flush_() override; 29 | 30 | private: 31 | details::file_helper file_helper_; 32 | }; 33 | 34 | using basic_file_sink_mt = basic_file_sink; 35 | using basic_file_sink_st = basic_file_sink; 36 | 37 | } // namespace sinks 38 | 39 | // 40 | // factory functions 41 | // 42 | template 43 | inline std::shared_ptr basic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false) 44 | { 45 | return Factory::template create(logger_name, filename, truncate); 46 | } 47 | 48 | template 49 | inline std::shared_ptr basic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false) 50 | { 51 | return Factory::template create(logger_name, filename, truncate); 52 | } 53 | 54 | } // namespace spdlog 55 | 56 | #ifdef SPDLOG_HEADER_ONLY 57 | #include "basic_file_sink-inl.h" 58 | #endif -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/dist_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "base_sink.h" 7 | #include "spdlog/details/log_msg.h" 8 | #include "spdlog/details/null_mutex.h" 9 | #include "spdlog/details/pattern_formatter.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // Distribution sink (mux). Stores a vector of sinks which get called when log 17 | // is called 18 | 19 | namespace spdlog { 20 | namespace sinks { 21 | 22 | template 23 | class dist_sink : public base_sink 24 | { 25 | public: 26 | dist_sink() = default; 27 | dist_sink(const dist_sink &) = delete; 28 | dist_sink &operator=(const dist_sink &) = delete; 29 | 30 | void add_sink(std::shared_ptr sink) 31 | { 32 | std::lock_guard lock(base_sink::mutex_); 33 | sinks_.push_back(sink); 34 | } 35 | 36 | void remove_sink(std::shared_ptr sink) 37 | { 38 | std::lock_guard lock(base_sink::mutex_); 39 | sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); 40 | } 41 | 42 | void set_sinks(std::vector> sinks) 43 | { 44 | std::lock_guard lock(base_sink::mutex_); 45 | sinks_ = std::move(sinks); 46 | } 47 | 48 | protected: 49 | void sink_it_(const details::log_msg &msg) override 50 | { 51 | for (auto &sink : sinks_) 52 | { 53 | if (sink->should_log(msg.level)) 54 | { 55 | sink->log(msg); 56 | } 57 | } 58 | } 59 | 60 | void flush_() override 61 | { 62 | for (auto &sink : sinks_) 63 | { 64 | sink->flush(); 65 | } 66 | } 67 | 68 | void set_pattern_(const std::string &pattern) override 69 | { 70 | set_formatter_(details::make_unique(pattern)); 71 | } 72 | 73 | void set_formatter_(std::unique_ptr sink_formatter) override 74 | { 75 | base_sink::formatter_ = std::move(sink_formatter); 76 | for (auto &sink : sinks_) 77 | { 78 | sink->set_formatter(base_sink::formatter_->clone()); 79 | } 80 | } 81 | std::vector> sinks_; 82 | }; 83 | 84 | using dist_sink_mt = dist_sink; 85 | using dist_sink_st = dist_sink; 86 | 87 | } // namespace sinks 88 | } // namespace spdlog 89 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/msvc_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2016 Alexander Dalshov. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #if defined(_WIN32) 7 | 8 | #include "spdlog/details/null_mutex.h" 9 | #include "spdlog/sinks/base_sink.h" 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace spdlog { 17 | namespace sinks { 18 | /* 19 | * MSVC sink (logging using OutputDebugStringA) 20 | */ 21 | template 22 | class msvc_sink : public base_sink 23 | { 24 | public: 25 | explicit msvc_sink() {} 26 | 27 | protected: 28 | void sink_it_(const details::log_msg &msg) override 29 | { 30 | 31 | fmt::memory_buffer formatted; 32 | base_sink::formatter_->format(msg, formatted); 33 | OutputDebugStringA(fmt::to_string(formatted).c_str()); 34 | } 35 | 36 | void flush_() override {} 37 | }; 38 | 39 | using msvc_sink_mt = msvc_sink; 40 | using msvc_sink_st = msvc_sink; 41 | 42 | using windebug_sink_mt = msvc_sink_mt; 43 | using windebug_sink_st = msvc_sink_st; 44 | 45 | } // namespace sinks 46 | } // namespace spdlog 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/null_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/details/null_mutex.h" 7 | #include "spdlog/sinks/base_sink.h" 8 | #include "spdlog/details/synchronous_factory.h" 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | 15 | template 16 | class null_sink : public base_sink 17 | { 18 | protected: 19 | void sink_it_(const details::log_msg &) override {} 20 | void flush_() override {} 21 | }; 22 | 23 | using null_sink_mt = null_sink; 24 | using null_sink_st = null_sink; 25 | 26 | } // namespace sinks 27 | 28 | template 29 | inline std::shared_ptr null_logger_mt(const std::string &logger_name) 30 | { 31 | auto null_logger = Factory::template create(logger_name); 32 | null_logger->set_level(level::off); 33 | return null_logger; 34 | } 35 | 36 | template 37 | inline std::shared_ptr null_logger_st(const std::string &logger_name) 38 | { 39 | auto null_logger = Factory::template create(logger_name); 40 | null_logger->set_level(level::off); 41 | return null_logger; 42 | } 43 | 44 | } // namespace spdlog 45 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/ostream_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/details/null_mutex.h" 7 | #include "spdlog/sinks/base_sink.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | template 15 | class ostream_sink final : public base_sink 16 | { 17 | public: 18 | explicit ostream_sink(std::ostream &os, bool force_flush = false) 19 | : ostream_(os) 20 | , force_flush_(force_flush) 21 | {} 22 | ostream_sink(const ostream_sink &) = delete; 23 | ostream_sink &operator=(const ostream_sink &) = delete; 24 | 25 | protected: 26 | void sink_it_(const details::log_msg &msg) override 27 | { 28 | fmt::memory_buffer formatted; 29 | base_sink::formatter_->format(msg, formatted); 30 | ostream_.write(formatted.data(), static_cast(formatted.size())); 31 | if (force_flush_) 32 | { 33 | ostream_.flush(); 34 | } 35 | } 36 | 37 | void flush_() override 38 | { 39 | ostream_.flush(); 40 | } 41 | 42 | std::ostream &ostream_; 43 | bool force_flush_; 44 | }; 45 | 46 | using ostream_sink_mt = ostream_sink; 47 | using ostream_sink_st = ostream_sink; 48 | 49 | } // namespace sinks 50 | } // namespace spdlog 51 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/rotating_file_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/sinks/base_sink.h" 7 | #include "spdlog/details/file_helper.h" 8 | #include "spdlog/details/null_mutex.h" 9 | #include "spdlog/details/synchronous_factory.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace spdlog { 16 | namespace sinks { 17 | 18 | // 19 | // Rotating file sink based on size 20 | // 21 | template 22 | class rotating_file_sink final : public base_sink 23 | { 24 | public: 25 | rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false); 26 | static filename_t calc_filename(const filename_t &filename, std::size_t index); 27 | const filename_t &filename() const; 28 | 29 | protected: 30 | void sink_it_(const details::log_msg &msg) override; 31 | void flush_() override; 32 | 33 | private: 34 | // Rotate files: 35 | // log.txt -> log.1.txt 36 | // log.1.txt -> log.2.txt 37 | // log.2.txt -> log.3.txt 38 | // log.3.txt -> delete 39 | void rotate_(); 40 | 41 | // delete the target if exists, and rename the src file to target 42 | // return true on success, false otherwise. 43 | bool rename_file(const filename_t &src_filename, const filename_t &target_filename); 44 | 45 | filename_t base_filename_; 46 | std::size_t max_size_; 47 | std::size_t max_files_; 48 | std::size_t current_size_; 49 | details::file_helper file_helper_; 50 | }; 51 | 52 | using rotating_file_sink_mt = rotating_file_sink; 53 | using rotating_file_sink_st = rotating_file_sink; 54 | 55 | } // namespace sinks 56 | 57 | // 58 | // factory functions 59 | // 60 | 61 | template 62 | inline std::shared_ptr rotating_logger_mt( 63 | const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files, bool rotate_on_open = false) 64 | { 65 | return Factory::template create(logger_name, filename, max_file_size, max_files, rotate_on_open); 66 | } 67 | 68 | template 69 | inline std::shared_ptr rotating_logger_st( 70 | const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files, bool rotate_on_open = false) 71 | { 72 | return Factory::template create(logger_name, filename, max_file_size, max_files, rotate_on_open); 73 | } 74 | } // namespace spdlog 75 | 76 | #ifdef SPDLOG_HEADER_ONLY 77 | #include "rotating_file_sink-inl.h" 78 | #endif -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include "spdlog/sinks/sink.h" 8 | #endif 9 | 10 | #include "spdlog/common.h" 11 | 12 | SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const 13 | { 14 | return msg_level >= level_.load(std::memory_order_relaxed); 15 | } 16 | 17 | SPDLOG_INLINE void spdlog::sinks::sink::set_level(level::level_enum log_level) 18 | { 19 | level_.store(log_level, std::memory_order_relaxed); 20 | } 21 | 22 | SPDLOG_INLINE spdlog::level::level_enum spdlog::sinks::sink::level() const 23 | { 24 | return static_cast(level_.load(std::memory_order_relaxed)); 25 | } 26 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/details/log_msg.h" 7 | #include "spdlog/formatter.h" 8 | 9 | namespace spdlog { 10 | 11 | namespace sinks { 12 | class sink 13 | { 14 | public: 15 | virtual ~sink() = default; 16 | virtual void log(const details::log_msg &msg) = 0; 17 | virtual void flush() = 0; 18 | virtual void set_pattern(const std::string &pattern) = 0; 19 | virtual void set_formatter(std::unique_ptr sink_formatter) = 0; 20 | 21 | void set_level(level::level_enum log_level); 22 | level::level_enum level() const; 23 | bool should_log(level::level_enum msg_level) const; 24 | 25 | protected: 26 | // sink log level - default is all 27 | level_t level_{level::trace}; 28 | }; 29 | 30 | } // namespace sinks 31 | } // namespace spdlog 32 | 33 | #ifdef SPDLOG_HEADER_ONLY 34 | #include "sink-inl.h" 35 | #endif 36 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/stdout_color_sinks-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include "spdlog/sinks/stdout_color_sinks.h" 8 | #endif 9 | 10 | #include "spdlog/logger.h" 11 | #include "spdlog/common.h" 12 | 13 | namespace spdlog { 14 | 15 | template 16 | SPDLOG_INLINE std::shared_ptr stdout_color_mt(const std::string &logger_name, color_mode mode) 17 | { 18 | return Factory::template create(logger_name, mode); 19 | } 20 | 21 | template 22 | SPDLOG_INLINE std::shared_ptr stdout_color_st(const std::string &logger_name, color_mode mode) 23 | { 24 | return Factory::template create(logger_name, mode); 25 | } 26 | 27 | template 28 | SPDLOG_INLINE std::shared_ptr stderr_color_mt(const std::string &logger_name, color_mode mode) 29 | { 30 | return Factory::template create(logger_name, mode); 31 | } 32 | 33 | template 34 | SPDLOG_INLINE std::shared_ptr stderr_color_st(const std::string &logger_name, color_mode mode) 35 | { 36 | return Factory::template create(logger_name, mode); 37 | } 38 | } // namespace spdlog -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/stdout_color_sinks.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifdef _WIN32 7 | #include "spdlog/sinks/wincolor_sink.h" 8 | #else 9 | #include "spdlog/sinks/ansicolor_sink.h" 10 | #endif 11 | 12 | #include "spdlog/details/synchronous_factory.h" 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | #ifdef _WIN32 17 | using stdout_color_sink_mt = wincolor_stdout_sink_mt; 18 | using stdout_color_sink_st = wincolor_stdout_sink_st; 19 | using stderr_color_sink_mt = wincolor_stderr_sink_mt; 20 | using stderr_color_sink_st = wincolor_stderr_sink_st; 21 | #else 22 | using stdout_color_sink_mt = ansicolor_stdout_sink_mt; 23 | using stdout_color_sink_st = ansicolor_stdout_sink_st; 24 | using stderr_color_sink_mt = ansicolor_stderr_sink_mt; 25 | using stderr_color_sink_st = ansicolor_stderr_sink_st; 26 | #endif 27 | } // namespace sinks 28 | 29 | template 30 | std::shared_ptr stdout_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic); 31 | 32 | template 33 | std::shared_ptr stdout_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic); 34 | 35 | template 36 | std::shared_ptr stderr_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic); 37 | 38 | template 39 | std::shared_ptr stderr_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic); 40 | 41 | } // namespace spdlog 42 | 43 | #ifdef SPDLOG_HEADER_ONLY 44 | #include "stdout_color_sinks-inl.h" 45 | #endif 46 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/sinks/stdout_sinks.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "spdlog/details/console_globals.h" 7 | #include "spdlog/details/synchronous_factory.h" 8 | #include "spdlog/sinks/sink.h" 9 | #include 10 | 11 | namespace spdlog { 12 | 13 | namespace sinks { 14 | 15 | template 16 | class stdout_sink_base : public sink 17 | { 18 | public: 19 | using mutex_t = typename ConsoleMutex::mutex_t; 20 | explicit stdout_sink_base(FILE *file); 21 | ~stdout_sink_base() override = default; 22 | stdout_sink_base(const stdout_sink_base &other) = delete; 23 | stdout_sink_base &operator=(const stdout_sink_base &other) = delete; 24 | 25 | void log(const details::log_msg &msg) override; 26 | void flush() override; 27 | void set_pattern(const std::string &pattern) override; 28 | 29 | void set_formatter(std::unique_ptr sink_formatter) override; 30 | 31 | protected: 32 | mutex_t &mutex_; 33 | FILE *file_; 34 | std::unique_ptr formatter_; 35 | }; 36 | 37 | template 38 | class stdout_sink : public stdout_sink_base 39 | { 40 | public: 41 | stdout_sink(); 42 | }; 43 | 44 | template 45 | class stderr_sink : public stdout_sink_base 46 | { 47 | public: 48 | stderr_sink(); 49 | }; 50 | 51 | using stdout_sink_mt = stdout_sink; 52 | using stdout_sink_st = stdout_sink; 53 | 54 | using stderr_sink_mt = stderr_sink; 55 | using stderr_sink_st = stderr_sink; 56 | 57 | } // namespace sinks 58 | 59 | // factory methods 60 | template 61 | std::shared_ptr stdout_logger_mt(const std::string &logger_name); 62 | 63 | template 64 | std::shared_ptr stdout_logger_st(const std::string &logger_name); 65 | 66 | template 67 | std::shared_ptr stderr_logger_mt(const std::string &logger_name); 68 | 69 | template 70 | std::shared_ptr stderr_logger_st(const std::string &logger_name); 71 | 72 | } // namespace spdlog 73 | 74 | #include "stdout_sinks-inl.h" 75 | -------------------------------------------------------------------------------- /tiny-tensorrt/spdlog/version.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define SPDLOG_VER_MAJOR 1 7 | #define SPDLOG_VER_MINOR 4 8 | #define SPDLOG_VER_PATCH 0 9 | 10 | #define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH) 11 | --------------------------------------------------------------------------------