Shortcuts

mmengine.utils.dl_utils.torch_ops 源代码

# Copyright (c) OpenMMLab. All rights reserved.
import torch

from ..version_utils import digit_version
from .parrots_wrapper import TORCH_VERSION

_torch_version_meshgrid_indexing = (
    'parrots' not in TORCH_VERSION
    and digit_version(TORCH_VERSION) >= digit_version('1.10.0a0'))


[文档]def torch_meshgrid(*tensors): """A wrapper of torch.meshgrid to compat different PyTorch versions. Since PyTorch 1.10.0a0, torch.meshgrid supports the arguments ``indexing``. So we implement a wrapper here to avoid warning when using high-version PyTorch and avoid compatibility issues when using previous versions of PyTorch. Args: tensors (List[Tensor]): List of scalars or 1 dimensional tensors. Returns: Sequence[Tensor]: Sequence of meshgrid tensors. """ if _torch_version_meshgrid_indexing: return torch.meshgrid(*tensors, indexing='ij') else: return torch.meshgrid(*tensors) # Uses indexing='ij' by default

© Copyright 2022, mmengine contributors. Revision 39ed23fa.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
Versions
latest
stable
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.1
v0.9.0
v0.8.5
v0.8.4
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.7.4
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.