YOLOv5 source code line by line super-detailed comments and interpretation – project directory structure analysis

Time:2024-6-12

catalogs

preamble

I. Project catalog structure

1.1 .github folder

 1.2 datasets

1.3 data folder

1.4 models folder

 1.5 runs folder

 1.6 utils folder

 1.7 Other first-level catalog documents

YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

I. Project catalog structure

YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

After downloading the source code and configuring the environment, you can see the overall directory of YOLOv5 as shown above. Let’s analyze them one by one

1.1 .github folder

YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

 githubIt’s for storing some “configurations” on github, which is not important and we can leave it alone.

1.2 datasets

YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

The source code we just downloaded does not contain this folder.datasetsIt is used to store your own dataset, which is divided into two parts: images and labels.Also under each folder, it should be divided into TRAIN, VAL.The .cache file is a cache file, which loads the data into memory, so that the next call is fast. You can name it, for example, my flame dataset is called “fire_yolo_format”.

1.3 data folder

 YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

data folderIt is mainly to store someConfiguration file for hyperparameters(e.g., a .yaml file) is used to configure the paths to the training and test sets and the validation set, which also includes the number of target assays and the names of the assays; and theSome of the official images provided for testingYOLOv5 has about 30 hyperparameters for various training settings. Better initial guesses produce better final results, so it is important to initialize these values correctly before evolution. If it isIf you train your own dataset, then you need to modify the yaml file in it. But be warned.It is not recommended to put your own dataset under this path, it is recommended to put the dataset under the same level directory of the YOLOv5 project. Detailed explanation:
  • hyps folder   # Store hyperparameter configuration files in yaml format.
    • hyps.scratch-high.yaml  # High data enhancement for large models i.e. v3, v3-spp, v5l, v5x
    • hyps.scratch-low.yaml  # Low data enhancement for smaller models i.e. v5n, v5s
    • hyps.scratch-med.yaml  # in Data Enhancement for medium sized models. i.e. v5m
  • images  # There are two official test images stored #
  • scripts  # Store dataset and weights download shell scripts
    • download_weights.sh  # Download the weights file, including the P5 and P6 versions in five sizes, and the classifier version
    • get_coco.sh   Download coco dataset
    • get_coco128.sh  # Download coco128 (only 128)
  • Argoverse.yaml  # Each .yaml file that follows corresponds to data in one of the standard dataset formats
  • coco.yaml   # COCO dataset profiles
  • coco128.yaml   # COCO128 dataset profile
  • voc.yaml   # VOC dataset profiles

1.4 models folder

YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

modelsisModel folder. It contains mainly configuration files and functions for building the network, and it contains four different versions of the project, which ares、m、l、x. The size of these versions is obvious from the name.Their detection speed is from fast to slow, but their accuracy is from low to high.If you train your own dataset, you need to modify the corresponding yaml file here to train your own model. Detailed explanation:
  • hub  # Store yolov5 target detection network model configuration files for all versions of yolov5.
    • anchors.yaml  # Default anchors for COCO data
    • yolov3-spp.yaml  # yolov3 with spp
    • yolov3-tiny.yaml  # lite yolov3
    • yolov3.yaml  # yolov3
    • yolov5-bifpn.yaml  # yolov5l with binary fpn
    • yolov5-fpn.yaml  # yolov5 with fpn
    • yolov5-p2.yaml  # (P2, P3, P4, P5) are all output with the same width and depth as the large version, which corresponds to the ability to detect smaller objects than the large version.
    • yolov5-p34.yaml  # Outputs only (P3, P4) with the same width and depth as the small version, which corresponds to a more focused detection of small and medium-sized objects than the small version
    • yolov5-p6.yaml  # (P3, P4, P5, P6) are all output with the same width and depth as the large version, which corresponds to the ability to detect larger objects than the large version.
    • yolov5-p7.yaml  # (P3, P4, P5, P6, P7) are all output with the same width and depth as the large version, which equates to detecting larger objects than the large version.
    • yolov5-panet.yaml  # yolov5l with PANet #
    • yolov5n6.yaml  # (P3, P4, P5, P6) are all output, width and depth are the same as the nano version, which is equivalent to detecting larger objects than the nano version, anchor is predefined
    • yolov5s6.yaml  # (P3, P4, P5, P6) are all output, width and depth are the same as the small version, which is equivalent to detecting larger objects than the small version, anchor is predefined
    • yolov5m6.yaml   # (P3, P4, P5, P6) are all output, width and depth are the same as the middle version, which is equivalent to detecting larger objects than the middle version, anchor is predefined
    • yolov5l6.yaml   # (P3, P4, P5, P6) are output, the width and depth are the same as the large version, which is equivalent to detecting larger objects than the large version, the anchor has been predefined, presumably a product of the author’s experiments
    • yolov5x6.yaml   # (P3, P4, P5, P6) are all output, width and depth are the same as the Xlarge version, which is equivalent to being able to detect larger objects than the Xlarge version, anchor is predefined
    • yolov5s-ghost.yaml   # backbone’s convolution replaced with yolov5s in GhostNet form, anchor predefined
    • yolov5s-transformer.yaml  # backbone final C3 convolution added Transformer module for yolov5s, anchor predefined
  • _int_.py   # Empty
  • common.py   # Put some of the network structure of the definition of the general module, including autopad, Conv, DWConv, TransformerLayer and so on
  • experimental.py   # Code of an experimental nature, including MixConv2d, cross-layer weights Sum, etc.
  • tf.py  # tensorflow version of yolov5 code
  • yolo.py  # yolo specific modules, including BaseModel, DetectionModel, ClassificationModel, parse_model, etc.
  • yolov5l.yaml   # yolov5l network model profile, large version, depth 1.0, width 1.0
  • yolov5m.yaml   # yolov5m network model profile, middle version, depth 0.67, width 0.75
  • yolov5n.yaml   # yolov5n network model profile, nano version, depth 0.33, width 0.25
  • yolov5s.yaml   # yolov5s network model profile, small version, depth 0.33, width 0.50
  • yolov5x.yaml   # yolov5x network model profile, Xlarge version, depth 1.33, width 1.25

