选自GitHub
还在为机器学习模型打包成 API 发愁? 这个工具能让你一行代码直接打包。
自动定义:Cortex 可以自动定义需要负责生产工作的 API;
多框架支持:Cortex 支持多种机器学习框架,包括 TensorFlow、PyTorch、scikit-learn、XGBoost 等;
CPU/GPU 支持:Cortex 能够在 CPU 或者 GPU 上进行推理工作;
回滚式更新:Cortex 可以对部署的 API 直接更新;
日志流:Cortex 会保留部署模型的日志流,并在 CLI 上显示;
预测监控:Cortex 能够监控网络的评价指标,并追踪预测结果;
最小配置:部署时,用户只需要在一个名为 cortex.yaml 的文件中配置相关属性。
# predictor.pymodel = download_my_model()def predict(sample, metadata):return model.predict(sample["text"])
# cortex.yaml- kind: deploymentname: sentiment- kind: apiname: classifierpredictor:path: predictor.pytracker:model_type: classificationcompute:gpu: 1
$ cortex deploycreating classifier (http://***.amazonaws.com/sentiment/classifier)
$ curl http://***.amazonaws.com/sentiment/classifier \-X POST -H "Content-Type: application/json" \-d '{"text": "the movie was great!"}'positive
cortex get classifier --watchstatus up-to-date available requested last update avg latencylive 1 1 1 8s 123msclass countpositive 8negative 4
基于 TensorFlow 和 BERT 进行情感分析:https://github.com/cortexlabs/cortex/tree/0.10/examples/tensorflow/sentiment-analysis
基于 TensorFlow 和 Inception 模型进行图像分类:https://github.com/cortexlabs/cortex/tree/0.10/examples/tensorflow/image-classifier
基于 PyTorch 和 DistilGPT2 进行文本生成:https://github.com/cortexlabs/cortex/tree/0.10/examples/pytorch/text-generator
基于 XGBoost / ONNX 进行虹膜分类:https://github.com/cortexlabs/cortex/tree/0.10/examples/xgboost/iris-classifier
# handler.pyimport tensorflow as tfimport tensorflow_hub as hubfrom bert import tokenization, run_classifierlabels = ["negative", "positive"]with tf.Graph().as_default():bert_module = hub.Module("https://tfhub.dev/google/bert_uncased_L-12_H-768_A-12/1")info = bert_module(signature="tokenization_info", as_dict=True)with tf.Session() as sess:vocab_file, do_lower_case = sess.run([info["vocab_file"], info["do_lower_case"]])tokenizer = tokenization.FullTokenizer(vocab_file=vocab_file, do_lower_case=do_lower_case)def pre_inference(sample, signature, metadata):input_example = run_classifier.InputExample(guid="", text_a=sample["review"], label=0)input_feature = run_classifier.convert_single_example(0, input_example, [0, 1], 128, tokenizer)return {"input_ids": [input_feature.input_ids]}def post_inference(prediction, signature, metadata):return labels[prediction["labels"][0]]
# cortex.yaml- kind: deploymentname: sentiment- kind: apiname: classifiertensorflow:model: s3://cortex-examples/tensorflow/sentiment-analysis/bertrequest_handler: handler.pytracker:model_type: classification
cortex deploydeployment started
$ cortex get classifier --watchstatus up-to-date available requested last update avg latencylive 1 1 1 8s
$ cortex get classifierurl: http://***.amazonaws.com/sentiment/classifier$ curl http://***.amazonaws.com/sentiment/classifier \-X POST -H "Content-Type: application/json" \-d '{"review": "The movie was great!"}'"positive
第三届机器之心「Synced Machine Intelligence Awards」年度奖项评选正在进行中。本次评选设置六大奖项,重点关注人工智能公司的产品、应用案例和产业落地情况,基于真实客观的产业表现筛选出最值得关注的企业,为行业带来实际的参考价值。