static PyObject *roc_for_far(PyObject *, PyObject *args, PyObject *kwds) { BOB_TRY /* Parses input arguments in a single shot */ char **kwlist = roc_for_far_doc.kwlist(); PyBlitzArrayObject *neg; PyBlitzArrayObject *pos; PyBlitzArrayObject *far; PyObject *is_sorted = Py_False; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O&O&O&|O", kwlist, &double1d_converter, &neg, &double1d_converter, &pos, &double1d_converter, &far, &is_sorted)) return 0; // protects acquired resources through this scope auto neg_ = make_safe(neg); auto pos_ = make_safe(pos); auto far_ = make_safe(far); auto result = bob::measure::roc_for_far( *PyBlitzArrayCxx_AsBlitz<double, 1>(neg), *PyBlitzArrayCxx_AsBlitz<double, 1>(pos), *PyBlitzArrayCxx_AsBlitz<double, 1>(far), PyObject_IsTrue(is_sorted)); return PyBlitzArrayCxx_AsNumpy(result); BOB_CATCH_FUNCTION("roc_for_far", 0) }
static PyObject *precision_recall_curve(PyObject *, PyObject *args, PyObject *kwds) { BOB_TRY char **kwlist = precision_recall_curve_doc.kwlist(); PyBlitzArrayObject *neg; PyBlitzArrayObject *pos; Py_ssize_t n_points; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&n", kwlist, &double1d_converter, &neg, &double1d_converter, &pos, &n_points)) return 0; // protects acquired resources through this scope auto neg_ = make_safe(neg); auto pos_ = make_safe(pos); auto result = bob::measure::precision_recall_curve( *PyBlitzArrayCxx_AsBlitz<double, 1>(neg), *PyBlitzArrayCxx_AsBlitz<double, 1>(pos), n_points); return PyBlitzArrayCxx_AsNumpy(result); BOB_CATCH_FUNCTION("precision_recall_curve", 0) }
static PyObject *epc(PyObject *, PyObject *args, PyObject *kwds) { BOB_TRY /* Parses input arguments in a single shot */ char **kwlist = epc_doc.kwlist(); PyBlitzArrayObject *dev_neg; PyBlitzArrayObject *dev_pos; PyBlitzArrayObject *test_neg; PyBlitzArrayObject *test_pos; Py_ssize_t n_points; PyObject *is_sorted = Py_False; PyObject *thresholds = Py_False; if (!PyArg_ParseTupleAndKeywords( args, kwds, "O&O&O&O&n|OO", kwlist, &double1d_converter, &dev_neg, &double1d_converter, &dev_pos, &double1d_converter, &test_neg, &double1d_converter, &test_pos, &n_points, &is_sorted, &thresholds)) return 0; // protects acquired resources through this scope auto dev_neg_ = make_safe(dev_neg); auto dev_pos_ = make_safe(dev_pos); auto test_neg_ = make_safe(test_neg); auto test_pos_ = make_safe(test_pos); auto result = bob::measure::epc(*PyBlitzArrayCxx_AsBlitz<double, 1>(dev_neg), *PyBlitzArrayCxx_AsBlitz<double, 1>(dev_pos), *PyBlitzArrayCxx_AsBlitz<double, 1>(test_neg), *PyBlitzArrayCxx_AsBlitz<double, 1>(test_pos), n_points, PyObject_IsTrue(is_sorted), PyObject_IsTrue(thresholds)); return PyBlitzArrayCxx_AsNumpy(result); BOB_CATCH_FUNCTION("epc", 0) }
static PyObject *correctly_classified_positives(PyObject *, PyObject *args, PyObject *kwds) { BOB_TRY static char **kwlist = correctly_classified_positives_doc.kwlist(); PyBlitzArrayObject *pos; double threshold; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&d", kwlist, &double1d_converter, &pos, &threshold)) return 0; // protects acquired resources through this scope auto pos_ = make_safe(pos); auto result = bob::measure::correctlyClassifiedPositives( *PyBlitzArrayCxx_AsBlitz<double, 1>(pos), threshold); return PyBlitzArrayCxx_AsNumpy(result); BOB_CATCH_FUNCTION("correctly_classified_positives", 0) }
static PyObject* PyBobIpFlandmark_locate(PyBobIpFlandmarkObject* self, PyObject *args, PyObject* kwds) { BOB_TRY char** kwlist = s_locate.kwlist(); PyBlitzArrayObject* image; int bbx[4]; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&iiii", kwlist, &PyBlitzArray_Converter, &image, &bbx[0], &bbx[1], &bbx[2], &bbx[3])) return 0; // create bounding box in format (top, left, bottom, right) bbx[2] += bbx[0] - 1; bbx[3] += bbx[1] - 1; auto image_ = make_safe(image); // check if (image->type_num != NPY_UINT8 || image->ndim != 2) { PyErr_Format(PyExc_TypeError, "`%s' input `image' data must be a 2D array with dtype `uint8' (i.e. a gray-scaled image), but you passed a %" PY_FORMAT_SIZE_T "d array with data type `%s'", Py_TYPE(self)->tp_name, image->ndim, PyBlitzArray_TypenumAsString(image->type_num)); return 0; } // detect std::vector<double> detected(2*self->flandmark->data.options.M); bob::ip::flandmark::flandmark_detect(*PyBlitzArrayCxx_AsBlitz<uint8_t, 2>(image), bbx, self->flandmark, &detected[0]); // extract landmarks blitz::Array<double, 2> landmarks(self->flandmark->data.options.M, 2); for (int k = 0; k < self->flandmark->data.options.M; ++k){ landmarks(k,0) = detected[2*k]; landmarks(k,1) = detected[2*k+1]; } return PyBlitzArrayCxx_AsNumpy(landmarks); BOB_CATCH_MEMBER("locate", 0) }; static PyMethodDef PyBobIpFlandmark_methods[] = { { s_locate.name(), (PyCFunction)PyBobIpFlandmark_locate, METH_VARARGS|METH_KEYWORDS, s_locate.doc() }, {0} /* Sentinel */ }; PyObject* PyBobIpFlandmark_Repr(PyBobIpFlandmarkObject* self) { /** * Expected output: * * <bob.ip.flandmark(model='...')> */ PyObject* retval = PyUnicode_FromFormat("<%s(model='%s')>", Py_TYPE(self)->tp_name, self->filename); #if PYTHON_VERSION_HEX < 0x03000000 if (!retval) return 0; PyObject* tmp = PyObject_Str(retval); Py_DECREF(retval); retval = tmp; #endif return retval; }