From 9e4dc5404ca896bd305689dc51d4c5bfefaa6130 Mon Sep 17 00:00:00 2001 From: Oleksandr Bezdieniezhnykh Date: Tue, 12 Aug 2025 14:53:14 +0300 Subject: [PATCH] remove cpdef, add constants h --- Azaion.Inference/constants_inf.h | 55 ++++++++++++++++++++++++++++ Azaion.Inference/inference.pxd | 4 +- Azaion.Inference/inference.pyx | 4 +- Azaion.Inference/onnx_engine.pyx | 6 +-- Azaion.Inference/tensorrt_engine.pxd | 6 +-- Azaion.Inference/tensorrt_engine.pyx | 6 +-- 6 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 Azaion.Inference/constants_inf.h diff --git a/Azaion.Inference/constants_inf.h b/Azaion.Inference/constants_inf.h new file mode 100644 index 0000000..620b985 --- /dev/null +++ b/Azaion.Inference/constants_inf.h @@ -0,0 +1,55 @@ +/* Generated by Cython 3.1.2 */ + +#ifndef __PYX_HAVE__constants_inf +#define __PYX_HAVE__constants_inf + +#include "Python.h" + +#ifndef __PYX_HAVE_API__constants_inf + +#ifdef CYTHON_EXTERN_C + #undef __PYX_EXTERN_C + #define __PYX_EXTERN_C CYTHON_EXTERN_C +#elif defined(__PYX_EXTERN_C) + #ifdef _MSC_VER + #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.") + #else + #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead. + #endif +#else + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#ifndef DL_IMPORT + #define DL_IMPORT(_T) _T +#endif + +__PYX_EXTERN_C int TILE_DUPLICATE_CONFIDENCE_THRESHOLD; + +#endif /* !__PYX_HAVE_API__constants_inf */ + +/* WARNING: the interface of the module init function changed in CPython 3.5. */ +/* It now returns a PyModuleDef instance instead of a PyModule instance. */ + +/* WARNING: Use PyImport_AppendInittab("constants_inf", PyInit_constants_inf) instead of calling PyInit_constants_inf directly from Python 3.5 */ +PyMODINIT_FUNC PyInit_constants_inf(void); + +#if PY_VERSION_HEX >= 0x03050000 && (defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) || (defined(__cplusplus) && __cplusplus >= 201402L)) +#if defined(__cplusplus) && __cplusplus >= 201402L +[[deprecated("Use PyImport_AppendInittab(\"constants_inf\", PyInit_constants_inf) instead of calling PyInit_constants_inf directly.")]] inline +#elif defined(__GNUC__) || defined(__clang__) +__attribute__ ((__deprecated__("Use PyImport_AppendInittab(\"constants_inf\", PyInit_constants_inf) instead of calling PyInit_constants_inf directly."), __unused__)) __inline__ +#elif defined(_MSC_VER) +__declspec(deprecated("Use PyImport_AppendInittab(\"constants_inf\", PyInit_constants_inf) instead of calling PyInit_constants_inf directly.")) __inline +#endif +static PyObject* __PYX_WARN_IF_PyInit_constants_inf_INIT_CALLED(PyObject* res) { + return res; +} +#define PyInit_constants_inf() __PYX_WARN_IF_PyInit_constants_inf_INIT_CALLED(PyInit_constants_inf()) +#endif + +#endif /* !__PYX_HAVE__constants_inf */ diff --git a/Azaion.Inference/inference.pxd b/Azaion.Inference/inference.pxd index 781c08a..5799b22 100644 --- a/Azaion.Inference/inference.pxd +++ b/Azaion.Inference/inference.pxd @@ -20,7 +20,7 @@ cdef class Inference: cdef int tile_height cdef build_tensor_engine(self, object updater_callback) - cpdef init_ai(self) + cdef init_ai(self) cdef bint is_building_engine cdef bint is_video(self, str filepath) @@ -28,7 +28,7 @@ cdef class Inference: cdef _process_video(self, RemoteCommand cmd, AIRecognitionConfig ai_config, str video_name) cdef _process_images(self, RemoteCommand cmd, AIRecognitionConfig ai_config, list[str] image_paths) cdef _process_images_inner(self, RemoteCommand cmd, AIRecognitionConfig ai_config, list frame_data) - cpdef split_to_tiles(self, frame, path, overlap_percent) + cdef split_to_tiles(self, frame, path, overlap_percent) cdef stop(self) cdef preprocess(self, frames) diff --git a/Azaion.Inference/inference.pyx b/Azaion.Inference/inference.pyx index 05ddc48..083b86b 100644 --- a/Azaion.Inference/inference.pyx +++ b/Azaion.Inference/inference.pyx @@ -97,7 +97,7 @@ cdef class Inference: except Exception as e: updater_callback(f'Error. {str(e)}') - cpdef init_ai(self): + cdef init_ai(self): if self.engine is not None: return @@ -292,7 +292,7 @@ cdef class Inference: self._process_images_inner(cmd, ai_config, chunk) - cpdef split_to_tiles(self, frame, path, overlap_percent): + cdef split_to_tiles(self, frame, path, overlap_percent): constants_inf.log(f'splitting image {path} to tiles...') img_h, img_w, _ = frame.shape stride_w = int(self.tile_width * (1 - overlap_percent / 100)) diff --git a/Azaion.Inference/onnx_engine.pyx b/Azaion.Inference/onnx_engine.pyx index 15ddd1b..cc64f4c 100644 --- a/Azaion.Inference/onnx_engine.pyx +++ b/Azaion.Inference/onnx_engine.pyx @@ -15,12 +15,12 @@ cdef class OnnxEngine(InferenceEngine): model_meta = self.session.get_modelmeta() constants_inf.log(f"Metadata: {model_meta.custom_metadata_map}") - cpdef tuple get_input_shape(self): + cdef tuple get_input_shape(self): shape = self.input_shape return shape[2], shape[3] - cpdef int get_batch_size(self): + cdef int get_batch_size(self): return self.batch_size - cpdef run(self, input_data): + cdef run(self, input_data): return self.session.run(None, {self.input_name: input_data}) \ No newline at end of file diff --git a/Azaion.Inference/tensorrt_engine.pxd b/Azaion.Inference/tensorrt_engine.pxd index 6fc31bd..5c0f565 100644 --- a/Azaion.Inference/tensorrt_engine.pxd +++ b/Azaion.Inference/tensorrt_engine.pxd @@ -17,8 +17,8 @@ cdef class TensorRTEngine(InferenceEngine): cdef object stream - cpdef tuple get_input_shape(self) + cdef tuple get_input_shape(self) - cpdef int get_batch_size(self) + cdef int get_batch_size(self) - cpdef run(self, input_data) + cdef run(self, input_data) diff --git a/Azaion.Inference/tensorrt_engine.pyx b/Azaion.Inference/tensorrt_engine.pyx index c792340..a0a03e7 100644 --- a/Azaion.Inference/tensorrt_engine.pyx +++ b/Azaion.Inference/tensorrt_engine.pyx @@ -112,13 +112,13 @@ cdef class TensorRTEngine(InferenceEngine): constants_inf.log('conversion done!') return bytes(plan) - cpdef tuple get_input_shape(self): + cdef tuple get_input_shape(self): return self.input_shape[2], self.input_shape[3] - cpdef int get_batch_size(self): + cdef int get_batch_size(self): return self.batch_size - cpdef run(self, input_data): + cdef run(self, input_data): try: cuda.memcpy_htod_async(self.d_input, input_data, self.stream) self.context.set_tensor_address(self.input_name, int(self.d_input)) # input buffer