Fix deprecation warning collections.abc (#312)

* Fix deprecation warning collections.abc

* Fix isort
pull/290/head
Miguel Mendez 2020-06-02 13:29:54 +02:00 committed by GitHub
parent efecf7d1fe
commit fe4f657f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -1,5 +1,5 @@
# Copyright (c) Open-MMLab. All rights reserved.
import collections
from collections.abc import Mapping, Sequence
import torch
import torch.nn.functional as F
@ -20,7 +20,7 @@ def collate(batch, samples_per_gpu=1):
3. cpu_only = False, stack = False, e.g., gt bboxes
"""
if not isinstance(batch, collections.Sequence):
if not isinstance(batch, Sequence):
raise TypeError(f'{batch.dtype} is not supported.')
if isinstance(batch[0], DataContainer):
@ -73,10 +73,10 @@ def collate(batch, samples_per_gpu=1):
stacked.append(
[sample.data for sample in batch[i:i + samples_per_gpu]])
return DataContainer(stacked, batch[0].stack, batch[0].padding_value)
elif isinstance(batch[0], collections.Sequence):
elif isinstance(batch[0], Sequence):
transposed = zip(*batch)
return [collate(samples, samples_per_gpu) for samples in transposed]
elif isinstance(batch[0], collections.Mapping):
elif isinstance(batch[0], Mapping):
return {
key: collate([d[key] for d in batch], samples_per_gpu)
for key in batch[0]