ModelScope

1.35.3 · active · verified Fri Apr 10

ModelScope is an open-source model-as-a-service (MaaS) platform from Alibaba Damo Academy, providing a wide range of AI models (vision, NLP, audio, multimodal) for easy deployment and use. It abstracts complex AI model inference into a simple API and offers functionalities for model discovery, download, and fine-tuning. The library is actively developed, with its current version at 1.35.3 and frequent releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use ModelScope to perform image classification using a pre-trained model. It initializes a `pipeline` for a specific task and model, then processes an input image from a URL. Models are automatically downloaded and cached locally upon first use. For tasks requiring authentication (e.g., uploading to the Hub or accessing private models), ensure your ModelScope token is set via `os.environ['MS_TOKEN']` or passed explicitly.

import os
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

# Initialize an image classification pipeline
classifier = pipeline(task=Tasks.image_classification, model='damo/cv_resnest50_image-classification_damo')

# Example input image URL
image_url = 'https://modelscope.cn/api/v1/models/damo/cv_resnest50_image-classification_damo/repo/files/animal.JPEG'

# Perform inference
result = classifier(image_url)
print(f"Image classification result: {result}")

# You can also download a model first
# from modelscope.hub.snapshot_download import snapshot_download
# model_dir = snapshot_download('damo/cv_resnest50_image-classification_damo')
# local_classifier = pipeline(task=Tasks.image_classification, model=model_dir)
# print(f"Local inference result: {local_classifier(image_url)}")

view raw JSON →