Hi all,
I have trained a classification network using the
model.fit(train,
begin_epoch = epoch,
num_epoch = num_epochs,
eval_data = val,
eval_metric = MultitaskAccuracy(num=NUM_LABELS),
optimizer = ‘nag’,
optimizer_params = optimizer_params,
#arg_params = new_args,
initializer = initializer,
allow_missing = True,
batch_end_callback = mx.callback.Speedometer(batch_size, 1000),
epoch_end_callback = checkpoint)
train and val are defined as follows:
train = mx.io.ImageRecordIter(
path_imglist= train_list
path_imgrec = train_rec,
#mean_img = train_mean,
#resize = 230,
mean_r = 127.5,
mean_g = 127.5,
mean_b = 127.5,
data_shape = data_shape,
batch_size = batch_size,
rand_crop = True,
rand_mirror = True,
shuffle = True,
label_width = NUM_LABELS
)
I have been testing it as follows:
test = mx.io.ImageRecordIter(
path_imglist= pred_file,
path_imgrec = pred_rec,
mean_r = 127.5,
mean_g = 127.5,
mean_b = 127.5,
#mean_img = mean_file,
rand_crop = False,
rand_mirror = False,
data_shape = data_shape,
batch_size = 1,
label_width = NUM_LABELS
)
predictions = mod.predict(test)
However I need to test it one image at a time, so I wrote the test in the following way:
image = cv2.cvtColor(cv2.imread(img), cv2.COLOR_BGR2RGB)
image = np.array(image, dtype=np.float32)
test_img = cv2.resize(image, (224, 224))
test_img = np.expand_dims(np.transpose(test_img, (2, 0, 1)), axis=0)
test_img = test_img - 127.5
mod.forward(Batch([mx.nd.array(test_img)]))
However the responses are different.
What is the correct way of testing the trained network, when we have to do mean-subtraction and resizing?