Location>code7788 >text

From zero physical examination of a magic tower community model (modelscope) the simplest demo

Popularity:653 ℃/2024-08-04 23:50:53

Take a model from the community, such as this link below/models/iic/cv_mobilenet-v2_bad-image-detecting

The sample code for it is as follows

from  import pipeline
from  import Tasks
from  import OutputKeys

img = '/test/images/'
test_pipeline = pipeline(Tasks.bad_image_detecting, 'damo/cv_mobilenet-v2_bad-image-detecting')
result = test_pipeline(img)
print(result)

How do I get it up and running in my own computer environment?

preliminary

First install a Python environment, just pick the latest version and install it, then configure Python to the environment variables.

According to the official documentation, you need to install a conda environment, the recommendation here is to install a miniconda version, linkMiniconda — Anaconda documentation

If you want to use it from the cmd command line, you can also change the installation path tominiconda3\condabinConfigure to environment variables

Finally, on the console, typeconda -VIf you can display the version number without any problem, you have succeeded.

C:\Users\Admin>conda -V
conda 24.5.0

Create a conda environment

Note that the official documentation recommends using python version 3.8 (If you are prompted with Permission denied, then run as an administrator)

conda create --name modelscope python==3.8

pass (a bill or inspection etc)conda info -eCheck for the existence of a modelscope environment

C:\Windows\System32>conda info -e
# conda environments:
#
base                     C:\ProgramData\miniconda3
modelscope               C:\ProgramData\miniconda3\envs\modelscope

Using the conda environment in PyCharm

Add the Python interpreter - Virtualenv environment, selecting theminiconda3\envs\modelscopelower

Next, configure the Conda environment, selecting the existing environment modelscope

If all of the above steps went well, the Python environment you see in the PyCharm terminal at this point should look like this

(modelscope) PS E:\GitHub\blogsCodeSimple\New Folder\modelscopeDemo> python
Python 3.8.0 (default, Nov 6 2019, 16:00:02) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.

Then pullmodelscope[framework]cap (a poem)opencv-python

Just click Run (If you are prompted with Permission denied, then run PyCharm as an administrator.)

The final output is as follows

{'scores': [1.0, 2.5564614e-10, 3.6810602e-13], 'labels': ['normal', 'green', 'splash']}