用于模型转换、序列化、加载等的机器学习实用程序

ml2rt的Python项目详细描述


用于模型转换、序列化、加载等的机器学习实用程序

  • 免费软件:apache软件许可证2.0

安装

pip install ml2rt

文档

ml2rt提供了一些方便的功能来转换、保存和加载机器学习模型。它目前支持tensorflow、pytorch、sklearn、spark和onnx,但xgboost、coreml等框架正在开发中。

保存tensorflow模型

importtensorflowastffromml2rtimportsave_tensorflow# train your model heresess=tf.Session()save_tensorflow(sess,path,output=['output'])

保存pytorch模型

# it has to be a torchscript graph made by tracing / scriptingfromml2rtimportsave_torchsave_torch(torch_script_graph,path)

在NX型号上保存

fromml2rtimportsave_onnxsave_onnx(onnx_model,path)

保存sklearn模型

fromml2rtimportsave_sklearnprototype=np.array(some_shape,dtype=some_dtype)# Equivalent to the input of the modelsave_sklearn(sklearn_model,path,prototype=prototype)# or# some_shape has to be a tuple and some_dtype has to be a np.dtype, np.dtype.type or str objectsave_sklearn(sklearn_model,path,shape=some_shape,dtype=some_dtype)# or# some_shape has to be a tuple and some_dtype has to be a np.dtype, np.dtype.type or str objectinital_types=utils.guess_onnx_tensortype(shape=shape,dtype=dtype)save_sklearn(sklearn_model,path,initial_types=initial_types)

保存SPARKML模型

fromml2rtimportsave_sparkmlprototype=np.array(some_shape,dtype=some_dtype)# Equivalent to the input of the modelsave_sparkml(spark_model,path,prototype=prototype)# or# some_shape has to be a tuple and some_dtype has to be a np.dtype, np.dtype.type or str objectsave_sparkml(spark_model,path,shape=some_shape,dtype=some_dtype)# or# some_shape has to be a tuple and some_dtype has to be a np.dtype, np.dtype.type or str objectinital_types=utils.guess_onnx_tensortype(shape=shape,dtype=dtype)save_sparkml(spark_model,path,initial_types=initial_types)

sklearn和sparkml模型将首先转换为onnx,然后保存到磁盘。这些模型可以使用onnxruntime、redisai等执行。onnx转换需要知道输入节点的类型,因此我们必须传递shape&dtype或原型,从中实用程序可以推断shape&dtype或转换实用程序可以理解的初始类型对象。像sparkml这样的框架允许用户拥有具有多个类型的异构输入。在这种情况下,请使用guess onnx_tensortypes并创建一个以上的初始类型,这些类型可以传递给save function as a list

加载模型和脚本

model=ml2rt.load_model(path)script=ml2rt.load_script(script)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaEclipseMars没有保存首选项   java梯度同步失败:原因:启动失败:   java如何从嵌套的JSON获取数据?   java如何判断可观察对象中的任何对象满足一个条件?   java将字符串转换为保持相同值的byte[]数组   java有没有办法绕过AuditingEntityListener为测试设置数据?   从/usr/share/java中解析linux JAR依赖关系   安卓 My java函数抛出nullpointerexception?   java Gradle使用正确版本的依赖项   JBoss和Java6中带注释的WebService中的web服务ClassCastException   java如何修复codename one中的简单逻辑错误?   java如何迭代矩阵的索引?   java如何在JPanel不可见时将其保存为图像?   java HashMap如何在Kotlin中实现MutableMap接口?   javascript如何在单击后加载特定片段?   EclipseJava为纳什均衡获取所有玩家/策略组合   JavaSpring:Web服务REST在JSON上产生双反斜杠   java为什么ServletContext#getRealPath(“/”)返回相对路径?   java当我的游戏应该重新启动时,我应该如何处理重置SurfaceView和线程?