How to TensorFlow Object Detection on Windows

From Scratch: https://github.com/tensorflow/models

Rio Weber
riow
4 min readMay 11, 2020

--

For this guide to work you must have a minimum of Windows version 18362.0

INSTALLS…

Windows Media Feature Pack

Windows N and KN editions do not include Media Feature Pack which is required by OpenCV. If you are using Windows N or KN edition, please install also Windows Media Feature Pack.

https://www.microsoft.com/en-us/download/details.aspx?id=48145

Git

https://git-scm.com/

Click the download button and install

Python 3.7

TensorFlow only runs on python 3.7 64 bit

https://www.python.org/ftp/python/3.7.7/python-3.7.7-amd64-webinstall.exe

Upgrade PIP

python -m pip install --upgrade pip

Virtualenv

pip install virtualenv

Windows Terminal

https://www.microsoft.com/store/productId/9N0DX20HK701

Project Setup

cd to where you keep your projects

cd /mnt/c/Users/riodw/projects/

Download the TensorFlow models (this includes the Object Detection models)

git clone https://github.com/tensorflow/models.git

cd to models/

cd models

Start a Virtualenv

virtualenv venv

To begin using the virtual environment, it needs to be activated:

venv\scripts\activate

If you get the error below:
You need to run `Set-ExecutionPolicy RemoteSigned` to fix it

Tensorflow Object Detection API

https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md

Install TensorFlow

Object Detection does NOT work with TensorFlow version 2
Have to install most recent version of 1

pip install tensorflow==1.15

Install packages

pip install Cython contextlib2 pillow lxml jupyter matplotlib

Install opencv-python

pip install opencv-python

Install Visual Studio Build Tools

https://go.microsoft.com/fwlink/?LinkId=691126

Install COCO API for windows

https://github.com/philferriere/cocoapi

pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

Install Protobuf

https://github.com/protocolbuffers/protobuf/blob/master/src/README.md

https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protoc-3.11.4-win64.zip

Unzip the download

cd to research folder

cd .\research\

Compile model and training parameters using Protobuf

# From tensorflow/models/research/
C:\Users\riodw\protoc-3.11.4-win64\bin\protoc.exe object_detection/protos/*.proto --python_out=.

Testing the Installation

# From tensorflow/models/research/
python object_detection/builders/model_builder_test.py

If it fails to No module named 'object_detection':

No module named 'object_detection':

1. in models\research directory run the following:
python setup.py build
python setup.py install

2. go to model\research\slim and run the following:
pip install -e .

Update PATH

Open the application “Edit the system environment variables”

or just windows search “PATH”

Click Environment Variables…

Edit the Path

Add:

C:\Users\riodw\AppData\Roaming\Python\Python37\Scripts
C:\Users\riodw\AppData\Roaming\Python\Python37\Scripts\bin

Vehicle Detector

Create vehicle_detector.py

https://gist.github.com/riodw/446791dbdeeb2a37943ba6e033fd010b

Create grabscreen.py

https://gist.github.com/riodw/e79504012b2ae6bab605e2a74ee3d045

Install opencv-python

pip install opencv-python

--

--