From 94edd0785f75f9bf9bdc5b813768691636afcceb Mon Sep 17 00:00:00 2001 From: UltralyticsAssistant Date: Sun, 23 Feb 2025 14:49:51 +0000 Subject: [PATCH] Auto-format by https://ultralytics.com --- classify/val.py | 5 +++-- models/common.py | 3 ++- segment/train.py | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/classify/val.py b/classify/val.py index 48104e39e..6114839a6 100644 --- a/classify/val.py +++ b/classify/val.py @@ -48,12 +48,13 @@ from utils.general import ( ) from utils.torch_utils import select_device, smart_inference_mode -#version check +# version check if torch.__version__.startswith("1.8"): - Autocast = torch.cuda.amp.autocast + Autocast = torch.cuda.amp.autocast else: Autocast = torch.amp.autocast + @smart_inference_mode() def run( data=ROOT / "../datasets/mnist", # dataset dir diff --git a/models/common.py b/models/common.py index 50dd5b937..39b26cf47 100644 --- a/models/common.py +++ b/models/common.py @@ -55,12 +55,13 @@ from utils.general import ( ) from utils.torch_utils import copy_attr, smart_inference_mode -# version check +# version check if torch.__version__.startswith("1.8"): Autocast = torch.cuda.amp.autocast else: Autocast = torch.amp.autocast + def autopad(k, p=None, d=1): """ Pads kernel to 'same' output shape, adjusting for optional dilation; returns padding size. diff --git a/segment/train.py b/segment/train.py index cec3df024..00cfacee3 100644 --- a/segment/train.py +++ b/segment/train.py @@ -387,11 +387,10 @@ def train(hyp, opt, device, callbacks): ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]] # new shape (stretched to gs-multiple) imgs = nn.functional.interpolate(imgs, size=ns, mode="bilinear", align_corners=False) - amp_autocast = None if torch.__version__.startswith("1.8"): - amp_autocast = torch.cuda.amp.autocast(enabled=amp) + torch.cuda.amp.autocast(enabled=amp) else: - amp_autocast = torch.amp.autocast("cuda", enabled=amp) + torch.amp.autocast("cuda", enabled=amp) # Forward with Autocast(enabled=amp): pred = model(imgs) # forward