Revert loss head PR (#2873)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Ayush Chaurasia
2023-05-28 19:45:41 +05:30
committed by GitHub
parent 6391c60089
commit 527a97759b
8 changed files with 335 additions and 327 deletions

View File

@ -325,7 +325,8 @@ class BaseTrainer:
# Forward
with torch.cuda.amp.autocast(self.amp):
batch = self.preprocess_batch(batch)
self.loss, self.loss_items = de_parallel(self.model).loss(batch)
preds = self.model(batch['img'])
self.loss, self.loss_items = self.criterion(preds, batch)
if RANK != -1:
self.loss *= world_size
self.tloss = (self.tloss * i + self.loss_items) / (i + 1) if self.tloss is not None \
@ -495,6 +496,12 @@ class BaseTrainer:
"""Build dataset"""
raise NotImplementedError('build_dataset function not implemented in trainer')
def criterion(self, preds, batch):
"""
Returns loss and individual loss items as Tensor.
"""
raise NotImplementedError('criterion function not implemented in trainer')
def label_loss_items(self, loss_items=None, prefix='train'):
"""
Returns a loss dict with labelled training loss items tensor

View File

@ -162,8 +162,7 @@ class BaseValidator:
# Loss
with dt[2]:
if self.training:
loss_items = model.loss(batch, preds)
self.loss += loss_items[1]
self.loss += trainer.criterion(preds, batch)[1]
# Postprocess
with dt[3]: