ModelScope 是由阿里巴巴達摩院開發的開源統一機器學習框架,基於"模型即服務"(Model-as-a-Service, MaaS)的理念構建。該項目旨在將 AI 社區中最先進的機器學習模型整合在一起,簡化在實際應用中利用 AI 模型的过程。
項目地址: https://github.com/modelscope/modelscope
ModelScope 基於"模型即服務"(MaaS)的核心理念,致力於:
提供官方 Docker 鏡像,包括:
pip install modelscope
# 多模態模型
pip install modelscope[multi-modal]
# 自然語言處理
pip install modelscope[nlp]
# 計算機視覺
pip install modelscope[cv]
# 語音處理
pip install modelscope[audio]
# 科學計算
pip install modelscope[science]
# 中文分詞
from modelscope.pipelines import pipeline
word_segmentation = pipeline('word-segmentation',
model='damo/nlp_structbert_word-segmentation_chinese-base')
result = word_segmentation('今天天氣不錯,適合出去遊玩')
print(result) # {'output': '今天 天氣 不錯 , 適合 出去 游玩'}
# 人像摳圖
import cv2
from modelscope.pipelines import pipeline
portrait_matting = pipeline('portrait-matting')
result = portrait_matting('image_url')
cv2.imwrite('result.png', result['output_img'])
from modelscope.metainfo import Trainers
from modelscope.msdatasets import MsDataset
from modelscope.trainers import build_trainer
# 加載數據集
train_dataset = MsDataset.load('chinese-poetry-collection', split='train')
eval_dataset = MsDataset.load('chinese-poetry-collection', split='test')
# 配置訓練參數
kwargs = dict(
model='damo/nlp_gpt3_text-generation_1.3B',
train_dataset=train_dataset,
eval_dataset=eval_dataset,
max_epochs=10,
work_dir='./gpt3_poetry'
)
# 構建訓練器並開始訓練
trainer = build_trainer(name=Trainers.gpt3_trainer, default_args=kwargs)
trainer.train()
ModelScope 是一個功能強大、易於使用的統一機器學習框架,通過"模型即服務"的理念,為開發者提供了一個完整的 AI 模型生態系統。無論是初學者還是專業開發者,都能通過 ModelScope 快速構建和部署 AI 應用,推動 AI 技術的普及和應用。