File size: 1,922 Bytes
4a690bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
Build Model
===========
In YOLOv7, the prediction will be ``Anchor``, and in YOLOv9, it will predict ``Vector``. The converter will turn the bounding box to the vector.
The overall model flowchart is as follows:
.. mermaid::
flowchart LR
Input-->Model;
Model--Class-->NMS;
Model--Anc/Vec-->Converter;
Converter--Box-->NMS;
NMS-->Output;
Load Model
~~~~~~~~~~
Using `create_model`, it will automatically create the :class:`~yolo.model.yolo.YOLO` model and load the provided weights.
Arguments:
- **model**: :class:`~yolo.config.config.ModelConfig`
The model configuration.
- **class_num**: :guilabel:`int`
The number of classes in the dataset, used for the YOLO's prediction head.
- **weight_path**: :guilabel:`Path | bool`
The path to the model weights.
- If `False`, weights are not loaded.
- If :guilabel:`True | None`, default weights are loaded.
- If a `Path`, the model weights are loaded from the specified path.
.. code-block:: python
model = create_model(cfg.model, class_num=cfg.dataset.class_num, weight_path=cfg.weight)
model = model.to(device)
Deploy Model
~~~~~~~~~~~~
In the deployment version, we will remove the auxiliary branch of the model for fast inference. If the config includes ONNX and TensorRT, it will load/compile the model to ONNX or TensorRT format after removing the auxiliary branch.
.. code-block:: python
model = FastModelLoader(cfg).load_model(device)
Autoload Converter
~~~~~~~~~~~~~~~~~~
Autoload the converter based on the model type (v7 or v9).
Arguments:
- **Model Name**: :guilabel:`str`
Used for choosing ``Vec2Box`` or ``Anc2Box``.
- **Anchor Config**: The anchor configuration, used to generate the anchor grid.
- **model**, **image_size**: Used for auto-detecting the anchor grid.
.. code-block:: python
converter = create_converter(cfg.model.name, model, cfg.model.anchor, cfg.image_size, device)
|