Package: modelscope
English|中文|日本語IntroductionModelScopeis built upon the notion of “Model-as-a-Service” (MaaS). It seeks to bring together most advanced machine learning models from the AI community, and streamlines the process of leveraging AI models in real-world applications. The core ModelScope library open-sourced in this repository provides the interfaces and implementations that allow developers to perform  model inference, training and evaluation.In particular, with rich layers of API-abstraction, the ModelScope library offers unified experience to explore state-of-the-art models spanning across domains such as CV, NLP, Speech, Multi-Modality, and Scientific-computation. Model contributors of different areas can integrate models into the ModelScope ecosystem through the layered-APIs, allowing easy and unified access to their models. Once integrated, model inference, fine-tuning, and evaluations can be done with only a few lines of codes. In the meantime, flexibilities are also provided so that different components in the model applications can be customized wherever necessary.Apart from harboring implementations of a wide range of different models, ModelScope library also enables the necessary interactions with ModelScope backend services, particularly with the Model-Hub and Dataset-Hub. Such interactions facilitate management of  various entities (models and datasets) to be performed seamlessly under-the-hood, including entity lookup, version control, cache management, and many others.Models and Online AccessibilityHundreds of models are made publicly available onModelScope(700+ and counting), covering the latest development in areas such as NLP, CV, Audio, Multi-modality, and AI for Science, etc. Many of these models represent the SOTA in their specific fields, and made their open-sourced debut on ModelScope. Users can visit ModelScope(modelscope.cn) and experience first-hand how these models perform via online experience, with just a few clicks. Immediate developer-experience is also possible through the ModelScope Notebook, which is backed by ready-to-use CPU/GPU development environment in the cloud - only one click away onModelScope.Some representative examples include:NLP:ChatGLM3-6BQwen-14B-ChatBaichuan2-13B-ChatZiya2-13B-ChatInternlm-chat-20bUdever Multilingual Universal Text Representation Model 1b1CoROM Text Vector - Chinese - E-commerce Domain - BaseMGeo Address Similarity Matching Entity Alignment - Chinese - Address Field - BaseMulti-Modal:Qwen-VL-ChatCogVLMText-to-Video Synthesis Large Model - English - General DomainI2VGen-XL High Definition Image to Video Large ModelI2VGen-XL High Definition Video to Video Large ModelCV:DamoFD Face Detection Key Point Model - 0.5GBSHM Portrait MattingDCT-Net Portrait Cartoonization - 3DDCT-Net Portrait Cartoonization Model - 3DDuGuang - Text Recognition - Line Recognition Model - Chinese and English - General DomainDuGuang - Text Recognition - Line Recognition Model - Chinese and English - General DomainLaMa Image InpaintingAudio:Paraformer Speech Recognition - Chinese - General - 16k - Offline - Large - Long Audio VersionFSMN Voice Endpoint Detection - Chinese - General - 16k - onnxMonotonic-Aligner Speech Timestamp Prediction - 16k - OfflineCT-Transformer Punctuation - Chinese - General - onnxSpeech Synthesis - Chinese - Multiple Emotions Domain - 16k - Multiple SpeakersCAM++ Speaker Verification - Chinese - General - 200k-SpkrsAI for Science:uni-fold-monomeruni-fold-multimerNote:Most models on ModelScope are public and can be downloaded without account registration on modelscope website(www.modelscope.cn), please refer to instructions formodel download, for dowloading models with api provided by modelscope library or git.QuickTourWe provide unified interface for inference usingpipeline, fine-tuning and evaluation usingTrainerfor different tasks.For any given task with any type of input (image, text, audio, video...), inference pipeline can be implemented with only a few lines of code, which will automatically load the underlying model to get inference result, as is exemplified below:>>>frommodelscope.pipelinesimportpipeline>>>word_segmentation=pipeline('word-segmentation',model='damo/nlp_structbert_word-segmentation_chinese-base')>>>word_segmentation('今天天气不错，适合出去游玩'){'output':'今天 天气 不错 ， 适合 出去 游玩'}Given an image, portrait matting (aka. background-removal) can be accomplished with the following code snippet:>>>importcv2>>>frommodelscope.pipelinesimportpipeline>>>portrait_matting=pipeline('portrait-matting')>>>result=portrait_matting('https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_matting.png')>>>cv2.imwrite('result.png',result['output_img'])The output image with the background removed is:Fine-tuning and evaluation can also be done with a few more lines of code to set up training dataset and trainer, with the heavy-lifting work of training and evaluation a model encapsulated in the implementation oftraner.train()andtrainer.evaluate()interfaces.For example, the gpt3 base model (1.3B) can be fine-tuned with the chinese-poetry dataset, resulting in a model that can be used for chinese-poetry generation.>>>frommodelscope.metainfoimportTrainers>>>frommodelscope.msdatasetsimportMsDataset>>>frommodelscope.trainersimportbuild_trainer>>>train_dataset=MsDataset.load('chinese-poetry-collection',split='train').remap_columns({'text1':'src_txt'})>>>eval_dataset=MsDataset.load('chinese-poetry-collection',split='test').remap_columns({'text1':'src_txt'})>>>max_epochs=10>>>tmp_dir='./gpt3_poetry'>>>kwargs=dict(model='damo/nlp_gpt3_text-generation_1.3B',train_dataset=train_dataset,eval_dataset=eval_dataset,max_epochs=max_epochs,work_dir=tmp_dir)>>>trainer=build_trainer(name=Trainers.gpt3_trainer,default_args=kwargs)>>>trainer.train()Why should I use ModelScope libraryA unified and concise user interface is abstracted for different tasks and different models. Model inferences and training can be implemented by as few as 3 and 10 lines of code, respectively. It is convenient for users to explore models in different fields in the ModelScope community. All models integrated into ModelScope are ready to use, which makes it easy to get started with AI, in both educational and industrial settings.ModelScope offers a model-centric development and application experience. It streamlines the support for model training, inference, export and deployment, and facilitates users to build their own MLOps based on the ModelScope ecosystem.For the model inference and training process, a modular design is put in place, and a wealth of functional module implementations are provided, which is convenient for users to customize their own model inference, training and other processes.For distributed model training, especially for large models, it provides rich training strategy support, including data parallel, model parallel, hybrid parallel and so on.InstallationDockerModelScope Library currently supports popular deep learning framework for model training and inference, including PyTorch, TensorFlow and ONNX. All releases are tested and run on Python 3.7+, Pytorch 1.8+, Tensorflow1.15 or Tensorflow2.0+.To allow out-of-box usage for all the models on ModelScope, official docker images are provided for all releases. Based on the docker image, developers can skip all environment installation and configuration and use it directly. Currently, the latest version of the CPU image and GPU image can be obtained from:CPU docker image# py37registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-1.6.1# py38registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch2.0.1-tf2.13.0-1.9.5GPU docker image# py37registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-1.6.1# py38registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.8.0-py38-torch2.0.1-tf2.13.0-1.9.5Setup Local Python EnvironmentOne can also set up local ModelScope environment using pip and conda.  ModelScope supports python3.7 and above.
We suggestanacondafor creating local python environment:condacreate-nmodelscopepython=3.8
condaactivatemodelscopePyTorch or TensorFlow can be installed separately according to each model's requirements.Install pytorchdocInstall tensorflowdocAfter installing the necessary machine-learning framework, you can install modelscope library as follows:If you only want to play around with the modelscope framework, of trying out model/dataset download, you can install the core modelscope components:pipinstallmodelscopeIf you want to use multi-modal models:pipinstallmodelscope[multi-modal]If you want to use nlp models:pipinstallmodelscope[nlp]-fhttps://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.htmlIf you want to use cv models:pipinstallmodelscope[cv]-fhttps://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.htmlIf you want to use audio models:pipinstallmodelscope[audio]-fhttps://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.htmlIf you want to use science models:pipinstallmodelscope[science]-fhttps://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.htmlNotes:Currently, some audio-task models only support python3.7, tensorflow1.15.4 Linux environments. Most other models can be installed and used on Windows and Mac (x86).Some models in the audio field use the third-party library SoundFile for wav file processing. On the Linux system, users need to manually install libsndfile of SoundFile(doc link). On Windows and MacOS, it will be installed automatically without user operation. For example, on Ubuntu, you can use following commands:sudoapt-getupdate
sudoapt-getinstalllibsndfile1Some models in computer vision need mmcv-full, you can refer to mmcvinstallation guide, a minimal installation is as follows:pipuninstallmmcv# if you have installed mmcv, uninstall itpipinstall-Uopenmim
miminstallmmcv-fullLearn MoreWe  provide additional documentations including:More detailed Installation GuideIntroduction to tasksUse pipeline for model inferenceFinetuning examplePreprocessing of dataEvaluationContribute your own model to ModelScopeLicenseThis project is licensed under theApache License (Version 2.0).