MCPcopy
hub / github.com/hustvl/Vim / test_scriptability

Method test_scriptability

det/tests/structures/test_boxes.py:198–219  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

196 self.assertEqual(x.to(device="cpu").tensor.device.type, "cpu")
197
198 def test_scriptability(self):
199 def func(x):
200 boxes = Boxes(x)
201 test = boxes.to(torch.device("cpu")).tensor
202 return boxes.area(), test
203
204 f = torch.jit.script(func)
205 f = reload_script_model(f)
206 f(torch.rand((3, 4)))
207
208 data = torch.rand((3, 4))
209
210 def func_cat(x: torch.Tensor):
211 boxes1 = Boxes(x)
212 boxes2 = Boxes(x)
213 # boxes3 = Boxes.cat([boxes1, boxes2]) # this is not supported by torchsript for now.
214 boxes3 = boxes1.cat([boxes1, boxes2])
215 return boxes3
216
217 f = torch.jit.script(func_cat)
218 script_box = f(data)
219 self.assertTrue(torch.equal(torch.cat([data, data]), script_box.tensor))
220
221
222if __name__ == "__main__":

Callers

nothing calls this directly

Calls 3

reload_script_modelFunction · 0.90
fClass · 0.70
catMethod · 0.45

Tested by

no test coverage detected