From c021841a52a7b71224b755bfbf779b05012b59d5 Mon Sep 17 00:00:00 2001
From: Tino Hager <tino.hager@nager.at>
Date: Tue, 10 Jul 2018 19:46:14 +0000
Subject: [PATCH] Get gpu count and name
---
src/yolo_v2_class.cpp | 64 ++++++++++++++++++++++++++++++++
1 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/src/yolo_v2_class.cpp b/src/yolo_v2_class.cpp
index 03d581a..64f2afc 100644
--- a/src/yolo_v2_class.cpp
+++ b/src/yolo_v2_class.cpp
@@ -22,6 +22,66 @@
#define FRAMES 3
+//static Detector* detector = NULL;
+static std::unique_ptr<Detector> detector;
+
+int init(const char *configurationFilename, const char *weightsFilename, int gpu)
+{
+ detector.reset(new Detector(configurationFilename, weightsFilename, gpu));
+ return 1;
+}
+
+int detect_image(const char *filename, bbox_t_container &container)
+{
+ std::vector<bbox_t> detection = detector->detect(filename);
+ for (size_t i = 0; i < detection.size() && i < C_SHARP_MAX_OBJECTS; ++i)
+ container.candidates[i] = detection[i];
+ return detection.size();
+}
+
+int detect_mat(const uint8_t* data, const size_t data_length, bbox_t_container &container) {
+#ifdef OPENCV
+ std::vector<char> vdata(data, data + data_length);
+ cv::Mat image = imdecode(cv::Mat(vdata), 1);
+
+ std::vector<bbox_t> detection = detector->detect(image);
+ for (size_t i = 0; i < detection.size() && i < C_SHARP_MAX_OBJECTS; ++i)
+ container.candidates[i] = detection[i];
+ return detection.size();
+#else
+ return -1;
+#endif // OPENCV
+}
+
+int dispose() {
+ //if (detector != NULL) delete detector;
+ //detector = NULL;
+ detector.reset();
+ return 1;
+}
+
+int get_device_count() {
+#ifdef GPU
+ int count = 0;
+ cudaGetDeviceCount(&count);
+ return count;
+#else
+ return -1;
+#endif // GPU
+}
+
+int get_device_name(int gpu, char* deviceName) {
+#ifdef GPU
+ cudaDeviceProp prop;
+ cudaGetDeviceProperties(&prop, gpu);
+ std::string result = prop.name;
+ std::copy(result.begin(), result.end(), deviceName);
+ return 1;
+#else
+ return -1;
+#endif // GPU
+}
+
#ifdef GPU
void check_cuda(cudaError_t status) {
if (status != cudaSuccess) {
@@ -119,6 +179,10 @@
detector_gpu_t &detector_gpu = *static_cast<detector_gpu_t *>(detector_gpu_ptr.get());
return detector_gpu.net.h;
}
+YOLODLL_API int Detector::get_net_color_depth() const {
+ detector_gpu_t &detector_gpu = *static_cast<detector_gpu_t *>(detector_gpu_ptr.get());
+ return detector_gpu.net.c;
+}
YOLODLL_API std::vector<bbox_t> Detector::detect(std::string image_filename, float thresh, bool use_mean)
--
Gitblit v1.10.0