4

I am trying to compile protoc files using this command:

protoc/bin/protoc models/research/object_detection/protos/*.proto --python_out=.

but I am getting this output on cmd

object_detection/protos/flexible_grid_anchor_generator.proto: File not found.
object_detection/protos/grid_anchor_generator.proto: File not found.
object_detection/protos/multiscale_anchor_generator.proto: File not found.
object_detection/protos/ssd_anchor_generator.proto: File not found.
models/research/object_detection/protos/anchor_generator.proto:5:1: Import "object_detection/protos/flexible_grid_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:6:1: Import "object_detection/protos/grid_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:7:1: Import "object_detection/protos/multiscale_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:8:1: Import "object_detection/protos/ssd_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:14:5: "GridAnchorGenerator" is not defined.
models/research/object_detection/protos/anchor_generator.proto:15:5: "SsdAnchorGenerator" is not defined.
models/research/object_detection/protos/anchor_generator.proto:16:5: "MultiscaleAnchorGenerator" is not defined.
models/research/object_detection/protos/anchor_generator.proto:17:5: "FlexibleGridAnchorGenerator" is not defined.

So what can be the problem Thank you

Jenny
  • 375
  • 4
  • 6
  • 25

3 Answers3

8

You need to run the protobuf compiler in the correct directory. In that case, it would be models/research:

$ cd models/research
$ ../../protoc/bin/protoc object_detection/protos/*.proto --python_out=.

The protobuf files will be compiled to python. In the directory object_detection/protos/, you should have python files named after the protobuf file (i.e <name_protobuf>_pb2.py).

There is relative imports in those protobuf files, so it's important that the protobuf compiler is run in the correct directory. You have a hint that it might be the error as the File not Found error message lists a different path than your current directory.

Lescurel
  • 10,749
  • 16
  • 39
  • Thank you for your help, I tried this and no error showed, in fact nothing showed up, is that normal? can I consider the files compiled? @lescurel – Jenny Jun 30 '21 at 08:50
  • This answer helped me and nothing showed up afterwards @Jenny – Mike Dubs Jan 05 '22 at 21:48
0

I faced this issue recently. I cleared it by changing the file paths in the proto file.

For example, a proto file had following imports.

import "object_detection/protos/flexible_grid_anchor_generator.proto";
import "object_detection/protos/grid_anchor_generator.proto";
import "object_detection/protos/multiscale_anchor_generator.proto";
import "object_detection/protos/ssd_anchor_generator.proto";

I changed it to the following.

import "flexible_grid_anchor_generator.proto";
import "grid_anchor_generator.proto";
import "multiscale_anchor_generator.proto";
import "ssd_anchor_generator.proto";

The reason is all the proto files are present in the same object_detection/protos folder so path is not required.

I changed the references in all the proto files and it worked.

Harish R
  • 1
  • 1
0

On my side, I followed Harish recommendation above to remove the file path. Then compiled the proto files one by one then added the --proto_path=path/to/imports flag for each file. Find this https://stackoverflow.com/a/21152266/12001817 that when you compile a .proto file that includes imports, you must provide the paths to the imported files so that the compiler can find them. For example, you might use a command like the following to compile a .proto file that imports other files:

Sample command which have worked:

$protoc/bin/protoc --proto_path=models/research/object_detection/protos models/research/object_detection/protos/box_predictor.proto --python_out=.

JM Acera
  • 1
  • 1