top of page

Hello

Home: Welcome

About Me

IMG_7861.JPG

Hi, welcome to my website! I’m not really sure what this is or should be; but hopefully it can be at least fun or interesting. I aim to make regular posts about things I find inspiring or technical things I hope I can remember in the future.

First, a little about me…


I am a professional physicist; I am a generalist with specialisms in all sorts. I am passionate about AI and I try to reflect on the use of AI in research and business. I also take a strong interest in the ways we run our projects and how we are influenced by the culture of work or research around us; I like to teach and to share knowledge and in part that explains this site.


I have spent the last decade in Durham, UK where I completed a BSc, Masters and PhD in theoretical physics. My interests are in the detection of dark matter, which sits somewhere between particle physics and cosmology. Although I have left academic research; I still maintain ties to the university. My tome of a thesis (500 pages!) was designed to be a useful textbook-like reference for students of dark matter, and it expands at length on my various published research topics.


The decision to leave academia wasn’t easy; but there is a world of skills and knowledge in industry which I was ready to tap. I started out as a software developer at a consultancy firm in Oxford; learning the ropes with C++ and Python and contributing as a developer to the Mantid codebase for muon beam analysis at Rutherford Appleton Labs. I moved back to Durham to join Kromek, a innovative R&D company who make detectors to work on X-ray security applications.


Now, I mostly spend my days running X-ray projects with a focus on AI. 

Home: About Me
Home: Blog2

Let’s Chat

Thanks for submitting!

DSCF2493.JPG
Home: Contact
  • Writer's pictureTom Jubb

Installing Tensorflow Object Detection API on Windows

I thought I would start off the AI topic with a brief tutorial on how to get the Tensorflow object detection API up and running on Windows. The object detection API is a series of tools that allow us to quickly test or train state-of-the-art object detection algorithms; coding these from scratch would be incredibly time consuming and so this tool is immensely valuable.


Installing the API is one of those things that's best done by following a tutorial; however the Tensorflow documentation is sometimes a little lacking and is also focussed towards Linux or Mac.


I will try to provide a bit of insight into the reason the various steps are needed; and also give some tips on how to check if what you've done in each step has worked. Things sometimes fail silently and this can be frustrating...

I am using Windows 10 on a 64-bit system; I will be putting everything inside a root folder

 

Step 0 : Prerequesites


You will need a few things set up before beginning. I highly recommend Anaconda for dealing with Python code. To find out a bit more about Anaconda (as I am assuming you have some familiarity with it) go here.

Once installed you should have access to the "Anaconda Prompt" app. Open this up and it should like the image below



 

Step 1 : Install Dependencies


The first thing you *need* to do (or I highly recommend you do), is create a new conda environment so that you have a clean area to build up the dependencies. Use the following lines of code

In the first line the environment is created with the name "tf_detect" and python version 3.6; in the second line we move into the environment (you should notice the prompt change from base to tf_detect). The third line should return the location of pip, which is a python package manager.

This output is good; there are two pip executables, one in my new environment and one in the base environment. The first one will be the one that gets used with the pip command and this should be the environment one (the reason I highlight this is that if you use the wrong pip, you will install things into the wrong environment and end up very confused).

Next, we need to install Tensorflow version 1 (I suggest the latest version which is 1.15.2 as of writing) using pip. We should also install jupyter so that we can run notebooks

Now you can check the success of the Tensorflow installation by listing all the packages on your environment. You should use the command

which provides the following output on my machine (I have scrolled to the relevant section)



The fact that Tensorflow appears shows that it has been installed correctly (and is the 2.1.0 version, yours should be 1.15.2).

Another way to check is to open the python repr, and try to import the package. If it works without error then it is correctly installed; as shown below.


 

Step 2 : Install Object Detection API

Ok; now the dependencies are set up we can start with the Tensorflow object detection API. First off, we want to get the source code. There is a posh and a non-posh way to do this


2.1 Posh

Use a git client to clone the repository. My favourite is GitBash as this has many of the usual Linux commands and function basically like a linux terminal in Windows (you can use it for non-git things!). Once you have installed it, open the GitBash prompt.

Go to the directory that you want to put the Tensorflow object detector code and then clone it (see below)

You should see some sensible output and once complete, the folder will appear in tensorflow_detection.

2.2 Non-Posh

Go to https://github.com/tensorflow/models and select to download the zip file



Place the zip file in our root folder and extract it. That should have placed the code inside the "tensorflow_detection" folder.

 

Step 3 : Dealing with Protobuf

For some reason; many of the files in this code are "protobuf" (these are the ones with the .proto extension) and you need to convert them to python .py files. To do this we need to download the converter from

You should make sure you download the correct one for the operating system, for me it was "protoc-3.11.3-win64.zip" for 64-bit Windows. Place this zip file in /tensorflow_detection/ and extract it. You should have a ".exe" file inside `protoc-3.11.3-win64\bin` called protoc.exe. This will do the conversions for us.

Go back to the anaconda prompt; we are now going to run this executable on all the proto files (which handily are all in the same folder). First go to the correct folder, and then run the executable on the relevant files;

To check this, firstly there shouldn't be any warnings, and secondly there should be .py files in the protos/ folder. Now, we can install the object detection API onto our environment

To test this, try to import object_detection from within python, if it works, all good!

 

Step 4 : Testing the Installation

The quickest way to test the install is to use the example Jupyter notebook supplied with the Tensorflow object detection API; it can be found in

However; this is designed to be used with Google colab so I have simplified it a bit for running locally on Jupyter notebooks and you can download it here.

Place it in the root folder. To open jupyter do the following

this should open your preferred browser and start a tab with a Jupyter server on. You should see the tutorial file straight away since we opened the server in the directory containing it. Click it to open. I have left all the output in the Jupyter notebook except for the images so you can see the expected output.

In this notebook you will find an example run of an object detector as well as a segmentation algorithm. Actually it's quite fun to spend a few minutes shoving some of your own images in and testing them. To do that, put your images in .jpg form and put this files in

and rerun the relevant parts of the notebook

In the next blog; I will show you how to train an object detector on new data.


Left : An example of an object detector from the notebook. Right : A segmentation algorithm



References

Tensorflow Object Detection API on GitHub :



Other Tutorials



110 views0 comments
  • linkedin
  • generic-social-link

©2020 by Thomas Jubb.

bottom of page