I’m participating in nuggets Creators Camp # 4, click here to learn more and learn together!

First, high altitude parabolic detection

1. Project application scenarios

“Put on your helmet when you go out.”

“Pies don’t fall from heaven, but POTS and pans do.”

“As soon as you pass the upper floors, walk quickly through the lower floors.”

2. Artificial intelligence parabolic detection

This “flying projectile” doesn’t make life easy

Anything falls down

It’s even more infuriating

The reason for throwing is also strange

In a bad mood, throw

Quarrel with boyfriend or girlfriend, throw

If you don’t like something, get rid of it

In their opinion

In short, “Throw it if you want.”

Did you think you couldn’t be caught?

Wrong!

It’s time to cue the high flier

“Your every move is being recorded.”

3. Basic idea

  • Calculate compare_ssim

  • Calculate the location of the exception for matting

  • Use PP-SHITU to classify and identify the discovered objects

  • Alarm is given to the objects that have alarms and are identified within 3 seconds.

Two, abnormal object detection

1. Basic information

The first frame

The second frame

Detected objects

2. Calculation procedure

From skimage.metrics import structural_similarity as compare_ssim import argparse import imutils import cv2 ImageA = cv2.imread("gl_1.jpeg") imageB = cv2.imread("gl_2.jpeg") # convert them to grayscale: GrayA = cv2.cvtcolor (imageA, cv2.color_bgr2gray) grayB = cv2.cvtcolor (imageB, cv2.color_bgr2gray) # calculate the structure similarity index between two gray images: # However ssiM is mostly used for comparison of distortion after compression pictures. (score,diff) = compare_ssim(grayA,grayB,full = True) diff = (diff *255).astype("uint8") Find the contours of different points so that we can place rectangles around areas identified as "different" : Thresh = cv2. Threshold (diff, 0255, cv2. THRESH_BINARY_INV | cv2. THRESH_OTSU). [1] # cv2 findContours () function returns two values, one is the contour itself, The other is the attribute for each contour. # it first returns a list, Each element in the list is a profile in the image CNTS = cv2.findContours(thresh.copy(), cv2.retr_external, cv2.chain_approx_simple) """ Note the CV version, The following line has the following problems: Change OpenCV 3 to cv2.findContours(...) The return value is image, contours, hierarchy, OpenCV 2 cv2.findContours(...). And OpenCV 4 cv2.findContours(...) The return value is contours, hierarchy. CNTS = CNTS [1] if imutils.is_cv2() else CNTS [0] # Find a series of regions and place rectangles around them: Rectangle (imageA,(x,y),(x+w,y+h),(0,0,255), rectangle(imageA,(x,y),(x+w,y+h),(0,0,255) (x+w, y+h) is the coordinates of the lower-right point of the matrix. The fourth parameter: (0,0,255) is the RGB color corresponding to the lines drawn. The fifth parameter: 2 is the width of the lines drawn. (x, y, w, h) = cv2. BoundingRect (c) cv2. A rectangle (imageA, (x, y), (y + x + w, h), (0,0,255), 2) Cv2. A rectangle (imageB, (x, y), (y + x + w, h), (0,0,255), 2) ex_obj = imageB [y, y + h, x: x + w] cv2. Imwrite (' ex_obj. JPG, ex_obj) # show the final comparison with cv2.imshow Cv2. imshow("differ",imageB) cv2.imwrite("differ. JPG ",imageB) cv2.waitKey(0)Copy the code
from skimage.metrics import structural_similarity as compare_ssim
import argparse
import imutils
import cv2


# load two images:
# Note that the slash copied from the file path is backward, remember to change, and use the English path

imageA = cv2.imread("gl_1.jpeg")
imageB = cv2.imread("gl_2.jpeg")

# Convert them to grayscale:

grayA = cv2.cvtColor(imageA,cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB,cv2.COLOR_BGR2GRAY)


# Calculate the structural similarity index between two grayscale images:
# However ssiM is mostly used for comparison of distortion after compression pictures.

(score,diff) = compare_ssim(grayA,grayB,full = True)
diff = (diff *255).astype("uint8")



Find the contours of different points so that we can place rectangles around areas identified as "different" :

thresh = cv2.threshold(diff,0.255,cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]

The #cv2.findContours() function returns two values, one for the contour itself and one for the properties of each contour.
It first returns a list in which each element is an outline in the image

cnts = cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)


