pythontensorflowprotocol-buffersobject-recognition

Is it possible to loop when compiling with protobuf, converting .proto files to .py files?


I was setting up an environment for an object recognition project using TensorFlow. When it came to compiling some .proto files I hit a wall. It took the efforts of find the path to the files / then find the path to the protobuf app / then go ahead and command -- python_out=. for every single proto file!!

What I'm doing / trying to do: Following this (https://www.edureka.co/blog/tensorflow-object-detection-tutorial/#object) tutorial sort of thing on edureka I managed to:

The Commands

C:\Users\yourusername\Desktop\TensorFlow\protoc-3.5.1-win32\bin\protoc object_detection/protos/anchor_generator.proto --python_out=.
C:\Users\yourusername\Desktop\TensorFlow\protoc-3.5.1-win32\bin\protoc object_detection/protos/argmax_matcher.proto --python_out=.
C:\Users\yourusername\Desktop\TensorFlow\protoc-3.5.1-win32\bin\protoc object_detection/protos/bipartite_matcher.proto --python_out=.

....and so on until you finish all items in the protos folder

So what this did was basically allow me to compile as a .py file under every proto file. I do happen to have a lot more to go ahead and command, so for productivity - How can I loop this to do just the exact same task over and over through the proto files that need to be compiled?


Solution

  • I was able to resolve this following these steps:

    1. Navigate to the Tensorflow\models\research folder in command line (Path may vary in your case)
    2. Enter this command for %i in (object_detection\protos\*.proto) do protoc %i --python_out=.

    It'll create .py file for each .proto file in the Tensorflow\models\research folder as in this screenshot

    Hope this helps.