Converting proto files to .py on Windows – Tensorflow

Hey everyone,

Ran into a bit of an issue today with Tensorflow:

ImportError: cannot import name preprocessor_pb2

Turned out that I hadn’t run some of the installing steps. I needed to use protoc to convert the proto directory files:

protoc object_detection/protos/preprocessor_pb2.proto --python_out=.

This turned out to be a bit of a headache as well, but thankfully a github post explained it all pretty well:

Here are the steps I followed to install it for windows:
(Prerequisite, you must have python, pip and)

Choose a Python release from here and download: Link here
– Extract the tar.gzor zip
– Open a cmd and pip install the following: pillow, lxml, jupyter, matplotlib
– Copy the protoc.exe from the protoc folder (you don’t need to do all the CMake steps you might have stumbled upon, it worked for me without them too) and paste it into your protos folder in the object detection directory.
– Run the protoc for each of those protos like “protoc object_detection/protos/*.proto –python_out=.”. . Note that you might encounter a problem with the paths and there’s two ways around that: Either move the protoc.exe two folders down or do the noobish thing that I did – copy the protos and paste them into a new directory inside the protos folder ‘object_detection\protos’ so you would have a folder structure like’\object_detection\protos\object_detection\protos’ (If it looks stupid but it works, it’s not stupid eh?) Note that *.proto might also not work and you might have to do each of them individually
– You are done. :) Try to run something to see if you have any problems. You might have to install a manual version of numpyandscipy

GitHub Link:

Leave a Reply