Object Detection using Tensorflow: coco API for python in Windows

homeMachine Learning >Image Processing

Object Detection using Tensorflow: bee and butterflies

  1. Part 1: set up tensorflow in a virtual environment
  2. adhoc functions
  3. Part 2: preparing annotation in PASCAL VOC format
  4. Part 3: preparing tfrecord files
  5. more scripts
  6. Part 4: start training our machine learning algorithm!
  7. COCO API for Windows
  8. Part 5: perform object detection

We continue our tutorial from part IV. Since the instruction to set up coco API for python here is for Linux, we need to find a way to do it in Windows. First download the coco API and extract it, and you will see folder cocoapi-master. The following instruction mainly refers to the link here.

We need to follow the following steps beforehand:

  1. install Microsoft Visual C++ 14.0. ***
  2. Visual C++ might raise rc.exe error. Fix by add to PATH variable C:\Program Files (x86)\Windows Kits\8.1\bin\x64.
  3. inside cocoapi-master/PythonAPI, edit the setup.py (see below).

Install MinGW and go into msys.exe. Move into the PythonAPI folder of the coco API just downloaded.

cd "C:\Users\acer\Downloads\cocoapi-master\PythonAPI"
Make

If successful, the file _mask.cp36-win_amd64 will be generated in /PythonAPI/pycocotools. Move the folder pycocotools so that we have

adhoc\myproject\Lib\site-packages\tensorflow\models\research
+ pycocotools
 - ...
 - _mask.cp36-win_amd64

The modified setup.py is shown here.

setup.py

import sys
from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
import numpy as np

extra_compile_args = ['-Wno-cpp', '-Wno-unused-function', '-std=c99']\
  if sys.platform != 'win32' else []
ext_modules = [
    Extension(       
        'pycocotools._mask',
        language='c++',
        sources=['../common/maskApi.c', 'pycocotools/_mask.pyx'],
        include_dirs = [np.get_include(), '../common'],
        extra_compile_args=extra_compile_args,
    )
]

setup(name='pycocotools',
      packages=['pycocotools'],
      package_dir = {'pycocotools': 'pycocotools'},
      version='2.0',
      ext_modules=
          cythonize(ext_modules)
      )

*** We attempted to install VC++ 14 via Visual Studio Community 2017 installer Windows 10 and had some troubles. In particular, msys.exe raised error “cannot find vcvarsall.bat”. Indeed, when we look into “C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC”, vcvarsall.bat is not installed.

Instead, we download Visual Studio Community 2015 here and install Programming Languages/Visual C++ package as shown here. Web installer is available but it is not downloading smoothly. When the downloader says there is a “A Setup Package is Missing or Damaged”, just keep clicking “Retry” till it works.