[Keras pit filling tour]· The effect of using IMG_TO_array in image classification

 

1. Background

In the task of image classification using Keras, the author’s initial method is to use opencV library Cv2. imread to read photos, and then use cv2.resize to reset the size. Training with other people’s code and finding similar code with very different results. Someone else’s VAL_ACC can be several percentage points higher than your author’s. Find an extra step in someone else’s code:

feature = img_to_array(feature)

So the author did the following experiment: control other codes unchanged, parameter unchanged respectively training using IMG_to_array have not used network.

 

2. Experimental results

Read the code as follows, masking the statement without imG_TO_array

def get_feature(path) :
    image = cv2.imread(path)
    feature = cv2.resize(image,(IMAGE_DIMS[0],IMAGE_DIMS[1]))
    feature = img_to_array(feature)
    return(feature/255.0)
Copy the code

1. Img_to_array is not used

2. Use img_to_array

It can be seen from the above that whether imG_TO_array is used has a great impact on network performance. Val_acc and VAL_Loss are closer to training ACC and Loss after the use of IMG_TO_array.

The author used both the official Keras image iterator and his own manual iterator to reach the above conclusion.

The performance of official iterators is better than that of our own hand-written iterators.

3. Conclusions and analysis

From the above experiments, it can be concluded that whether imG_TO_array is used or not has a great impact on the network, which can make the performance of the training network better. It is strongly recommended to use IMG_TO_array when doing image classification tasks.

Why is that?

The reason may be that Keras has different image reading processing methods during training and prediction, and imG_TO_array will reduce the gap. Further reasons will be analyzed later in the experiment. Also welcome big guy can help point out, thank you very much.