MCPcopy Create free account
hub / github.com/pytorch/pytorch / run

Method run

caffe2/python/onnx/backend_rep.py:30–65  ·  view source on GitHub ↗
(self, inputs, **kwargs)

Source from the content-addressed store, hash-verified

28 return ''
29
30 def run(self, inputs, **kwargs):
31 super().run(inputs, **kwargs)
32 with core.DeviceScope(self.predict_net.device_option):
33 if isinstance(inputs, dict):
34 with core.NameScope(self._name_scope):
35 for key, value in inputs.items():
36 self.workspace.FeedBlob(key, value)
37 elif isinstance(inputs, list) or isinstance(inputs, tuple):
38 if len(self.uninitialized) != len(inputs):
39 raise RuntimeError('Expected {} values for uninitialized '
40 'graph inputs ({}), but got {}.'.format(
41 len(self.uninitialized),
42 ', '.join(self.uninitialized),
43 len(inputs)))
44 for i, value in enumerate(inputs):
45 # namescope already baked into protobuf
46 self.workspace.FeedBlob(self.uninitialized[i], value)
47 else:
48 # single input
49 self.workspace.FeedBlob(self.uninitialized[0], inputs)
50 if not self.nets_created:
51 self.workspace.CreateNet(self.init_net)
52 self.workspace.CreateNet(self.predict_net)
53 self.nets_created = True
54 if not self.ran_init_net:
55 self.workspace.RunNet(self.init_net.name)
56 self.ran_init_net = True
57 self.workspace.RunNet(self.predict_net.name)
58 output_values = []
59 for name in self.predict_net.external_output:
60 try:
61 output_values.append(self.workspace.FetchBlob(name))
62 except Exception:
63 output_values.append(self.workspace.FetchInt8Blob(name))
64 return namedtupledict('Outputs',
65 self.predict_net.external_output)(*output_values)

Callers 13

test_mobile_exporterMethod · 0.45
test_runMethod · 0.45
test_run_mapMethod · 0.45
test_relu_graphMethod · 0.45
test_initializerMethod · 0.45
_test_netMethod · 0.45

Calls 6

isinstanceFunction · 0.85
namedtupledictFunction · 0.85
itemsMethod · 0.45
formatMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45

Tested by 13

test_mobile_exporterMethod · 0.36
test_runMethod · 0.36
test_run_mapMethod · 0.36
test_relu_graphMethod · 0.36
test_initializerMethod · 0.36
_test_netMethod · 0.36