Skip to content

Commit

Permalink
[YOLOV8] Update version (#1138)
Browse files Browse the repository at this point in the history
* update as per yolov8 updates

* update setup.py; removed unused imports

* style

* remove nm

* fix segmentation

* update to remove classification

* make sure current device is set when no gpus availabble
  • Loading branch information
dsikka committed Jul 25, 2023
1 parent 2be7087 commit 982938b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _parse_requirements_file(file_path):
"opencv-python<=4.6.0.66",
]
_yolo_integration_deps = [
"torchvision>=0.3.0,<0.14",
"torchvision>=0.3.0,<=0.15.1",
"opencv-python<=4.6.0.66",
]
_openpifpaf_integration_deps = [
Expand All @@ -142,7 +142,7 @@ def _parse_requirements_file(file_path):
"pycocotools >=2.0.6",
"scipy==1.10.1",
]
_yolov8_integration_deps = _yolo_integration_deps + ["ultralytics==8.0.30"]
_yolov8_integration_deps = _yolo_integration_deps + ["ultralytics==8.0.124"]
_transformers_integration_deps = [
f"{'nm-transformers' if is_release else 'nm-transformers-nightly'}"
f"~={version_base}",
Expand Down
14 changes: 4 additions & 10 deletions src/deepsparse/yolov8/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,14 @@ def process_engine_outputs(
)

def process_engine_outputs_seg(
self, engine_outputs: List[numpy.ndarray], nm: int = 32, **kwargs
self, engine_outputs: List[numpy.ndarray], nc: int = 80, **kwargs
) -> YOLOSegOutput:
"""
The pathway for processing the outputs of the engine for YOLOv8 segmentation.
:param engine_outputs: list of numpy arrays that are the output of the engine
forward pass
:param nm: number of mask protos. It is information needed to perform NMS on the
segmentation output. It can be calculated in the following way:
dims = bboxes + classes + nm
where:
- bboxes = 4
- classes = 80 (explicit assumption -> we are using COCO dataset)
- dims = 116 (comes from the fact that
detection.shape == [B, dims, 8400])
: params nc: number of classes. If not provided, calculated as
detection.shape[1] - 4
:return: outputs of engine post-processed into an object in the `output_schema`
format of this pipeline
"""
Expand All @@ -131,9 +125,9 @@ def process_engine_outputs_seg(
# NMS
detections_output = self.nms_function(
outputs=detections,
nc=nc,
iou_thres=kwargs.get("iou_thres", 0.25),
conf_thres=kwargs.get("conf_thres", 0.45),
nm=nm,
multi_label=kwargs.get("multi_label", False),
)

Expand Down
29 changes: 14 additions & 15 deletions src/deepsparse/yolov8/utils/validation/deepsparse_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@

from tqdm import tqdm

import torch
from deepsparse.yolov8.utils.validation.helpers import schema_to_tensor
from ultralytics.yolo.data.utils import check_det_dataset
from ultralytics.yolo.utils import (
DEFAULT_CFG,
LOGGER,
RANK,
SETTINGS,
TQDM_BAR_FORMAT,
callbacks,
)
from ultralytics.yolo.utils import LOGGER, TQDM_BAR_FORMAT, callbacks
from ultralytics.yolo.utils.ops import Profile
from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode

Expand All @@ -41,8 +35,9 @@ def __call__(self, classes: Dict[int, str]):
# for validation when self.training is True
callbacks.add_integration_callbacks(self)
self.run_callbacks("on_val_start")
if not torch.cuda.is_available():
self.args.device = "cpu"
self.device = select_device(self.args.device, self.args.batch)
self.args.half &= self.device.type != "cpu"
self.data = check_det_dataset(self.args.data)
if isinstance(self.data["path"], str):
self.data["path"] = Path(self.data["path"])
Expand All @@ -53,7 +48,7 @@ def __call__(self, classes: Dict[int, str]):
)

self.dataloader = self.dataloader or self.get_dataloader(
self.data.get("val") or self.data.set("test"), self.args.batch
self.data.get(self.args.split), self.args.batch
)

dt = Profile(), Profile(), Profile(), Profile()
Expand Down Expand Up @@ -93,18 +88,22 @@ def __call__(self, classes: Dict[int, str]):
stats = self.get_stats()
self.check_stats(stats)
self.print_results()
self.speed = tuple(
x.t / len(self.dataloader.dataset) * 1e3 for x in dt
self.speed = dict(
zip(
self.speed.keys(),
(x.t / len(self.dataloader.dataset) * 1e3 for x in dt),
)
) # speeds per image
self.finalize_metrics()
self.run_callbacks("on_val_end")

self.logger.info(
LOGGER.info(
"Speed: %.1fms pre-process, %.1fms inference, %.1fms loss, %.1fms post-process per image"
% self.speed
% tuple(self.speed.values())
)
if self.args.save_json and self.jdict:
with open(str(self.save_dir / "predictions.json"), "w") as f:
self.logger.info(f"Saving {f.name}...")
LOGGER.info(f"Saving {f.name}...")
json.dump(self.jdict, f) # flatten and save
stats = self.eval_json(stats) # update stats
return stats
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ def __init__(
dataloader=None,
save_dir=None,
pbar=None,
logger=None,
args=None,
):
DetectionValidator.__init__(self, dataloader, save_dir, pbar, logger, args)
DetectionValidator.__init__(self, dataloader, save_dir, pbar, args)
DeepSparseValidator.__init__(self, pipeline)

# deepsparse edit: replaced argument `model` with `classes`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
logger=None,
args=None,
):
SegmentationValidator.__init__(self, dataloader, save_dir, pbar, logger, args)
SegmentationValidator.__init__(self, dataloader, save_dir, pbar, args)
DeepSparseValidator.__init__(self, pipeline)

# deepsparse edit: replaced argument `model` with `classes`
Expand Down
2 changes: 1 addition & 1 deletion src/deepsparse/yolov8/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
@click.option(
"--subtask",
default="detection",
type=click.Choice(["detection", "classification", "segmentation"]),
type=click.Choice(["detection", "segmentation"]),
show_default=True,
help="A subtask of YOLOv8 to run. Default is `detection`.",
)
Expand Down

0 comments on commit 982938b

Please sign in to comment.