Skip to content

Commit

Permalink
Reuse de_parallel() rather than is_parallel() (ultralytics#6354)
Browse files Browse the repository at this point in the history
  • Loading branch information
imyhxy committed Jan 20, 2022
1 parent 029181d commit a00257a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions utils/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import torch.nn as nn

from utils.metrics import bbox_iou
from utils.torch_utils import is_parallel
from utils.torch_utils import de_parallel


def smooth_BCE(eps=0.1): # https://github.com/ultralytics/yolov3/issues/238#issuecomment-598028441
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(self, model, autobalance=False):
if g > 0:
BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g)

det = model.module.model[-1] if is_parallel(model) else model.model[-1] # Detect() module
det = de_parallel(model).model[-1] # Detect() module
self.balance = {3: [4.0, 1.0, 0.4]}.get(det.nl, [4.0, 1.0, 0.25, 0.06, 0.02]) # P3-P7
self.ssi = list(det.stride).index(16) if autobalance else 0 # stride 16 index
self.BCEcls, self.BCEobj, self.gr, self.hyp, self.autobalance = BCEcls, BCEobj, 1.0, h, autobalance
Expand Down
4 changes: 2 additions & 2 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class ModelEMA:

def __init__(self, model, decay=0.9999, updates=0):
# Create EMA
self.ema = deepcopy(model.module if is_parallel(model) else model).eval() # FP32 EMA
self.ema = deepcopy(de_parallel(model)).eval() # FP32 EMA
# if next(model.parameters()).device.type != 'cpu':
# self.ema.half() # FP16 EMA
self.updates = updates # number of EMA updates
Expand All @@ -309,7 +309,7 @@ def update(self, model):
self.updates += 1
d = self.decay(self.updates)

msd = model.module.state_dict() if is_parallel(model) else model.state_dict() # model state_dict
msd = de_parallel(model).state_dict() # model state_dict
for k, v in self.ema.state_dict().items():
if v.dtype.is_floating_point:
v *= d
Expand Down

0 comments on commit a00257a

Please sign in to comment.