diff --git a/docs/datasets/detect/index.md b/docs/datasets/detect/index.md index 7eec93c..7ce8cf0 100644 --- a/docs/datasets/detect/index.md +++ b/docs/datasets/detect/index.md @@ -40,13 +40,12 @@ In this example, the first object is of class 0 (person), with its center at (0. The Ultralytics framework uses a YAML file format to define the dataset and model configuration for training Detection Models. Here is an example of the YAML format used for defining a detection dataset: -``` +```yaml train: val: nc: names: [, , ..., ] - ``` The `train` and `val` fields specify the paths to the directories containing the training and validation images, respectively. @@ -105,7 +104,7 @@ TODO ### COCO dataset format to YOLO format -``` +```python from ultralytics.yolo.data.converter import convert_coco convert_coco(labels_dir='../coco/annotations/') diff --git a/docs/datasets/segment/index.md b/docs/datasets/segment/index.md index 7d24e41..928d9f9 100644 --- a/docs/datasets/segment/index.md +++ b/docs/datasets/segment/index.md @@ -104,7 +104,7 @@ names: [ 'person', 'car' ] ### COCO dataset format to YOLO format -``` +```python from ultralytics.yolo.data.converter import convert_coco convert_coco(labels_dir='../coco/annotations/', use_segments=True) diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index a1166cb..759641f 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = '8.0.119' +__version__ = '8.0.120' from ultralytics.hub import start from ultralytics.vit.rtdetr import RTDETR diff --git a/ultralytics/nn/tasks.py b/ultralytics/nn/tasks.py index 38fd3fc..3c2ba06 100644 --- a/ultralytics/nn/tasks.py +++ b/ultralytics/nn/tasks.py @@ -243,6 +243,8 @@ class DetectionModel(BaseModel): m.stride = torch.tensor([s / x.shape[-2] for x in forward(torch.zeros(1, ch, s, s))]) # forward self.stride = m.stride m.bias_init() # only run once + else: + self.stride = torch.Tensor([32]) # default stride for i.e. RTDETR # Init weights, biases initialize_weights(self) diff --git a/ultralytics/vit/rtdetr/model.py b/ultralytics/vit/rtdetr/model.py index 5142056..259c7c9 100644 --- a/ultralytics/vit/rtdetr/model.py +++ b/ultralytics/vit/rtdetr/model.py @@ -5,6 +5,8 @@ RT-DETR model interface from pathlib import Path +import torch.nn as nn + from ultralytics.nn.tasks import RTDETRDetectionModel, attempt_load_one_weight, yaml_model_load from ultralytics.yolo.cfg import get_cfg from ultralytics.yolo.engine.exporter import Exporter @@ -37,7 +39,7 @@ class RTDETR: self.task = 'detect' self.model = RTDETRDetectionModel(cfg_dict, verbose=verbose) # build model - # Below added to allow export from yamls + # Below added to allow export from YAMLs self.model.args = DEFAULT_CFG_DICT # attach args to model self.model.task = self.task @@ -125,6 +127,23 @@ class RTDETR: """Get model info""" return model_info(self.model, verbose=verbose) + def _check_is_pytorch_model(self): + """ + Raises TypeError is model is not a PyTorch model + """ + pt_str = isinstance(self.model, (str, Path)) and Path(self.model).suffix == '.pt' + pt_module = isinstance(self.model, nn.Module) + if not (pt_module or pt_str): + raise TypeError(f"model='{self.model}' must be a *.pt PyTorch model, but is a different type. " + f'PyTorch models can be used to train, val, predict and export, i.e. ' + f"'yolo export model=yolov8n.pt', but exported formats like ONNX, TensorRT etc. only " + f"support 'predict' and 'val' modes, i.e. 'yolo predict model=yolov8n.onnx'.") + + def fuse(self): + """Fuse PyTorch Conv2d and BatchNorm2d layers.""" + self._check_is_pytorch_model() + self.model.fuse() + @smart_inference_mode() def export(self, **kwargs): """ diff --git a/ultralytics/yolo/cfg/default.yaml b/ultralytics/yolo/cfg/default.yaml index 62202b5..960b2fa 100644 --- a/ultralytics/yolo/cfg/default.yaml +++ b/ultralytics/yolo/cfg/default.yaml @@ -19,7 +19,7 @@ workers: 8 # (int) number of worker threads for data loading (per RANK if DDP) project: # (str, optional) project name name: # (str, optional) experiment name, results saved to 'project/name' directory exist_ok: False # (bool) whether to overwrite existing experiment -pretrained: True # (bool) whether to use a pretrained model +pretrained: True # (bool | str) whether to use a pretrained model (bool) or a model to load weights from (str) optimizer: auto # (str) optimizer to use, choices=[SGD, Adam, Adamax, AdamW, NAdam, RAdam, RMSProp, auto] verbose: True # (bool) whether to print verbose output seed: 0 # (int) random seed for reproducibility