参考资料:
CUDA Automatic Mixed Precision examples — PyTorch master documentation
pytorch scheduler汇总_AI大魔王的博客-优快云博客_pytorch scheduler
代码:
import argparse
import math
import os
import sys
from pathlib import Path
import torch.distributed as dist
import torch
import torchvision
from torch import nn
from torch.optim import lr_scheduler
from torchvision import transforms
FILE = Path(__file__).resolve()
ROOT = FILE.parents[0] # YOLOv5 root directory
if str(ROOT) not in sys.path:
sys.path.append(str(ROOT)) # add ROOT to PATH
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
RANK = int(os.getenv('RANK', -1))
WORLD