[Forefront of Object Recognition 2020] Logs from installing Pytorch on Windows 10 to running CornerNet-Lite.

If you notice it, it's been updated for the first time in over a year ... (^^ ;;;

Recently, I haven't touched Python or OpenCV because I'm only doing Java or professional programming. So I haven't followed the latest trends in object detection and object recognition, but CornerNet-Lite has been a hot topic since last year, and it seems that CornerNet-Squeeze is faster than yolo v3, so I will build an environment and experiment with Max-kun by object recognition. .. See below for details on trends.

https://opencv.org/latest-trends-in-object-detection-from-cornernet-to-centernet-explained-part-ii-cornernet-lite/

See ↓ for an easy-to-understand article in Japanese about the mechanism of CornerNet. https://engineer.dena.jp/2019/07/cv-papers-19-keypoint-object-detection.html In a nutshell, CornerNet seems to be a mechanism that creates a heat map, estimates the corners of a rectangle, and detects and recognizes an object.

So, as shown below, it would be better if it was built in the Anaconda environment, but the pip3 environment has already been built and there is competition with Anaconda (conda and pip: Danger of mixing. hatenablog.com/entry/2018/02/11/142347)) It's annoying, so I built it without using Anaconda, so I'll keep a log of it.

https://github.com/princeton-vl/CornerNet-Lite

Install pytorch

Access the URL below and click according to your environment to display the command. https://pytorch.org/

QUICK START LOCALLY That part!

My environment is Windows and the package manager is pip, Python 3.7.4, cuda10.1.

C:\>pip3 install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch===1.4.0
  Downloading https://download.pytorch.org/whl/cu101/torch-1.4.0-cp37-cp37m-win_amd64.whl (796.8MB)
      |████████████████████████████████| 796.8MB 45kB/s
Collecting torchvision===0.5.0
  Using cached https://files.pythonhosted.org/packages/7d/3e/2b5ddf744226159dc90a52f0d044c0de7c5ca4f42d12a350a674ebb6fb2a/torchvision-0.5.0-cp37-cp37m-win_amd64.whl
Requirement already satisfied: six in c:\python\python37\lib\site-packages (from torchvision===0.5.0) (1.12.0)
Requirement already satisfied: pillow>=4.1.1 in c:\python\python37\lib\site-packages (from torchvision===0.5.0) (6.1.0)
Requirement already satisfied: numpy in c:\python\python37\lib\site-packages (from torchvision===0.5.0) (1.17.2)
Installing collected packages: torch, torchvision
  Found existing installation: torch 1.0.1
    Uninstalling torch-1.0.1:
      Successfully uninstalled torch-1.0.1
  Found existing installation: torchvision 0.4.0
    Uninstalling torchvision-0.4.0:
      Successfully uninstalled torchvision-0.4.0
Successfully installed torch-1.4.0 torchvision-0.5.0

C:\>

If Successfully is displayed, you are done.

Obtaining the pytorch version of CornerNet-Lite

Get the pytorch version of CornerNet-Lite from the following and try it.

https://github.com/princeton-vl/CornerNet-Lite.git

C:\>cd github
C:\github>git clone https://github.com/princeton-vl/CornerNet-Lite.git
Cloning into 'CornerNet-Lite'...
remote: Enumerating objects: 75, done.
remote: Total 75 (delta 0), reused 0 (delta 0), pack-reused 75
Unpacking objects: 100% (75/75), done.

Execute make, but assume that the mingw environment has been built.

C:\github\CornerNet-Lite\core\external>mingw32-make
python setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    from Cython.Build import cythonize
ModuleNotFoundError: No module named 'Cython'
Makefile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1

I'm getting the error No module named'Cython', so install Cython with pip. Depending on the pre-built environment, you may get No module named for other modules. In that case, judge the error message that appears and install the module.

What is Cython?

A package for accelerating Python. See ↓ https://qiita.com/pashango2/items/45cb85390193d97523ca