Note the CV version, the following line will have the following problem: OpenCV 3 changed to cv2.findContours(...) The return value is image, contours, hierarchy, OpenCV 2 cv2.findContours(...). And OpenCV 4 cv2.findContours(...) The return value is contours, hierarchy. ""

Store the contours in the list of CNTS

cnts = cnts[1] if imutils.is_cv2() else cnts[0]


# Find a series of areas and place rectangles around them:
Rectangle (imageA,(x,y),(x+w,y+h),(0,0,255), rectangle(imageA,(x,y),(x+w,y+h),(0,0,255) (x+w, y+h) is the coordinate of the lower right point of the matrix. The fourth parameter: (0,0,255) is the RGB color corresponding to the line drawn. The fifth parameter: 2 is the width of the line drawn.

for c in cnts:
    (x,y,w,h) = cv2.boundingRect(c)
    cv2.rectangle(imageA,(x,y),(x+w,y+h),(0.0.255),2)
    cv2.rectangle(imageB,(x,y),(x+w,y+h),(0.0.255),2)
    ex_obj=imageB[y:y+h,x:x+w]
    cv2.imwrite('ex_obj.jpg',ex_obj)




# cv2.imshow shows the final comparison image, cv2.imwrite saves the final image

cv2.imshow("differ",imageB)
cv2.imwrite("differ.jpg",imageB)
cv2.waitKey(0)

Copy the code

Third, PP-SHITU for object classification

1. Configure the environment

Download PaddleClas: Download the PaddleClas code for the official REPO

! git clone https://gitee.com/PaddlePaddle/PaddleClas --depth=1
Copy the code
Cloning into 'PaddleClas'... remote: Enumerating objects: 1413, done.[K remote: Counting objects: 100% (1413/1413), done.[K remote: Compressing objects: 100% (1009/1009), done.[K remote: Total 1413 (delta 566), reused 837 (delta 378), pack-reused 0[K Receiving objects: 100% (1413/1413) and 61.53 MiB | 4.68 MiB/s, done. Resolving deltas: 100% (566/566), done. Checking connectivity... done.Copy the code
# It takes about 40 seconds! pip install pip -U ! cd PaddleClas && pip install -r requirements.txtCopy the code
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
[?25l  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7MB)
[K    100% |████████████████████████████████| 1.7MB 15.5MB/s ta 0:00:01
[?25hInstalling collected packages: pip
  Found existing installation: pip 19.0.3
    Uninstalling pip-19.0.3:
      Successfully uninstalled pip-19.0.3
Successfully installed pip-21.3.1
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: prettytable in /opt/conda/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (0.7.2)
Requirement already satisfied: ujson in /opt/conda/lib/python3.6/site-packages (from -r requirements.txt (line 2)) (1.35)
Collecting opencv-python==4.4.0.46
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6d/80/10a9ae6fa0940f25af32739d1dc6dfdbbdc79af3f04c5ea1a6de4303cd54/opencv_python-4.4.0.46-cp36-cp36m-manylinux2014_x86_64.whl (49.5 MB)
     |████████████████████████████████| 49.5 MB 329 kB/s            
[?25hRequirement already satisfied: pillow in /opt/conda/lib/python3.6/site-packages (from -r requirements.txt (line 4)) (5.4.1)
Requirement already satisfied: tqdm in /opt/conda/lib/python3.6/site-packages (from -r requirements.txt (line 5)) (4.32.2)
Requirement already satisfied: PyYAML in /opt/conda/lib/python3.6/site-packages (from -r requirements.txt (line 6)) (5.1)
Collecting visualdl>=2.2.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/87/c8/10d0d24822637d8e5493a73ad118640530195e45b1c71ae0e60606ff5f0e/visualdl-2.2.3-py3-none-any.whl (2.7 MB)
     |████████████████████████████████| 2.7 MB 50.5 MB/s            
[?25hRequirement already satisfied: scipy in /opt/conda/lib/python3.6/site-packages (from -r requirements.txt (line 8)) (1.5.3)
Requirement already satisfied: scikit-learn==0.23.2 in /opt/conda/lib/python3.6/site-packages (from -r requirements.txt (line 9)) (0.23.2)
Collecting gast==0.3.3
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d6/84/759f5dd23fec8ba71952d97bcc7e2c9d7d63bdc582421f3cd4be845f0c98/gast-0.3.3-py2.py3-none-any.whl (9.7 kB)
Collecting faiss-cpu==1.7.1.post2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5f/2e/a7c8358aeedd28c6026890b4f292498e0440118cf4d32398d2647e1216c6/faiss_cpu-1.7.1.post2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB)
     |████████████████████████████████| 8.4 MB 54.8 MB/s            
[?25hRequirement already satisfied: numpy>=1.13.3 in /opt/conda/lib/python3.6/site-packages (from opencv-python==4.4.0.46->-r requirements.txt (line 3)) (1.19.4)
Requirement already satisfied: joblib>=0.11 in /opt/conda/lib/python3.6/site-packages (from scikit-learn==0.23.2->-r requirements.txt (line 9)) (1.0.1)
Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/lib/python3.6/site-packages (from scikit-learn==0.23.2->-r requirements.txt (line 9)) (2.1.0)
Collecting pillow
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ea/0f/2fa195c2d8c6fe0b3dc2df5fc6ac6b8dbd005ea30aaa0fa43eca88b8c664/Pillow-8.4.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)
     |████████████████████████████████| 3.1 MB 46.9 MB/s            
[?25hRequirement already satisfied: pandas in /opt/conda/lib/python3.6/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (0.24.2)
Requirement already satisfied: matplotlib in /opt/conda/lib/python3.6/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (2.2.3)
Collecting bce-python-sdk
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/55/ef/2a7e6c7692a036bae2570a9bcdcd7963ea54e07db97b4554c24d3cfacb21/bce-python-sdk-0.8.64.tar.gz (127 kB)
     |████████████████████████████████| 127 kB 72.6 MB/s            
[?25h  Preparing metadata (setup.py) ... [?25ldone
[?25hCollecting shellcheck-py
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0f/4f/ab756db996bdde0a647bf552c1be78cbf8055b664ecd54f08f3210f8cf26/shellcheck_py-0.8.0.3-py2.py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 46.6 MB/s            
[?25hRequirement already satisfied: requests in /opt/conda/lib/python3.6/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (2.22.0)
Collecting protobuf>=3.11.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0f/1c/6b3b5b8c07e92b84cb7d4fb946a8bc72b98d93d8b7c8e8a8e45023745810/protobuf-3.19.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB)
     |████████████████████████████████| 1.1 MB 49.6 MB/s            
[?25hCollecting flask>=1.1.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cd/77/59df23681f4fd19b7cbbb5e92484d46ad587554f5d490f33ef907e456132/Flask-2.0.3-py3-none-any.whl (95 kB)
     |████████████████████████████████| 95 kB 14.3 MB/s            
[?25hRequirement already satisfied: flake8>=3.7.9 in /opt/conda/lib/python3.6/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (3.8.2)
Collecting Flask-Babel>=1.0.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ab/3e/02331179ffab8b79e0383606a028b6a60fb1b4419b84935edd43223406a0/Flask_Babel-2.0.0-py3-none-any.whl (9.3 kB)
Collecting pre-commit
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d6/a0/9c06353771c8dae6db437dd513a885eccdb1566cb332569130484eddf4e7/pre_commit-2.17.0-py2.py3-none-any.whl (195 kB)
     |████████████████████████████████| 195 kB 57.8 MB/s            
[?25hCollecting six>=1.14.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl (11 kB)
Requirement already satisfied: pyflakes<2.3.0,>=2.2.0 in /opt/conda/lib/python3.6/site-packages (from flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.2.0)
Requirement already satisfied: importlib-metadata in /opt/conda/lib/python3.6/site-packages (from flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.6.1)
Requirement already satisfied: pycodestyle<2.7.0,>=2.6.0a1 in /opt/conda/lib/python3.6/site-packages (from flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.6.0)
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /opt/conda/lib/python3.6/site-packages (from flake8>=3.7.9->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.6.1)
Collecting Jinja2>=3.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/20/9a/e5d9ec41927401e41aea8af6d16e78b5e612bca4699d417f646a9610a076/Jinja2-3.0.3-py3-none-any.whl (133 kB)
     |████████████████████████████████| 133 kB 62.3 MB/s            
[?25hCollecting Werkzeug>=2.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f4/f3/22afbdb20cc4654b10c98043414a14057cd27fdba9d4ae61cea596000ba2/Werkzeug-2.0.3-py3-none-any.whl (289 kB)
     |████████████████████████████████| 289 kB 45.3 MB/s            
[?25hCollecting click>=7.1.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4a/a8/0b2ced25639fb20cc1c9784de90a8c25f9504a7f18cd8b5397bd61696d7d/click-8.0.4-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 1.8 MB/s             
[?25hCollecting itsdangerous>=2.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9c/96/26f935afba9cd6140216da5add223a0c465b99d0f112b68a4ca426441019/itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting Babel>=2.3
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/aa/96/4ba93c5f40459dc850d25f9ba93f869a623e77aaecc7a9344e19c01942cf/Babel-2.9.1-py2.py3-none-any.whl (8.8 MB)
     |████████████████████████████████| 8.8 MB 2.2 MB/s            
[?25hRequirement already satisfied: pytz in /opt/conda/lib/python3.6/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.2.0->-r requirements.txt (line 7)) (2018.9)
Collecting pycryptodome>=3.8.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/71/6b/965be3bec8fc1f6013739fea2bba86cf43a3be09ab7e29bd2134829c7615/pycryptodome-3.14.1-cp35-abi3-manylinux2010_x86_64.whl (2.0 MB)
     |████████████████████████████████| 2.0 MB 63.9 MB/s            
[?25hRequirement already satisfied: future>=0.6.0 in /opt/conda/lib/python3.6/site-packages (from bce-python-sdk->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.17.1)
Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.6/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.3.1)
Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.8.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.0.1)
Collecting nodeenv>=0.11.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/54/73/56c89b343befb9c63e8117294d265458f0ff726fa2abcdc6bb5ec5e66a1a/nodeenv-1.6.0-py2.py3-none-any.whl (21 kB)
Collecting importlib-resources<5.3
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/11/8e/84a6a778a1160cefcef1192a7bd26e4e6689981553aff13c2b2b6f1c352f/importlib_resources-5.2.3-py3-none-any.whl (27 kB)
Requirement already satisfied: toml in /opt/conda/lib/python3.6/site-packages (from pre-commit->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.10.1)
Collecting virtualenv>=20.0.8
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/56/a2/3e5fdac9ecca6a3a6d2f63f7a486afd4a72728ba9f2ae83fa43f7af8ac8b/virtualenv-20.13.2-py2.py3-none-any.whl (8.7 MB)
     |████████████████████████████████| 8.7 MB 60.4 MB/s            
[?25hCollecting cfgv>=2.0.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6d/82/0a0ebd35bae9981dea55c06f8e6aaf44a49171ad798795c72c6f64cba4c2/cfgv-3.3.1-py2.py3-none-any.whl (7.3 kB)
Collecting identify>=1.0.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/da/1a/93ac674fee1a5af11bdbc1cd895895a8710aa49402558bf91ec3523f0214/identify-2.4.4-py2.py3-none-any.whl (98 kB)
     |████████████████████████████████| 98 kB 19.3 MB/s            
[?25hRequirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.6/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (2020.12.5)
Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/lib/python3.6/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/lib/python3.6/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.24.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.6/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.0.4)
Requirement already satisfied: zipp>=3.1.0 in /opt/conda/lib/python3.6/site-packages (from importlib-resources<5.3->pre-commit->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.1.0)
Collecting MarkupSafe>=2.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e2/a9/eafee9babd4b3aed918d286fbe1c20d1a22d347b30d2bddb3c49919548fa/MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Requirement already satisfied: setuptools in /opt/conda/lib/python3.6/site-packages (from kiwisolver>=1.0.1->matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (40.8.0)
Collecting platformdirs<3,>=2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b1/78/dcfd84d3aabd46a9c77260fb47ea5d244806e4daef83aa6fe5d83adb182c/platformdirs-2.4.0-py3-none-any.whl (14 kB)
Collecting filelock<4,>=3.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/84/ce/8916d10ef537f3f3b046843255f9799504aa41862bfa87844b9bdc5361cd/filelock-3.4.1-py3-none-any.whl (9.9 kB)
Collecting distlib<1,>=0.3.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ac/a3/8ee4f54d5f12e16eeeda6b7df3dfdbda24e6cc572c86ff959a4ce110391b/distlib-0.3.4-py2.py3-none-any.whl (461 kB)
     |████████████████████████████████| 461 kB 61.7 MB/s            
[?25hCollecting dataclasses
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fe/ca/75fac5856ab5cfa51bbbcefa250182e50441074fdc3f803f6e76451fab43/dataclasses-0.8-py3-none-any.whl (19 kB)
Building wheels for collected packages: bce-python-sdk
  Building wheel for bce-python-sdk (setup.py) ... [?25ldone
[?25h  Created wheel for bce-python-sdk: filename=bce_python_sdk-0.8.64-py3-none-any.whl size=202974 sha256=5be01a81f4e003a2983a3e3726049edd2a03aa433b07a39a1a7d5f695c7161f8
  Stored in directory: /home/aistudio/.cache/pip/wheels/4d/01/4a/0ddb9526bd30d94e4ba9d333ed1f462272e55724ee22ea338d
Successfully built bce-python-sdk
Installing collected packages: MarkupSafe, dataclasses, Werkzeug, six, platformdirs, Jinja2, itsdangerous, importlib-resources, filelock, distlib, click, virtualenv, pycryptodome, nodeenv, identify, flask, cfgv, Babel, shellcheck-py, protobuf, pre-commit, pillow, Flask-Babel, bce-python-sdk, visualdl, opencv-python, gast, faiss-cpu
  Attempting uninstall: MarkupSafe
    Found existing installation: MarkupSafe 1.1.1
    Uninstalling MarkupSafe-1.1.1:
      Successfully uninstalled MarkupSafe-1.1.1
  Attempting uninstall: Werkzeug
    Found existing installation: Werkzeug 0.15.1
    Uninstalling Werkzeug-0.15.1:
      Successfully uninstalled Werkzeug-0.15.1
  Attempting uninstall: six
    Found existing installation: six 1.12.0
    Uninstalling six-1.12.0:
      Successfully uninstalled six-1.12.0
  Attempting uninstall: Jinja2
    Found existing installation: Jinja2 2.10
    Uninstalling Jinja2-2.10:
      Successfully uninstalled Jinja2-2.10
  Attempting uninstall: itsdangerous
    Found existing installation: itsdangerous 1.1.0
    Uninstalling itsdangerous-1.1.0:
      Successfully uninstalled itsdangerous-1.1.0
  Attempting uninstall: click
    Found existing installation: Click 7.0
    Uninstalling Click-7.0:
      Successfully uninstalled Click-7.0
  Attempting uninstall: flask
    Found existing installation: Flask 1.0.2
    Uninstalling Flask-1.0.2:
      Successfully uninstalled Flask-1.0.2
  Attempting uninstall: protobuf
    Found existing installation: protobuf 3.6.1
    Uninstalling protobuf-3.6.1:
      Successfully uninstalled protobuf-3.6.1
  Attempting uninstall: pillow
    Found existing installation: Pillow 5.4.1
    Uninstalling Pillow-5.4.1:
      Successfully uninstalled Pillow-5.4.1
  Attempting uninstall: opencv-python
    Found existing installation: opencv-python 4.0.0.21
    Uninstalling opencv-python-4.0.0.21:
      Successfully uninstalled opencv-python-4.0.0.21
Successfully installed Babel-2.9.1 Flask-Babel-2.0.0 Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.3 bce-python-sdk-0.8.64 cfgv-3.3.1 click-8.0.4 dataclasses-0.8 distlib-0.3.4 faiss-cpu-1.7.1.post2 filelock-3.4.1 flask-2.0.3 gast-0.3.3 identify-2.4.4 importlib-resources-5.2.3 itsdangerous-2.0.1 nodeenv-1.6.0 opencv-python-4.4.0.46 pillow-8.4.0 platformdirs-2.4.0 pre-commit-2.17.0 protobuf-3.19.4 pycryptodome-3.14.1 shellcheck-py-0.8.0.3 six-1.16.0 virtualenv-20.13.2 visualdl-2.2.3
Copy the code

2. Image recognition experience

The following table describes the lightweight general subject detection model, lightweight general identification model and configuration file download methods.

model Model structure Pre-training model download address Inference model mAP The Inference model size (MB) Single image prediction time (excluding pre-processing)(ms)
Lightweight subject detection model PicoDet address Tar file address Zip file address 40.1% 30.1 29.8
Server principal detection model PP-YOLOv2 address Tar file address Zip file address 42.5% 210.5 466.6
  • You can download and extract the data and model by following the commands below
Mkdir models CD models # 下载 identify the inference model and extract wget {{model 下载 link} && tar-xf {compression package} CD.. Wget {data download link address} && tar -xf {package name}Copy the code
  • Use the following command to switch the default working directory to the deploy folder in PaddleClas
# import os # os.chdir("/home/aistudio/PaddleClas/deploy") # ! pwd %cd ~/PaddleClas/deploy /home/aistudio/PaddleClas/deployCopy the code
  • Download and extract inference model and Demo data

To download the Demo data set and the general detection and identification model, run the following command:

%cd ~/PaddleClas/
# !mkdir models
#! cd models && wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_i Nfer.tar && tar -xf picodet_pplcnet_x2_5_mainbody_lite_V1.0_infer.tar! wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/pretrain/general_PPLCNet_x2_5_pretrained_v1. 0.pdparams
Copy the code
/home/aistudio/PaddleClas --2022-02-27 21:27:31-- https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/pretrain/general_PPLCNet_x2_5_pretrained_v1.0.pdpar ams Resolving paddle-imagenet-models-name.bj.bcebos.com (paddle-imagenet-models-name.bj.bcebos.com)... 182.61.200.229 182.61.200.195, 2409:8c04:1001:1002:0:ff:b001:368a Connecting to paddle-imagenet-models-name.bj.bcebos.com (paddle-imagenet-models-name.bj.bcebos.com) | 182.61.200.229 | : 443... connected. HTTP request sent, awaiting response... 200 OK Length: 792851195 (756M) [application/octet-stream] Saving to: 'general_PPLCNet_x2_5_pretrained_v1. 0. 100% pdparams' general_PPLCNet_x2_ [= = = = = = = = = = = = = = = = = = = >] 756.12 M 49.4 MB/s in 19 s 2022-02-27 21:27:50 (40.6 MB/s) - 'general_pplcnet_x2_5_pretrained_v1.0.pdParams' saved [792851195/792851195]Copy the code
! cd models && wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1. 0_infer.tar && tar -xf general_PPLCNet_x2_5_lite_v1. 0_infer.tar
Copy the code
- 21:27:50-2022-02-27 https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1.0_infer.tar Resolving paddle-imagenet-models-name.bj.bcebos.com (paddle-imagenet-models-name.bj.bcebos.com)... 182.61.200.195 182.61.200.229, 2409:8c04:1001:1002:0:ff:b001:368a Connecting to paddle-imagenet-models-name.bj.bcebos.com (paddle-imagenet-models-name.bj.bcebos.com) | 182.61.200.195 | : 443... connected. HTTP request sent, awaiting response... 200 OK Length: 34242560 (33M) [application/x-tar] Saving to: 'general_PPLCNet_x2_5_lite_v1. 0 _infer. Tar' general_PPLCNet_x2_ 100% [= = = = = = = = = = = = = = = = = = = >] 32.66 M 17.2 MB/s in 1.9 s 2022-02-27 21:27:53 (17.2 MB/s) - 'general_pplcnet_x2_5_lite_V1.0_infer. Tar' saved [34242560/34242560]Copy the code
! tree models/Copy the code
Models / ├ ─ ─ general_PPLCNet_x2_5_lite_v1. 0 _infer │ ├ ─ ─ inference. Pdiparams │ ├ ─ ─ inference. Pdiparams. Info │ └ ─ ─ The inference. Pdmodel Exercises ── General_pplcnet_x2_5_lite_V1.0_infer. Tar Exercises ── Picodet_pplcnet_x2_5_mainbody_lite_v1.0_infer │ Exercises ── Infer_cfg. Yml │ ├ ─ ─ inference. Pdiparams │ ├ ─ ─ inference. Pdiparams. Info │ └ ─ ─ inference. Pdmodel └ ─ ─ Picodet_pplcnet_x2_5_mainbody_lite_v1.0_infer. Tar 2 directories, 9 filesCopy the code
  • Here, subject detection, feature extraction and vector retrieval are connected in series to form a set of image recognition system:

If the item is an existing item in the original index database: Create an index database

Create index library%cd /home/aistudio/PaddleClas/deploy ! python3 python/build_gallery.py \ -c configs/build_general.yaml \ -o IndexProcess.data_file="/home/aistudio/dataset/data_file.txt" \
    -o IndexProcess.index_dir="/home/aistudio/dataset/index_inference"
Copy the code

3. Parabolic recognition and retrieval

Identify the image Run the following command to identify and retrieve the image detected and alarm:

# Image recognition based on index library%cd /home/aistudio/PaddleClas/deploy ! python python/predict_system.py \ -c configs/inference_general.yaml \ -o Global.infer_imgs="/home/aistudio/dataset/ex_obj.jpg" \
    -o IndexProcess.index_dir="/home/aistudio/dataset/index_inference"
Copy the code