Get caffe protobuf. Returns: The imported caffe protobuf module.
()
| 115 | |
| 116 | |
| 117 | def get_caffe_pb(): |
| 118 | """ |
| 119 | Get caffe protobuf. |
| 120 | |
| 121 | Returns: |
| 122 | The imported caffe protobuf module. |
| 123 | """ |
| 124 | dir = get_dataset_path('caffe') |
| 125 | caffe_pb_file = os.path.join(dir, 'caffe_pb2.py') |
| 126 | if not os.path.isfile(caffe_pb_file): |
| 127 | download(CAFFE_PROTO_URL, dir) |
| 128 | assert os.path.isfile(os.path.join(dir, 'caffe.proto')) |
| 129 | |
| 130 | cmd = "protoc --version" |
| 131 | version, ret = subproc_call(cmd, timeout=3) |
| 132 | if ret != 0: |
| 133 | sys.exit(1) |
| 134 | try: |
| 135 | version = version.decode('utf-8') |
| 136 | version = float('.'.join(version.split(' ')[1].split('.')[:2])) |
| 137 | assert version >= 2.7, "Require protoc>=2.7 for Python3" |
| 138 | except Exception: |
| 139 | logger.exception("protoc --version gives: " + str(version)) |
| 140 | raise |
| 141 | |
| 142 | cmd = 'cd {} && protoc caffe.proto --python_out .'.format(dir) |
| 143 | ret = os.system(cmd) |
| 144 | assert ret == 0, \ |
| 145 | "Command `{}` failed!".format(cmd) |
| 146 | assert os.path.isfile(caffe_pb_file), caffe_pb_file |
| 147 | import imp |
| 148 | return imp.load_source('caffepb', caffe_pb_file) |
| 149 | |
| 150 | |
| 151 | if __name__ == '__main__': |
no test coverage detected