C:\>pip3 install cython
Collecting cython
  Downloading https://files.pythonhosted.org/packages/1f/be/b14be5c3ad1ff73096b518be1538282f053ec34faaca60a8753d975d7e93/Cython-0.29.14-cp37-cp37m-win_amd64.whl (1.7MB)
      |████████████████████████████████| 1.7MB 6.4MB/s
Installing collected packages: cython
Successfully installed cython-0.29.14

C:\>

take heart…

C:\github\CornerNet-Lite\core\external>mingw32-make
python setup.py build_ext --inplace
Compiling bbox.pyx because it changed.
Compiling nms.pyx because it changed.
[1/2] Cythonizing bbox.pyx
C:\Python\Python37\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\github\CornerNet-Lite\core\external\bbox.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
[2/2] Cythonizing nms.pyx
C:\Python\Python37\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\github\CornerNet-Lite\core\external\nms.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'bbox' extension
creating build
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Python\Python37\lib\site-packages\numpy\core\include -IC:\Python\Python37\include -IC:\Python\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\shared" -IC:\opencv3.4.0\sources\include\opencv2 -IC:\opencv3.4.0\sources\include -IC:\opencv3.4.0\build\include\opencv2 -IC:\opencv3.4.0\build\include -IC:\opencv\build\include /Tcbbox.c /Fobuild\temp.win-amd64-3.7\Release\bbox.obj -Wno-cpp -Wno-unused-function
 cl: Command line error D8021: The numeric argument'/ Wno-cpp' is invalid.
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
Makefile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1

C:\github\CornerNet-Lite\core\external>

I still get an error. The numeric argument'/ Wno-cpp' is invalid. I'm told For the time being, in C: \ github \ CornerNet-Lite \ core \ external \ setup.py

extra_compile_args=['-Wno-cpp', '-Wno-unused-function']

You don't need it because the compile options are invalid, right? That's why

extra_compile_args=[]

I lost the argument and re-executed.

C:\github\CornerNet-Lite\core\external>mingw32-make

~~~~
 Omitted on the way
~~~~
md64.lib
 Creating library build \ temp.win-amd64-3.7 \ Release \ nms.cp37-win_amd64.lib and object build \ temp.win-amd64-3.7 \ Release \ nms.cp37-win_amd64.exp
 I'm generating code.
 Code generation is complete.
rm -rf build

The generation goes well with.

Get model file

The training data is MS COCO. https://github.com/princeton-vl/CornerNet-Lite#training-and-evaluation

As shown in Documentation, the three created model files are acquired and placed.

CornerNet-Saccade CornerNet-Saccade model CornerNet_Saccade_500000.pkl(447M) https://drive.google.com/file/d/1MQDyPRI0HgDHxHToudHqQ-2m8TVBciaa/view?usp=sharing Download and place it below.

C:\github\CornerNet-Lite\cache\nnet\CornerNet_Saccade\

CornerNet-Squeeze CornerNet-Squeeze model CornerNet_Squeeze_500000.pkl(122M) https://drive.google.com/file/d/1qM8BBYCLUBcZx_UmLT0qMXNTh-Yshp4X/view?usp=sharing Download and place it below.

C:\github\CornerNet-Lite\cache\nnet\CornerNet_Squeeze\

CornerNet CornerNet model CornerNet_500000.pkl(768M) https://drive.google.com/file/d/1e8At_iZWyXQgLlMwHkB83kN-AN85Uff1/view?usp=sharing Download and place it below.

C:\github\CornerNet-Lite\cache\nnet\CornerNet\

Run demo

Execute the following command.

C:\github\CornerNet-Lite>python demo.py
Traceback (most recent call last):
  File "demo.py", line 7, in <module>
    detector = CornerNet_Saccade()
  File "C:\github\CornerNet-Lite\core\detectors.py", line 38, in __init__
    from .test.cornernet_saccade import cornernet_saccade_inference
  File "C:\github\CornerNet-Lite\core\test\__init__.py", line 1, in <module>
    from .cornernet import cornernet
  File "C:\github\CornerNet-Lite\core\test\cornernet.py", line 7, in <module>
    from tqdm import tqdm
ModuleNotFoundError: No module named 'tqdm'

C:\github\CornerNet-Lite>

