ModuleNotFoundError: No module named ‘mmcv.runner‘ 中 get_dist_info的问题

如何解决 mmcv中没有get_dist_info 的问题

Traceback (most recent call last):
  File "./tools/train.py", line 17, in <module>
    from mmcv.runner import get_dist_info, init_dist
ModuleNotFoundError: No module named 'mmcv.runner'

mmcv中的很多库都改到了mmengine里面去了,看了源码然后改了过来

mmcv中

def get_dist_info() -> Tuple[int, int]:
  """
  获取有关分布式进程环境的信息。

  返回:
    一个元组 (int, int):
        * rank: 当前进程在分布式环境中的排名
        * world_size: 分布式环境中的进程总数 
  """

  if dist.is_available() and dist.is_initialized():
    """检查分布式模块是否可用并已正确初始化"""
    rank = dist.get_rank()    # 获取当前进程的排名
    world_size = dist.get_world_size()  # 获取进程总数
  else:
    """如果分布式模块不可用,则假设为非分布式环境"""
    rank = 0  # 单进程环境下,排名为0
    world_size = 1  # 单进程环境下,进程总数为1

  return rank, world_size  # 返回排名和进程总数

mmengine中的

def get_dist_info(group: Optional[ProcessGroup] = None) -> Tuple[int, int]:
  """
  获取指定进程组的分布式信息。

  注意:
    在非分布式环境中调用 ``get_dist_info`` 将返回 (0, 1)。

  Args:
    group (ProcessGroup, optional): 要查询的进程组对象。如果为 None,将使用默认进程组。默认为 None。

  Returns:
    tuple[int, int]: 返回一个包含 ``rank`` (当前进程排名) 和  ``world_size`` (进程总数) 的元组。
  """

  world_size = get_world_size(group)  # 获取进程总数
  rank = get_rank(group)  # 获取当前进程的排名
  return rank, world_size  # 返回排名和进程总数

结果

#from mmcv.runner import get_dist_info, init_dist
from mmengine.dist.utils import get_dist_info, init_dist

你可能感兴趣的:(mmdet问题集,python)