Skip to content

Commit

Permalink
Auto-format by https://ultralytics.com
Browse files Browse the repository at this point in the history
  • Loading branch information
UltralyticsAssistant committed Jan 8, 2025
1 parent 23a0719 commit 29d867e
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion classify/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def lf(x):
amp_autocast = torch.cuda.amp.autocast(enabled=device.type != "cpu")
else:
amp_autocast = torch.amp.autocast("cuda", enabled=device.type != "cpu")
with amp_autocast:
with amp_autocast:
loss = criterion(model(images), labels)

# Backward
Expand Down
2 changes: 1 addition & 1 deletion classify/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def run(
amp_autocast = torch.cuda.amp.autocast(enabled=device.type != "cpu")
else:
amp_autocast = torch.amp.autocast("cuda", enabled=device.type != "cpu")

with amp_autocast:
for images, labels in bar:
with dt[0]:
Expand Down
1 change: 0 additions & 1 deletion models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ def forward(self, ims, size=640, augment=False, profile=False):
p = next(self.model.parameters()) if self.pt else torch.empty(1, device=self.model.device) # param
autocast = self.amp and (p.device.type != "cpu") # Automatic Mixed Precision (AMP) inference
if isinstance(ims, torch.Tensor): # torch

amp_autocast = None
if torch.__version__.startswith("1.8"):
amp_autocast = torch.cuda.amp.autocast(enabled=autocast)
Expand Down
4 changes: 2 additions & 2 deletions segment/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def lf(x):
maps = np.zeros(nc) # mAP per class
results = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls)
scheduler.last_epoch = start_epoch - 1 # do not move

scaler = None
if torch.__version__.startswith("1.8"):
scaler = torch.cuda.amp.GradScaler(enabled=amp)
Expand Down Expand Up @@ -391,7 +391,7 @@ def lf(x):
else:
amp_autocast = torch.amp.autocast("cuda", enabled=amp)
# Forward
with amp_autocast:
with amp_autocast:
pred = model(imgs) # forward
loss, loss_items = compute_loss(pred, targets.to(device), masks=masks.to(device).float())
if RANK != -1:
Expand Down
2 changes: 1 addition & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def lf(x):
amp_autocast = torch.cuda.amp.autocast(enabled=amp)
else:
amp_autocast = torch.amp.autocast("cuda", enabled=amp)
with amp_autocast:
with amp_autocast:
pred = model(imgs) # forward
loss, loss_items = compute_loss(pred, targets.to(device)) # loss scaled by batch_size
if RANK != -1:
Expand Down
1 change: 0 additions & 1 deletion utils/autobatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

def check_train_batch_size(model, imgsz=640, amp=True):
"""Checks and computes optimal training batch size for YOLOv5 model, given image size and AMP setting."""

if torch.__version__.startswith("1.8"):
with torch.cuda.amp.autocast(enabled=amp):
return autobatch(deepcopy(model).train(), imgsz)
Expand Down

0 comments on commit 29d867e

Please sign in to comment.