1.5 runs folder

YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

runsIt’s some output files when we run it. An exp folder is generated for each run.

YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

Detailed explanation:
  • detect   # Test the model, output the image and label the image with objects and probabilities
  • train    # Train the model, output content, model (best, latest) weights, confusion matrix, F1 curves, hyperparameter files, P curves, R curves, PR curves, result files (loss values, P, R), and so onexpn
    • expn# nth experimental data
    • confusion_matrix.png   # Confusion matrix
    • P_curve.png   # Accuracy vs. confidence plot line
    • R_curve.png  # Plot line of accuracy vs. confidence level
    • PR_curve.png  # Plot lines of precision vs. recall
    • F1_curve.png   # Relationship between F1 scores and confidence (x-axis)
    • labels_correlogram.jpg  # Predicted tag aspect and position distribution
    •  results.png   # Various loss and metrics (p, r, mAP, etc., see utils/metrics for details) curves
    • results.csv  # Raw result data corresponding to the png above
    • hyp.yaml  # Hyperparameter log files
    • opt.yaml  # Model option log files
    • train_batchx.jpg  # Training set image x (labeled)
    • val_batchx_labels.jpg  # Validation set image x (with labeling)
    • val_batchx_pred.jpg  # Validation set image x (with predictive labeling)
    • weights  # Weights
    • best.pt  # Best historical weights
    • last.pt   # Weight of last test point
    • labels.jpg  # 4 graphs, 4 graphs, (1, 1) denotes the amount of data in each category
(1, 2) bounding_box for real labeling (2, 1) Coordinates of the center point of the real labeling (2, 2) Real labeled matrix width and height

1.6 utils folder

   YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

 utilsTools folder. Stores the functions of the tools class, which includes the loss function, the metrics function, the plots function, and so on. Detailed explanation:
  • aws   # Resume interrupted training, and aws platform usage related tools
  • flask_rest_api  # flask-related tools
  • google_app_engine   # Tools related to Google App Engine
  • loggers    # Log Printing
  • _init_.py    # notebook initialization, checking system software and hardware
  • activations.py  # Activation function
  • augmentations  # Store various image enhancement techniques
  • autoanchor.py    # Auto-generated anchor frames
  • autobatch.py   # Automatic generation of batch sizes
  • benchmarks.py   # Perform performance evaluation of the model (in terms of inference speed and memory footprint)
  • callbacks.py   # Callback functions, mainly for loggers
  • datasets  # dateset and dateloader definition code
  • downloads.py   # Google Cloud Drive Content Download
  • general.py   # Project-wide generic code, related utility function implementation
  • loss.py   # Store the various loss functions
  • metrics.py   # Model validation metrics, including ap, confusion matrix, etc.
  • plots.py   # Plotting related functions such as plotting loss, ac curves, and also storing a bbox as an image separately
  • torch_utils.py   # Auxiliary Functions

1.7 Other first-level catalog documents

YOLOv5 source code line by line super-detailed comments and interpretation - project directory structure analysis

Detailed explanation:
  • .dockerignore   # docker’s ignore file
  • .gitattributes   To be used for the purpose of transferring .ipynbSuffixed files cull GitHub language statistics
  • .gitignore   # docker’s ignore file
  • CONTRIBUTING.md  # markdown formatting instructions document
  • detect.py   # Target detection prediction scripts
  • export.py  # Model export
  • hubconf.py  # pytorch hub related
  • LICENSE    # Certificates
  • README.md    # markdown formatting instructions document
  • requirements.txt # The dependencies can be downloaded via the pip install requirement
  • setup.cfg  # Project package files
  • train.py   # Target detection training scripts
  • tutorial.ipynb  # Target Detection Hands-On Tutorial
  • val.py  # Target detection validation scripts
  • yolov5s.pt   # coco dataset model pre-training weights that are automatically downloaded from the web when running code

Recommended Today

Unity — Physics Engine —- RigidBody with collider

  1. The purpose of a RigidBody is to give an object physical properties (such as gravity, sassafras, etc.) 2. If we want the object to be able to collide with other objects, we need one more component — the Colider collider component. 1. The image above shows the collider components provided in Unity with […]