| 137 | // ---------------------------------------------------------------------------------------- |
| 138 | |
| 139 | void bind_cnn_face_detection(py::module& m) |
| 140 | { |
| 141 | { |
| 142 | py::class_<cnn_face_detection_model_v1>(m, "cnn_face_detection_model_v1", "This object detects human faces in an image. The constructor loads the face detection model from a file. You can download a pre-trained model from http://dlib.net/files/mmod_human_face_detector.dat.bz2.") |
| 143 | .def(py::init<std::string>(), py::arg("filename")) |
| 144 | .def( |
| 145 | "__call__", |
| 146 | &cnn_face_detection_model_v1::detect_mult, |
| 147 | py::arg("imgs"), py::arg("upsample_num_times")=0, py::arg("batch_size")=128, |
| 148 | "takes a list of images as input returning a 2d list of mmod rectangles" |
| 149 | ) |
| 150 | .def( |
| 151 | "__call__", |
| 152 | &cnn_face_detection_model_v1::detect, |
| 153 | py::arg("img"), py::arg("upsample_num_times")=0, |
| 154 | "Find faces in an image using a deep learning model.\n\ |
| 155 | - Upsamples the image upsample_num_times before running the face \n\ |
| 156 | detector." |
| 157 | ); |
| 158 | } |
| 159 | |
| 160 | m.def("set_dnn_prefer_smallest_algorithms", &set_dnn_prefer_smallest_algorithms, "Tells cuDNN to use slower algorithms that use less RAM."); |
| 161 | |
| 162 | auto cuda = m.def_submodule("cuda", "Routines for setting CUDA specific properties."); |
| 163 | cuda.def("set_device", &dlib::cuda::set_device, py::arg("device_id"), |
| 164 | "Set the active CUDA device. It is required that 0 <= device_id < get_num_devices()."); |
| 165 | cuda.def("get_device", &dlib::cuda::get_device, "Get the active CUDA device."); |
| 166 | cuda.def("get_num_devices", &dlib::cuda::get_num_devices, "Find out how many CUDA devices are available."); |
| 167 | |
| 168 | { |
| 169 | typedef mmod_rect type; |
| 170 | py::class_<type>(m, "mmod_rectangle", "Wrapper around a rectangle object and a detection confidence score.") |
| 171 | .def_readwrite("rect", &type::rect) |
| 172 | .def_readwrite("confidence", &type::detection_confidence); |
| 173 | } |
| 174 | { |
| 175 | typedef std::vector<mmod_rect> type; |
| 176 | py::bind_vector<type>(m, "mmod_rectangles", "An array of mmod rectangle objects.") |
| 177 | .def("extend", extend_vector_with_python_list<mmod_rect>); |
| 178 | } |
| 179 | { |
| 180 | typedef std::vector<std::vector<mmod_rect> > type; |
| 181 | py::bind_vector<type>(m, "mmod_rectangless", "A 2D array of mmod rectangle objects.") |
| 182 | .def("extend", extend_vector_with_python_list<std::vector<mmod_rect>>); |
| 183 | } |
| 184 | } |