为Heartex或Label Studio部署机器学习

pyheartex的Python项目详细描述


皮哈特克斯

Python接口,用于运行ML后端服务器并在Heartex platform内使用它进行主动学习和预标记和预测

安装

首先确保你已经运行了Redis server(否则你只能使用预测,不能使用主动学习)。在

安装Heartex SDK:

git clone https://github.com/heartexlabs/pyheartex.git
cd pyheartex/
pip install -r requirements.txt
pip install -e .

你应该做的最后一件事是在后台启动RQ workers:

^{pr2}$

使用Docker

下面是如何开始提供图像分类器的示例:

cd examples/docker
docker-compose up

您需要用自己的模型替换的只是从this file更改加载、推理和训练脚本。在

快速入门

快速入门指南提供了以下Heartex平台中流行的机器学习框架的用法:

Scikit学习

让我们为文本分类提供scikit-learn模型。在

你可以简单地启动

python examples/quickstart.py

这个脚本看起来像

fromhtx.adapters.sklearnimportservefromsklearn.feature_extraction.textimportTfidfVectorizerfromsklearn.linear_modelimportLogisticRegressionfromsklearn.pipelineimportmake_pipelineif__name__=="__main__":# Creating sklearn-compatible modelmy_model=make_pipeline(TfidfVectorizer(),LogisticRegression())# Start serving this modelserve(my_model)

它开始在http://localhost:16118监听Heartex事件。 若要连接模型,请转到Heartex->设置->机器学习页面,然后选择“添加自定义模型”。在

也可以使用Heartex API激活模型:

curl -X POST -H 'Content-Type: application/json'\
-H 'Authorization: Token <PUT-YOUR-TOKEN-HERE>'\
-d '[{"url": "$HOST:$PORT", "name": "my_model", "title": "My model", "description": "My new model deployed on Heartex"}]'\
http://go.heartex.net/api/projects/{project-id}/backends/

其中$HOST:$PORT是您的服务器URL,应该可以从外部访问。在

法斯泰

您可以像scikit learn一样集成FastAI模型。 检查this example以了解如何插入可更新的图像分类器。在

高级用法

当您想超越使用sklearn兼容的API时,您可以通过手动进行输入/输出接口转换来构建自己的模型。 必须按如下方式将Heartex模型子类化:

fromhtx.base_modelimportBaseModel# This class exposes methods needed to handle model in the runtime (loading into memory, running predictions)classMyModel(BaseModel):defget_input(self,task):"""Extract input from serialized task"""passdefget_output(self,task):"""Extract output from serialized task"""passdefload(self,train_output):"""Loads model into memory. `train_output` dict is actually the output the `train` method (see below)"""passdefpredict(self,tasks):"""Get list of tasks, already processed by `get_input` method, and returns completions in Heartex format"""pass# This method handles model retrainingdeftrain(input_tasks,output_model_dir,**kwargs):"""    :param input_tasks: list of tasks already processed by `get_input`    :param output_model_dir: output directory where you can optionally store model resources    :param kwargs: any additional kwargs taken from `train_kwargs`    :return: `train_output` dict for consequent model loading    """pass

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

推荐PyPI第三方库


热门话题
java从JSP或HTML向servlet发送多个参数   java方法来查看字符是否在字符数组中   使用带有java的MAC地址连接到设备   java如何将csv文件中的数据打印到secondactivity?   java如何从netbean 7.0.1连接到数据库   java考虑所有可能的类值,用于输出测试分割的预测值。   java我的actionListener调用有什么问题   swing在Java中实现粒子过滤器最有效的方法是什么?   java运行。getFontFamily()为返回null。使用apachepoi的docx文件   一个事务中的java领域循环与每个步骤循环中的一个事务   java日期格式与Spring Boot不兼容   java类冲突。处理   java GridBagLayout不工作   java将图像发送到另一个应用程序