1、添加到yolov7的utils/general.py文件最下面
import pkg_resources as pkg
def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=False, hard=False, verbose=False):# Check version vs. required versioncurrent, minimum = (pkg.parse_version(x) for x in (current, minimum))result = (current == minimum) if pinned else (current >= minimum) # boolreturn resultdef set_seeds(seed=0, deterministic=False):# Initialize random number generator (RNG) seeds https://pytorch.org/docs/stable/notes/randomness.htmlrandom.seed(seed)np.random.seed(seed)torch.manual_seed(seed)torch.cuda.manual_seed(seed)torch.cuda.manual_seed_all(seed) # for Multi-GPU, exception safe# torch.backends.cudnn.benchmark = True # AutoBatch problem https://github.com/ultralytics/yolov5/issues/9287if deterministic and check_version(torch.__version__, '1.12.0'): # https://github.com/ultralytics/yolov5/pull/8213torch.use_deterministic_algorithms(True)torch.backends.cudnn.deterministic = Trueos.environ['CUBLAS_WORKSPACE_CONFIG'] = ':4096:8'os.environ['PYTHONHASHSEED'] = str(seed)
2、train.py导入
3、注释掉之前的,更新
4、ok