Recently, grayscale map was used in the recognition of the competition in the laboratory. Because the official color has been modified, we can only use grayscale map for training recognition in the absence of official data, hoping to exclude the influence of color. However, some problems occurred when yOLO was used to train single-channel grayscale images. After the CFG configuration file was modified, segmentation fault errors occurred all the time. I did not find a similar question on Baidu. Finally, I found the answer on GitHub comments. The following is a record for the convenience of future generations.

YOLO’s training and recognition of color graph (three-channel) data has been described in detail on many excellent blogs.

Only the configurations that need to be modified for single channel training using YOLO are described here.

It’s simple, in three steps:

Step 1 Modify the source file:

Enter the following files:

/darknet/src/data.c
Copy the code

Find the load_data_detection method

data load_data_detection(int n, char **paths, int m, int w, int h, int boxes, int classes, float jitter, float hue, float saturation, float exposure)
{
    char **random_paths = get_random_paths(paths, n, m);
    int i;
    data d = {0};
    d.shallow = 0;

    d.X.rows = n;
    d.X.vals = calloc(d.X.rows, sizeof(float*));
    d.X.cols = h*w; // d.X.cols = h*w*3; // change h*w*3 to h*w
Copy the code

Here, h* W *3 is changed to H * W. Originally, it was thought that the number of channels in the data was only related to channels in the CFG configuration file. After channels were set to 1, segmentation faults immediately appeared when the YOLO training code was running, which occurred to me as it should be related to the source code. The original solution was to import the CFG file directly into the code, and then use channels variable. However, after careful consideration, I found that it was not possible, because there are many CFG configuration files provided in YOLO, and each user may use a different file. Importing a configuration file is not feasible, so a more elegant implementation is needed.

Step 2: recompile

Go to darknet folder and recompile:

make clean
make
Copy the code

3. Modify the CFG configuration file

This step is simple, just change the channel variable to 1 in the configuration file you want to use, as shown in the following example:

[net] # Testing # batch=1 # subdivisions=1 # Training batch=8 subdivisions=8 width=416 height=416 channels=1 Decay = 0.1decay =0.0005 # Angle =0 # arc = 1.5 #exposure = 1.5 #hue=.1learning_rate =0.001 Burn_in =1000 MAX_scale = 50200 Policy = STEPS Steps = 40000scales =.1,.1Copy the code

Then you can train using yOLO’s commands. I will not repeat it here.