ModuleNotFoundError: No module named'tqdm', so install tqdm with pip.

C:\>pip3 install tqdm
Collecting tqdm
  Downloading https://files.pythonhosted.org/packages/72/c9/7fc20feac72e79032a7c8138fd0d395dc6d8812b5b9edf53c3afd0b31017/tqdm-4.41.1-py2.py3-none-any.whl (56kB)
      |████████████████████████████████| 61kB 4.1MB/s
Installing collected packages: tqdm
Successfully installed tqdm-4.41.1

C:\>

So, try again.

C:\github\CornerNet-Lite>python demo.py
total parameters: 116969339
loading from C:\github\CornerNet-Lite\core\..\cache\nnet\CornerNet_Saccade\CornerNet_Saccade_500000.pkl
C:\Python\Python37\lib\site-packages\torch\nn\functional.py:2506: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.
  "See the documentation of nn.Upsample for details.".format(mode))

The following files are created in C: \ github \ CornerNet-Lite.

demo_out.jpg demo_out.jpg Like this, Borzoi properly recognizes it as a dog, and SUP also recognizes surfboards and people (oilers).

Looking at the log

loading from C:\github\CornerNet-Lite\core\..\cache\nnet\CornerNet_Saccade\CornerNet_Saccade_500000.pkl

It has become. It's not CornerNet-Squeeze, which uses CornerNet-Saccade and is faster than yolo v3, so let's modify demo.py.

!/usr/bin/env python

import cv2
from core.detectors import CornerNet_Squeeze
from core.vis_utils import draw_bboxes

detector = CornerNet_Squeeze()

 image    = cv2.imread("demo.jpg ")
image    = cv2.imread("max_kun.jpg ")

bboxes = detector(image)
image  = draw_bboxes(image, bboxes)
cv2.imwrite("demo_out_max_kun.jpg ", image)

Then execute it.

C:\github\CornerNet-Lite>python demo2.py
total parameters: 31771852
loading from C:\github\CornerNet-Lite\core\..\cache\nnet\CornerNet_Squeeze\CornerNet_Squeeze_500000.pkl

C:\github\CornerNet-Lite>

The result looks like this. demo_out2.jpg Umu. The object could not be detected before the object was recognized. Moreover, he recognizes Keira as a bird. Is the accuracy not good? ?? ??

AP (Average Precision)

Looking at the AP of the COCO data in Documentation, Is it higher than yolo v3? compare-2.png

YOLOv3 33.0% at 39 ms CornerNet-Squeeze is 34.4% in 30 ms CornerNet-Saccade is 43.2% at 190 ms

The accuracy is getting higher.

f4.png

The image when it is recognized by yolo v3 is like this. yolov3_max_kun.png

See here for the article when running yolo v3 with pytorch ↓. https://qiita.com/goodboy_max/items/b75bb9eea52831fcdf15

Is CornerNet-Squeeze not good at recognizing and applying images different from COCO data? Because the image was rough? Or did you take the compile option? ?? ??

The mystery just deepens ...

Reference information

https://opencv.org/latest-trends-in-object-detection-from-cornernet-to-centernet-explained-part-ii-cornernet-lite/ https://engineer.dena.jp/2019/07/cv-papers-19-keypoint-object-detection.html https://qiita.com/sounansu/items/9a6caf1ac5e78aefaeae https://qiita.com/pashango2/items/45cb85390193d97523ca

Recommended Posts

[Forefront of Object Recognition 2020] Logs from installing Pytorch on Windows 10 to running CornerNet-Lite.
Everything from building a Python environment to running it on Windows
Change the Key of Object on S3 from normal date format to Hive format
Steps to build PyTorch 1.5 for CUDA 10.2 on Windows
A memo of installing Chainer 1.5 for GPU on Windows
From python to running instance on google cloud platform
From running MINST on TensorFlow 2.0 to visualization on TensorBoard (2019 edition)
How to know the number of GPUs from python ~ Notes on using multiprocessing with pytorch ~
After all, the story of returning from Linux to Windows
I tried changing the python script from 2.7.11 to 3.6.0 on windows10