diff --git a/pytorch3d/renderer/utils.py b/pytorch3d/renderer/utils.py index d78c2d43..2a15438e 100644 --- a/pytorch3d/renderer/utils.py +++ b/pytorch3d/renderer/utils.py @@ -8,7 +8,7 @@ import copy import inspect import warnings -from typing import Any, List, Optional, Tuple, Union +from typing import Any, List, Optional, Tuple, TypeVar, Union import numpy as np import torch @@ -191,7 +191,7 @@ class TensorProperties(nn.Module): """ for k in dir(self): v = getattr(self, k) - if inspect.ismethod(v) or k.startswith("__"): + if inspect.ismethod(v) or k.startswith("__") or type(v) is TypeVar: continue if torch.is_tensor(v): v_clone = v.clone() diff --git a/tests/test_cameras.py b/tests/test_cameras.py index fca05e2e..743ba14e 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -31,6 +31,7 @@ # SOFTWARE. import math +import pickle import typing import unittest from itertools import product @@ -1333,6 +1334,11 @@ class TestPerspectiveProjection(TestCaseMixin, unittest.TestCase): # Check in_ndc is handled correctly self.assertEqual(cam._in_ndc, c0._in_ndc) + def test_clone_picklable(self): + camera = PerspectiveCameras() + pickle.dumps(camera) + pickle.dumps(camera.clone()) + ############################################################ # FishEye Camera #