| 24 | _ids = count(0) |
| 25 | |
| 26 | def __init__(self, predict_net, init_net): |
| 27 | logger.info(f"Initializing ProtobufModel for: {predict_net.name} ...") |
| 28 | super().__init__() |
| 29 | assert isinstance(predict_net, caffe2_pb2.NetDef) |
| 30 | assert isinstance(init_net, caffe2_pb2.NetDef) |
| 31 | # create unique temporary workspace for each instance |
| 32 | self.ws_name = "__tmp_ProtobufModel_{}__".format(next(self._ids)) |
| 33 | self.net = core.Net(predict_net) |
| 34 | |
| 35 | logger.info("Running init_net once to fill the parameters ...") |
| 36 | with ScopedWS(self.ws_name, is_reset=True, is_cleanup=False) as ws: |
| 37 | ws.RunNetOnce(init_net) |
| 38 | uninitialized_external_input = [] |
| 39 | for blob in self.net.Proto().external_input: |
| 40 | if blob not in ws.Blobs(): |
| 41 | uninitialized_external_input.append(blob) |
| 42 | ws.CreateBlob(blob) |
| 43 | ws.CreateNet(self.net) |
| 44 | |
| 45 | self._error_msgs = set() |
| 46 | self._input_blobs = uninitialized_external_input |
| 47 | |
| 48 | def _infer_output_devices(self, inputs): |
| 49 | """ |