Object Detection (YOLOv4)

YOLOv4 Training Parameters and Value Ranges

Table 1 describes the names, types, value ranges, default values, and descriptions of the YOLOv4 training parameters.

Table 1 YOLOv4 training parameters (yolov4_mindspore/model_train.py)

Parameter

Type

Value Range

Default Value

Description

--train_dataset_path

String

-

None

Path of the training dataset.

--pretrained_ckpt_path

String

-

"pre_trained_ckpt"

Path of the pre-trained model.

--train_output_path

String

-

"train_output_path"

Output path of the training result.

--device_id

Integer

[0,7]

0

ID of the NPU used for training.

--device_num

Integer

1,2,4,8

1

Number of NPUs used for training.

--rank_table_file

String

-

None

Used for multi-device training.

--input_width

Integer

A multiple of 32 within [192,1920]

1472

Width of the model input image.

--input_height

Integer

A multiple of 32 within [192,1920]

1472

Height of the model input image.

--split_ratio

Float

(0,1)

0.8

Ratio of the training dataset to the validation dataset.

--per_batch_size

Integer

[1, 3]

2

Number of image batches for training.

--lr

Float

(0,1)

0.0005

Training learning rate.

--t_max

Integer

[1,10000]

100

T-max learning rate parameter.

--max_epoch

Integer

[1,10000]

100

Number of training epochs.

--run_eval

Bool

True or False

True

Whether to perform evaluation during training.

--eval_start_epoch

Integer

[1,10000]

40

Sequence number of epochs from which evaluation is performed during training.

--auto_set_eval_interval

Bool

True or False

False

Whether to enable automatic evaluation. If this parameter is enabled, --eval_start_epoch and --eval_interval are invalid and do not need to be configured.

--eval_detail_info

Bool

True or False

False

Whether to perform detailed evaluation.

--eval_interval

Integer

[1,10000]

1

Evaluation interval. Retain the default value.

--min_score

Float

(0,1)

0.2

Minimum score for evaluation.

--nms_threshold

Float

(0,1)

0.3

NMS threshold for evaluation.

--max_box_num

Integer

[1,1000]

90

Maximum number of evaluation bounding boxes.

--multi_scale_input

Bool

True or False

False

Whether to enable multi-scale training.

--mosaic

Bool

True or False

False

Whether to enable data augmentation.

--self_fit

Bool

True or False

False

Adaptively adjust the model width and height based on the dataset analysis result.

--self_fit_prior_choice

String

'enlarge_image', 'shrink_image', 'enlarge_aspect_ratio', or 'shrink_aspect_ratio'

""

Priority policy for adaptively adjusting the model width and height. Only one of the four policies is supported and takes effect only when self_fit detects multiple scenarios.

--dump_preprocessed_image

Bool

True or False

False

Save the preprocessed images to MindInsight.

--reg_loss

String

"ciou" or "giou"

"ciou"

Loss calculation method.

--enable_modelarts

Bool

True or False

False

Whether to use ModelArts for training.

--data_url

String

-

None

Dataset path for the ModelArts training.

--train_output_url

String

-

None

Output path for the ModelArts training.

--checkpoint_url

String

-

None

Path of the pre-trained model for the ModelArts training.

--split_image

Bool

True or False

False

Manually enable the image split function for small object detection. This parameter is valid only when self_fit is set to False.

--split_resize_ratio

String

Range of the two numbers in a value: [0.1,10].

"1,1"

Scaling ratio of the original image. The two numbers in the value indicate the width and height.

--split_block_size

String

Range of the two numbers in a value: [192,1920]

"1472,1472"

Size of image blocks. The two numbers in the value indicate the width and height.

The width and height of an image block must be less than the width and height of the original image multiplied by the zoom-in ratio.

--split_overlap_size

String

Range of the two numbers in a value: [96, minimum value of split_block_size - 96]

"256,256"

Size of the overlapping area of image blocks. The two numbers in the value indicate the width and height.

--force_fp16

Bool

True or False

False

Whether to use the fp16 precision mode when exporting the OM model.

Note: The original SSD small object detection parameter split_auto will be discarded in later versions.

Training Command Reference for YOLOv4

Run the following command to start the YOLOv4 model training:

python3 model_train.py --train_dataset_path=/path_to/images --pretrained_ckpt_path=/path_to/ckpt --train_output_path=./outputs/ --device_num=1 --device_id=0 --per_batch_size=2 --input_width=1472 --input_height=1472 --max_epoch=20 --lr=0.0005 --min_score=0.01 --nms_threshold=0.5 --eval_start_epoch=20 --run_eval=True --split_ratio=0.8

The model training process is random. Use the evaluated accuracy. When the preceding parameters are used, you can view the training accuracy results of 10 images and 20 epochs in Figure 1.

Figure 1 Accuracy results of the YOLOv4 model training

Figure 2 shows the log information after the model training is complete.

Figure 2 Log information of the YOLOv4 model training

After the training is complete, the .ckpt, .a310.om, .a310p.om, and .air model files are generated in the output directory specified by the --train_output_path parameter.

YOLOv4 Evaluation Parameters and Value Ranges

The following table describes the names, types, value ranges, default values, and descriptions of the YOLOv4 evaluation parameters.

Table 2 YOLOv4 model evaluation parameters (yolov4_mindspore/model_eval.py)

Parameter

Type

Value Range

Default Value

Description

--eval_dataset_path

String

-

None

Path of the evaluation dataset.

--eval_ckpt_path

String

-

"pre_trained_ckpt"

Path of the trained model.

--eval_output_path

String

-

"eval_output_path"

Output path of the evaluation results.

--device_id

Integer

[0,7]

0

ID of the NPU used for evaluation.

--per_batch_size

Integer

The value can only be 1.

1

Number of image batches for evaluation.

--input_width

Integer

[192,1920]

Consistent with the value listed in the training parameter table

Width of the model input image.

--input_height

Integer

[192,1920]

Consistent with the value listed in the training parameter table

Height of the model input image.

--min_score

Float

(0,1) or -1

0.2

Minimum score for evaluation.

--nms_threshold

Float

(0,1)

0.6

NMS threshold for evaluation.

--max_box_num

Integer

[0,1000]

90

Maximum number of evaluation bounding boxes.

--eval_detail_info

Bool

True or False

True

Whether to perform detailed evaluation.

--enable_modelarts

Bool

True or False

False

Whether to use ModelArts for training.

--data_url

String

-

None

Dataset path for the ModelArts training.

--eval_output_url

String

-

None

Output path for the ModelArts training.

--checkpoint_url

String

-

None

Path of the pre-trained model for the ModelArts training.

Evaluation Command Reference for YOLOv4

The command for evaluating the YOLOv4 model is as follows:

python3 model_eval.py --eval_dataset_path=path_to/images --eval_ckpt_path=path_to/your_ckpt --eval_output_path=./outputs_eval/ --min_score=0.001 --nms_threshold=0.5

Use the checkpoint generated during the training to evaluate the model accuracy, as shown in Figure 3.

Figure 3 YOLOv4 model evaluation results

The folders and files shown in Figure 4 are generated in the evaluation directory. The ok_images, ng_fp_images, and ng_fn_images folders store the image evaluation results, and the statistics.csv file stores the corresponding accuracy results.

Figure 4 YOLOv4 model evaluation directory

New feature in version 3.0: Image-level accuracy evaluation metrics are added to the statistics.csv file.

Figure 5 Image-level accuracy evaluation metrics