DOI: 10.5281/zenodo.11204798
title: Supplementary Materials for Learning Manufacturing Computer Vision Systems Using Tiny YOLOv4

description: About This Dataset

This repository contains the supplementary materials presented in the publication “Learning Manufacturing Computer Vision Systems Using Tiny YOLO v4” by Medina, A., Bradley, R., Xu, W., Ponce, P., Anthony, B., and Molina, A. that can be found with the following DOI 10.3389/frobt.2024.1331249

There are three files in this repository:



dataset.zip

YOLOv4_object_detection.ipynb

deploy.py


dataset.zip

This Dataset is for an example used for education purposes. It is a small dataset that is adapted from the following Kaggle repository, authored by Ruthger Righart https://www.kaggle.com/datasets/rrighart/jarlids/data. One of the activities proposed is to teach students how to find, download and review a free dataset, so this is the example given.

Another activity is to teach how to label images to create a custom dataset. The images (with extension .JPG) from the original repository are used. The labels (with extension .txt) were created by the authors of the Learning Manufacturing Computer Vision Systems Using Tiny YOLOv4 paper. The authors used the free tool labelImg, from GitHub repository (https://github.com/HumanSignal/labelImg), to label the images with object bounding boxes and corresponding labels in the YOLO format.

The dataset contains 238 images and corresponding labels, with files named “p<num>.JPG” and “p<num>.txt”. The text labels are formatted in the YOLO format with each row in the .txt file corresponding to one object in the image. Each row contains 5 elements: The object identifier, top left corner x coordinate, top left corner y coordinate, height, and width, separated by a whitespace. The object identifier represents good cans as 0 and defective cans as 1.

YOLOv4_object_detection.ipynb

This notebook was created to give the user a step-by-step tutorial on how to train a YOLOv4 algorithm with a custom dataset using a free GPU on Google Collab, the prerequisite to use it are:



To have ready the dataset.

Have the training txt file with the path to all images used for training.

Have the test txt file with the path to all images used for testing.


There are other requirements like cloning a GitHub repository and altering certain files on that repository; however, those steps are discussed within the notebook.

At the end of the notebook an example on how to test the trained model with images and/or videos is shown, however since Google Collab doesn’t have access to the physical computer of the user live stream video is not part of the example.

deploy.py

Disclaimer: This code is not optimized, and its intended purpose is to teach students how to run YOLO on a raspberry pi using the OpenCV library.

To use this code with different files or datasets, be sure to change the two parameters inside the net3 variable which are the cfg file used while training the algorithm and the weights file. You should also change the class list to include your classes, keeping in mind that the classes order must correspond to the order of the labeling process and class 0 is the first one on the list.

Also to change the Title of the created image prompt you shout go to the line calling the imshow method and change the ‘Tiny YOLOv4’ string.

This algorithm uses the first camera it finds and opens up a display image with the detected objects surrounded by a bounding box, on top of that box the top predicted class is going to show, to change color of bounding boxes or text change the rectangle method where it says GREEN as well as in the next code line ant change the number to change the thickness of the line.

This code has a hardcoded confidence threshold for both the YOLO objectevness score and the class score, this can be found in the NMSBoxes method and the if confidence line accordingly. The main value to change first is the if confidence value.

To close the image, you need to press the key ‘q’ as closing the display window is not going to work as it will reopen again.

Note: This code allows the pop-up window, which displays the detections, to be closed only when the "q" key is pressed. Simply closing the window will not work.