bugfix for hang in list(Batch()) (#117)

This commit is contained in:
youkaichao 2020-07-08 17:09:27 +08:00 committed by GitHub
parent f5e007932f
commit 481015932c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -433,6 +433,14 @@ class Batch:
"""Return self[k] if k in self else d. d defaults to None."""
return self.__dict__.get(k, d)
def __iter__(self):
try:
length = len(self)
except Exception:
length = 0
for i in range(length):
yield self[i]
def to_numpy(self) -> None:
"""Change all torch.Tensor to numpy.ndarray. This is an in-place
operation.