melody-rain opened a new issue #7398: inconsistent results when infering
   I trained a model with VGG16 on a dataset with accuracy of 96% on the 
validation set. However when I infer with the model I trained on the same 
validation set image by image and calculate the accuracy, I got 87%, which is 
quite smaller than 96%.
   You know when training we make the dataset in .rec format, and for inference 
we read the image with cv2.imread().
   What might be the reasons that I cannot get the same accuracy? All images 
have been resized to (224, 224) and subtracted by the mean.
   96%: mod.forward(batch, is_train=False), batch is from ImageRecordIter
   87%: prob = mod.forward(Batch([mx.nd.array(img)])), img is from cv2.imread()
   image preprocessing to get 96%
       data =
           data_name          = 'data',
           label_name         = 'softmax_label',
           path_imgrec        = data_val,
           label_width        = 1,
           data_shape         = data_shape,
           preprocess_threads = data_nthreads,
           batch_size         = batch_size,
           mean_r             = rgb_mean[0],
           mean_g             = rgb_mean[1],
           mean_b             = rgb_mean[2],
   image preprocessing to get 87%
   def get_image(file_name):
       img = cv2.cvtColor(cv2.imread(file_name), cv2.COLOR_BGR2RGB)
       if img is None:
            return None
       # convert into format (batch, RGB, width, height)
       img = cv2.resize(img, (224, 224))
       img = np.swapaxes(img, 0, 2)
       img = np.swapaxes(img, 1, 2)
       img = img.astype(np.float32)
       img -= mean_img
       img = img[np.newaxis, :]
       return img
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

Reply via email to