| | |
| | | YOLODLL_API Detector::Detector(std::string cfg_filename, std::string weight_filename, int gpu_id) |
| | | { |
| | | int old_gpu_index; |
| | | #ifdef GPU |
| | | cudaGetDevice(&old_gpu_index); |
| | | #endif |
| | | |
| | | detector_gpu_ptr = std::make_shared<detector_gpu_t>(); |
| | | detector_gpu_t &detector_gpu = *reinterpret_cast<detector_gpu_t *>(detector_gpu_ptr.get()); |
| | | |
| | | #ifdef GPU |
| | | cudaSetDevice(gpu_id); |
| | | #endif |
| | | network &net = detector_gpu.net; |
| | | net.gpu_index = gpu_id; |
| | | //gpu_index = i; |
| | |
| | | detector_gpu.probs = (float **)calloc(l.w*l.h*l.n, sizeof(float *)); |
| | | for (j = 0; j < l.w*l.h*l.n; ++j) detector_gpu.probs[j] = (float *)calloc(l.classes, sizeof(float)); |
| | | |
| | | #ifdef GPU |
| | | cudaSetDevice(old_gpu_index); |
| | | #endif |
| | | } |
| | | |
| | | |
| | |
| | | free(detector_gpu.probs); |
| | | |
| | | int old_gpu_index; |
| | | #ifdef GPU |
| | | cudaGetDevice(&old_gpu_index); |
| | | cudaSetDevice(detector_gpu.net.gpu_index); |
| | | #endif |
| | | |
| | | free_network(detector_gpu.net); |
| | | |
| | | #ifdef GPU |
| | | cudaSetDevice(old_gpu_index); |
| | | #endif |
| | | } |
| | | |
| | | YOLODLL_API int Detector::get_net_width() { |
| | | detector_gpu_t &detector_gpu = *reinterpret_cast<detector_gpu_t *>(detector_gpu_ptr.get()); |
| | | return detector_gpu.net.w; |
| | | } |
| | | YOLODLL_API int Detector::get_net_height() { |
| | | detector_gpu_t &detector_gpu = *reinterpret_cast<detector_gpu_t *>(detector_gpu_ptr.get()); |
| | | return detector_gpu.net.h; |
| | | } |
| | | |
| | | |
| | |
| | | detector_gpu_t &detector_gpu = *reinterpret_cast<detector_gpu_t *>(detector_gpu_ptr.get()); |
| | | network &net = detector_gpu.net; |
| | | int old_gpu_index; |
| | | #ifdef GPU |
| | | cudaGetDevice(&old_gpu_index); |
| | | cudaSetDevice(net.gpu_index); |
| | | #endif |
| | | //std::cout << "net.gpu_index = " << net.gpu_index << std::endl; |
| | | |
| | | //float nms = .4; |
| | |
| | | im.h = img.h; |
| | | im.w = img.w; |
| | | |
| | | image sized = resize_image(im, net.w, net.h); |
| | | image sized; |
| | | |
| | | if (net.w == im.w && net.h == im.h) { |
| | | sized = make_image(im.w, im.h, im.c); |
| | | memcpy(sized.data, im.data, im.w*im.h*im.c * sizeof(float)); |
| | | } |
| | | else |
| | | sized = resize_image(im, net.w, net.h); |
| | | |
| | | layer l = net.layers[net.n - 1]; |
| | | |
| | | float *X = sized.data; |
| | |
| | | if(sized.data) |
| | | free(sized.data); |
| | | |
| | | #ifdef GPU |
| | | cudaSetDevice(old_gpu_index); |
| | | #endif |
| | | |
| | | return bbox_vec; |
| | | } |