Commit efea540b authored by Jeremy Reizenstein's avatar Jeremy Reizenstein Committed by Facebook GitHub Bot
Browse files

Fix camera clone() with torch.save

Summary:
User reported that cloned cameras fail to save. The error with latest PyTorch is

```
pickle.PicklingError: Can't pickle ~T_destination: attribute lookup T_destination on torch.nn.modules.module failed
```

This fixes it.

Reviewed By: btgraham

Differential Revision: D39692258

fbshipit-source-id: 75bbf3b8dfa0023dc28bf7d4cc253ca96e46a64d
parent ce3fce49
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import copy import copy
import inspect import inspect
import warnings import warnings
from typing import Any, List, Optional, Tuple, Union from typing import Any, List, Optional, Tuple, TypeVar, Union
import numpy as np import numpy as np
import torch import torch
...@@ -191,7 +191,7 @@ class TensorProperties(nn.Module): ...@@ -191,7 +191,7 @@ class TensorProperties(nn.Module):
""" """
for k in dir(self): for k in dir(self):
v = getattr(self, k) v = getattr(self, k)
if inspect.ismethod(v) or k.startswith("__"): if inspect.ismethod(v) or k.startswith("__") or type(v) is TypeVar:
continue continue
if torch.is_tensor(v): if torch.is_tensor(v):
v_clone = v.clone() v_clone = v.clone()
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
# SOFTWARE. # SOFTWARE.
import math import math
import pickle
import typing import typing
import unittest import unittest
from itertools import product from itertools import product
...@@ -1333,6 +1334,11 @@ class TestPerspectiveProjection(TestCaseMixin, unittest.TestCase): ...@@ -1333,6 +1334,11 @@ class TestPerspectiveProjection(TestCaseMixin, unittest.TestCase):
# Check in_ndc is handled correctly # Check in_ndc is handled correctly
self.assertEqual(cam._in_ndc, c0._in_ndc) self.assertEqual(cam._in_ndc, c0._in_ndc)
def test_clone_picklable(self):
camera = PerspectiveCameras()
pickle.dumps(camera)
pickle.dumps(camera.clone())
############################################################ ############################################################
# FishEye Camera # # FishEye Camera #
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment