一. 图像编辑器 Monica
Monica 是一款跨平台的桌面图像编辑软件,使用 Kotlin Compose Desktop 作为 UI 框架。应用层使用 Kotlin 编写,基于 mvvm 架构,使用 koin 作为依赖注入框架。
大部分算法也是用 Kotlin 编写,少部分通过 jni 调用 OpenCV C++ 实现的图像处理或调用深度学习的模型。
Monica 目前还处于开发阶段,当前版本的可以参见 github 地址:https://github.com/fengzhizi715/Monica
二. ONNX Runtime 部署模型
ONNX Runtime 是一个高性能的推理引擎,专门用于加速和优化基于 ONNX(Open Neural Network Exchange)模型格式的机器学习模型的推理。ONNX 是一个开源的中间表示格式,它可以使不同深度学习框架(如 PyTorch、TensorFlow 等)的模型互相转换并在不同的硬件平台上运行。
ONNX Runtime 常用于部署和推理阶段,能够快速高效地运行机器学习模型。
ONNX Runtime 在 mac 下可以通过 brew 或者直接下载源码的方式进行安装。我采用直接下载源码,这样可以安装我想要的版本。
在 cmake 做如下配置即可使用 ONNX Runtime
# 指定ONNX Runtime的路径
set(ONNXRUNTIME_ROOT "/Users/Tony/onnxruntime/onnxruntime-osx-x86_64-1.10.0")
# 包含ONNX Runtime头文件
include_directories(${ONNXRUNTIME_ROOT}/include/)
# 查找ONNX Runtime库文件
find_library(ONNXRUNTIME_LIBS onnx-runtime PATHS ${ONNXRUNTIME_ROOT}/lib)
target_link_libraries(MonicaImageProcess ${ONNXRUNTIME_ROOT}/lib/libonnxruntime.1.10.0.dylib)
安装完成后,先封装一个比较通用的 OnnxRuntimeBase 类,下面是 OnnxRuntimeBase.h
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <vector>
#include <onnxruntime_cxx_api.h>
#include <onnxruntime_c_api.h>
class OnnxRuntimeBase
{
public:
OnnxRuntimeBase(std::string modelPath, const char* logId, const char* provider);
~OnnxRuntimeBase();
virtual std::vector<Ort::Value> forward(Ort::Value& inputTensors);
protected:
Ort::Env env;
Ort::Session ort_session{ nullptr };
Ort::SessionOptions sessionOptions = Ort::SessionOptions();
std::vector<char*> input_names;
std::vector<char*> output_names;
std::vector<std::vector<int64_t>> input_node_dims; // >=1 outputs
std::vector<std::vector<int