Release 8.0.5 PR (#279)
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> Co-authored-by: Izam Mohammed <106471909+izam-mohammed@users.noreply.github.com> Co-authored-by: Yue WANG 王跃 <92371174+yuewangg@users.noreply.github.com> Co-authored-by: Thibaut Lucas <thibautlucas13@gmail.com>
This commit is contained in:
@ -177,6 +177,7 @@ class Exporter:
|
||||
for p in model.parameters():
|
||||
p.requires_grad = False
|
||||
model.eval()
|
||||
model.float()
|
||||
model = model.fuse()
|
||||
for k, m in model.named_modules():
|
||||
if isinstance(m, (Detect, Segment)):
|
||||
|
@ -111,7 +111,7 @@ class YOLO:
|
||||
self.model.fuse()
|
||||
|
||||
@smart_inference_mode()
|
||||
def predict(self, source, return_outputs=True, **kwargs):
|
||||
def predict(self, source, return_outputs=False, **kwargs):
|
||||
"""
|
||||
Visualize prediction.
|
||||
|
||||
@ -191,6 +191,9 @@ class YOLO:
|
||||
self.trainer.model = self.trainer.get_model(weights=self.model if self.ckpt else None, cfg=self.model.yaml)
|
||||
self.model = self.trainer.model
|
||||
self.trainer.train()
|
||||
# update model and configs after training
|
||||
self.model, _ = attempt_load_one_weight(str(self.trainer.best))
|
||||
self.overrides = self.model.args
|
||||
|
||||
def to(self, device):
|
||||
"""
|
||||
|
@ -105,7 +105,7 @@ class BasePredictor:
|
||||
def postprocess(self, preds, img, orig_img):
|
||||
return preds
|
||||
|
||||
def setup(self, source=None, model=None, return_outputs=True):
|
||||
def setup(self, source=None, model=None, return_outputs=False):
|
||||
# source
|
||||
source = str(source if source is not None else self.args.source)
|
||||
is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)
|
||||
@ -161,7 +161,7 @@ class BasePredictor:
|
||||
return model
|
||||
|
||||
@smart_inference_mode()
|
||||
def __call__(self, source=None, model=None, return_outputs=True):
|
||||
def __call__(self, source=None, model=None, return_outputs=False):
|
||||
self.run_callbacks("on_predict_start")
|
||||
model = self.model if self.done_setup else self.setup(source, model, return_outputs)
|
||||
model.eval()
|
||||
|
@ -24,7 +24,7 @@ class DetectionValidator(BaseValidator):
|
||||
self.data_dict = yaml_load(check_file(self.args.data), append_filename=True) if self.args.data else None
|
||||
self.is_coco = False
|
||||
self.class_map = None
|
||||
self.metrics = DetMetrics(save_dir=self.save_dir, plot=self.args.plots)
|
||||
self.metrics = DetMetrics(save_dir=self.save_dir)
|
||||
self.iouv = torch.linspace(0.5, 0.95, 10) # iou vector for mAP@0.5:0.95
|
||||
self.niou = self.iouv.numel()
|
||||
|
||||
@ -34,8 +34,7 @@ class DetectionValidator(BaseValidator):
|
||||
for k in ["batch_idx", "cls", "bboxes"]:
|
||||
batch[k] = batch[k].to(self.device)
|
||||
|
||||
nb, _, height, width = batch["img"].shape
|
||||
batch["bboxes"] *= torch.tensor((width, height, width, height), device=self.device) # to pixels
|
||||
nb = len(batch["img"])
|
||||
self.lb = [torch.cat([batch["cls"], batch["bboxes"]], dim=-1)[batch["batch_idx"] == i]
|
||||
for i in range(nb)] if self.args.save_hybrid else [] # for autolabelling
|
||||
|
||||
@ -50,6 +49,7 @@ class DetectionValidator(BaseValidator):
|
||||
self.nc = head.nc
|
||||
self.names = model.names
|
||||
self.metrics.names = self.names
|
||||
self.metrics.plot = self.args.plots
|
||||
self.confusion_matrix = ConfusionMatrix(nc=self.nc)
|
||||
self.seen = 0
|
||||
self.jdict = []
|
||||
@ -95,7 +95,9 @@ class DetectionValidator(BaseValidator):
|
||||
|
||||
# Evaluate
|
||||
if nl:
|
||||
tbox = ops.xywh2xyxy(bbox) # target boxes
|
||||
height, width = batch["img"].shape[2:]
|
||||
tbox = ops.xywh2xyxy(bbox) * torch.tensor(
|
||||
(width, height, width, height), device=self.device) # target boxes
|
||||
ops.scale_boxes(batch["img"][si].shape[1:], tbox, shape,
|
||||
ratio_pad=batch["ratio_pad"][si]) # native-space labels
|
||||
labelsn = torch.cat((cls, tbox), 1) # native-space labels
|
||||
|
@ -22,7 +22,7 @@ class SegmentationValidator(DetectionValidator):
|
||||
def __init__(self, dataloader=None, save_dir=None, pbar=None, logger=None, args=None):
|
||||
super().__init__(dataloader, save_dir, pbar, logger, args)
|
||||
self.args.task = "segment"
|
||||
self.metrics = SegmentMetrics(save_dir=self.save_dir, plot=self.args.plots)
|
||||
self.metrics = SegmentMetrics(save_dir=self.save_dir)
|
||||
|
||||
def preprocess(self, batch):
|
||||
batch = super().preprocess(batch)
|
||||
@ -31,13 +31,15 @@ class SegmentationValidator(DetectionValidator):
|
||||
|
||||
def init_metrics(self, model):
|
||||
head = model.model[-1] if self.training else model.model.model[-1]
|
||||
self.is_coco = self.data.get('val', '').endswith(f'coco{os.sep}val2017.txt') # is COCO dataset
|
||||
val = self.data.get('val', '') # validation path
|
||||
self.is_coco = isinstance(val, str) and val.endswith(f'coco{os.sep}val2017.txt') # is COCO dataset
|
||||
self.class_map = ops.coco80_to_coco91_class() if self.is_coco else list(range(1000))
|
||||
self.args.save_json |= self.is_coco and not self.training # run on final val if training COCO
|
||||
self.nc = head.nc
|
||||
self.nm = head.nm if hasattr(head, "nm") else 32
|
||||
self.names = model.names
|
||||
self.metrics.names = self.names
|
||||
self.metrics.plot = self.args.plots
|
||||
self.confusion_matrix = ConfusionMatrix(nc=self.nc)
|
||||
self.plot_masks = []
|
||||
self.seen = 0
|
||||
@ -97,7 +99,9 @@ class SegmentationValidator(DetectionValidator):
|
||||
|
||||
# Evaluate
|
||||
if nl:
|
||||
tbox = ops.xywh2xyxy(bbox) # target boxes
|
||||
height, width = batch["img"].shape[2:]
|
||||
tbox = ops.xywh2xyxy(bbox) * torch.tensor(
|
||||
(width, height, width, height), device=self.device) # target boxes
|
||||
ops.scale_boxes(batch["img"][si].shape[1:], tbox, shape,
|
||||
ratio_pad=batch["ratio_pad"][si]) # native-space labels
|
||||
labelsn = torch.cat((cls, tbox), 1) # native-space labels
|
||||
|
Reference in New Issue
Block a user