(self)
| 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 | |
| 222 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected