Home  >  Article  >  Technology peripherals  >  Seven Steps to Prepare Datasets for Image AI Projects

Seven Steps to Prepare Datasets for Image AI Projects

WBOY
WBOYforward
2023-09-26 23:45:04916browse

Translator| ##I wonder if you have noticed that the data set may be the most overlooked part of the machine learning project. To most people, a dataset is nothing more than a collection of pre-made images that have been quickly put together or downloaded. In fact, datasets are the cornerstone of any image-based artificial intelligence (AI) project. For any machine learning project aiming to achieve high accuracy, creating and managing a balanced and well-structured dataset is crucial.

# However, creating a dataset is not as simple as collecting hundreds of images. When we try to start an AI project, we are likely to encounter various hidden dangers. Below, I'll discuss seven typical steps you can take to create your own dataset so you can gain insight into the importance of dataset size, possible data omissions, and converting a dataset into a database.

#Note: These steps will mainly apply to object detection and classification projects that include image datasets. Other project types, such as NLP

or graphics projects, require a different approach.

Steps

1: Image size

Normally, neural networks can only process images of a specific size, and images exceeding a threshold will be forced to be reduced. This means that before using the dataset, we need to choose a suitable neural network and resize the image accordingly

As you know, if the image Reducing the size may lead to a significant decrease in accuracy or even the disappearance of small objects on the image, thus causing damage to the entire recognition process. As shown below, you need to detect the license plate number in the image captured by the security camera, and the license plate only accounts for a small part of the entire image. Therefore, when the neural network shrinks the image, the license plate number may become too small to be recognized

As shown in the figure below, if you can understand the image sizes that the network can use, it will help you to crop the appropriate data set images.

##Although the image size that most neural networks can handle is relatively small, such as Seven Steps to Prepare Datasets for Image AI Projects

Yolo The latest neural networks such as v5x6

are capable of processing larger resolution images. For example, Yolo v5x

s

Seven Steps to Prepare Datasets for Image AI Projects6

can handle images up to 1280 pixels wide image. Step 2: Understandyourenvironment

In order to ensure that the data set can accurately reflect the real images that the neural network needs to recognize during operation, we need to pay attention to the following factors when collecting the data set: Type of camera, smartphone camera or security camera

Image The size

  1. The location of the camera, whether it is indoors or outdoors
  2. Weather conditions , such as light, rain, fog, snow, etc.
  3. With a clear understanding of the real images the neural network is processing, we can create a data set that accurately reflects those of interest. objects, and their environment.
  4. Collecting common images from Google might be considered the easiest and fastest way to assemble a large dataset. However, this method is actually difficult to achieve high accuracy requirements. As shown below, images from Google or photo databases are often "beautified" compared to images captured by real cameras

A data set that is too "beautiful" is likely to lead to higher test accuracy. This means that the neural network will only perform well on test data (a collection of images purified from the dataset), but will perform poorly in real-world conditions and result in poor accuracy.

Step

3

Seven Steps to Prepare Datasets for Image AI Projects:

Format and Comments

Another important aspect we need to pay attention to is: the format of the image. Before starting your project, check which formats your chosen framework supports and whether your images can meet these requirements. Although the current framework can support multiple image formats, there are still problems with formats such as .jfif.

Annotation data can be used to specify bounding boxes, file names, and the different structures that can be used. Generally, different neural networks and frameworks require different annotation methods. Some require absolute coordinates containing the bounding box location, others require relative coordinates; some require each image to be accompanied by a separate annotated .txt file, while others require Some require only one file containing all comments. As you can see, even if your dataset has good images, it won't help if your framework can't handle the annotations.

Step 4: Training and validation subsets

For training purposes, the data set is usually divided into two subsets:

  1. Training subset- It is a set of images. The neural network will be trained on this set of images. Its proportion is 70% to 80% of the total number of images.
  2. Validation subset- are smaller images used to check how well the neural network learns during training set. Its proportion is between 20% and 30% of the total number of images.

Seven Steps to Prepare Datasets for Image AI Projects

Typically, a neural network will use object features extracted from a training subset to "learn" The appearance of an object. That is, after a training period (epoch), the neural network looks at the validation subset data and tries to guess what it can "Look " to those objects. Whether it is a correct or wrong guess, its structure allows the neural network to learn further.

While this method has been widely used and proven to achieve good results, we prefer to adopt a different approach that combines the data The set is divided into the following subsets:

  1. Training subset - accounts for ## of the total number of images # 70%
  2. Validation subset - Accounting for the total number of images 20%
  3. Test data set - Approx. 10%

Seven Steps to Prepare Datasets for Image AI Projects

## of the total number of images due to test sub The set contains images from the dataset that the neural network has never seen, so developers can test the model on this subset to see how well it performs when run manually and which images it has difficulty with. In other words, this subset will help identify where the neural network may make mistakes before the project starts, thereby avoiding excessive retraining after the project starts.

Step

5: Datamissing

If you use If the data used to train a machine learning algorithm contains exactly the information you are trying to predict, a data breach may occur. As shown in the figure below, from an image recognition perspective, data leakage occurs when photos of the same object in the training and validation subsets are very similar. Obviously, missing data is extremely detrimental to the quality of neural networks.

Seven Steps to Prepare Datasets for Image AI Projects##Essentially, after the model sees an image in the training data set, it first extracts its features, Then go into the validation dataset and find the exact same (or very similar) images you saw. Therefore, rather than saying that the model is actually learning, it is better to say that it is just memorizing various information. Sometimes this results in ridiculously high accuracy on the validation dataset (e.g., as high as

98%), but very low accuracy in production. One of the most commonly used data set segmentation methods is to randomly shuffle the data and then select the top

70% images are put into the training subset, and the remaining 30% are put into the validation subset. This method can easily lead to data omissions. As shown in the figure below, our immediate priority is to remove all "duplicate" photos from the dataset and check whether similar photos exist in both subsets.

For this, we can use a simple script to automatically perform duplicate deletion. Of course, you can adjust the duplication threshold, for example: only delete completely duplicate pictures, or pictures with a similarity as high as 90% , etc. In general, the more duplicate content is removed, the more accurate the neural network will produce.

Step 6: Large Data Set Database

If your data set is quite large, for example: more than 10million images, and has dozens For object classes and subclasses, we recommend that you create a simple database to store data set information. The reason behind this is actually very simple: with large data sets, it is difficult to keep track of all the data. Therefore, without some structured processing of the data, we will not be able to analyze it accurately.

Through the database, you can quickly diagnose the data set and find out that: too few pictures in a specific category will make it difficult for the neural network to recognize the object; The distribution of images between categories is not even enough; there are too many Google images in a specific category, resulting in a low accuracy score for that category, etc.

With a simple database, we can include the following information:

  1. ## File name
  2. File path
  3. Comment data
  4. Class data
  5. Data source (from production environment, Google, etc.)
  6. Object type, name and other object-related information

The database is indispensable for collecting data sets and statistical data Tool of. It helps us quickly and easily see how balanced the dataset is and how many high-quality images are in each category (from a neural network perspective). With data like the one visualized below, we can analyze it faster and compare it to the recognition results to find the root cause of poor accuracy

Seven Steps to Prepare Datasets for Image AI Projects

What needs to be re-written is: One issue worth noting is that the reason for the low accuracy may be due to a smaller number of images or a higher proportion of Google Photos in a certain category. By creating such a database, the time for production, testing and model retraining can be greatly reduced

Step 7 :Dataset Augmentation

As a technique used to increase the number of images, data augmentation is the simple or complex transformation of the data Processes, such as through flipping or style transformation, we can improve the validity of the data. The effective data set obtained based on this does not require excessive training. As shown in the image below, such data transformations can be as simple as simply rotating the image by 90 degrees, or as complex as adding solar flares to the image to simulate a backlit photo or lens Flare.

Seven Steps to Prepare Datasets for Image AI Projects

Typically, these enhanced conversions are automated. For example, we can prepare a Python library specifically for data augmentation. Currently, there are two types of data augmentation:

  1. Pre-training augmentation- At the beginning of the training process Previously, the data was augmented and added to the training subset. Of course, we can make such additions only after the data set has been divided into training and validation subsets to avoid the data omissions mentioned earlier.
  2. In-training enhancement- Use something similar to PyTorch The frame has built-in image transformation technology.

It is worth noting that increasing the size of the data set ten times does not make the neural network ten times more efficient. In fact, this may actually make the network perform worse than before. Therefore, we should only use enhancements that are relevant to production environments. For example, a camera installed in a building will not be exposed to rain when it is operating normally. So there is absolutely no need to add "rain" enhancement to the image.

knot

Although for those looking to apply AI to business, the dataset is The least exciting part. But it is undeniable that data sets are an important part of any image recognition project. Moreover, in most image recognition projects, the management and organization of data sets often takes a lot of time from the team. Finally, let’s summarize how you can get the best results from your AI projects by properly handling your datasets:

  1. Crop or adjust The size of the image to meet the requirements of the neural network
  2. #Collect real images based on weather and lighting conditions
  3. Construct annotations according to the requirements of the neural network
  4. Avoid using all images to train the network. A part needs to be reserved for testing
  5. Delete duplicate images in the validation data set to avoid data omission
  6. Create a database to quickly diagnose the data set
  7. Use data augmentation as little as possible to increase the number of images

Translator introduction

Julian Chen, 51CTO community editor, has more than ten years of IT experience Project implementation experience, good at managing and controlling internal and external resources and risks, and focusing on disseminating network and information security knowledge and experience.

Original title: 7 Steps To Prepare A Dataset For An Image-Based AI Project by Oleg Kokorin

The above is the detailed content of Seven Steps to Prepare Datasets for Image AI Projects. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51cto.com. If there is any infringement, please contact admin@php.cn delete