Trained a multi-task model, the training accuracy as below:
Two different tasks’ accuracy are high, however , Task1’s accuracy can only reach 90% when tested in training data set.
And the prediction code as below,
import mxnet as mx
import numpy as np
import cv2
import time
import glob
from collections import namedtuple
Batch = namedtuple(‘Batch’, [‘data’])
ctx = mx.gpu(0)
sym, arg_params, aux_params = mx.model.load_checkpoint(’/root/insight_multiTask_thres/src/thres_none’, 52)
all_layers = sym.get_internals()
sym = all_layers[‘fc3_output’]
mod = mx.mod.Module(symbol=sym, context=ctx, label_names=None)
mod.bind(for_training=False, data_shapes=[(‘data’, (1,3,112,112))])
mod.set_params(arg_params, aux_params,allow_missing=True)
file_list = glob.glob("/root/emotion_data/surprise/*")
ccount = 0.0
rcount = 0.0
for file in file_list:
img1 = cv2.imread(file)
img = cv2.resize(img1,(112,112))
nimg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
aligned = np.transpose(nimg, (2,0,1))
input_blob = np.expand_dims(aligned, axis=0)
data = mx.nd.array(input_blob)
start = time.clock()
db = mx.io.DataBatch(data=(data,))
mod.forward(db, is_train=False)
prob = mod.get_outputs()[0].asnumpy()
#print(mod.get_outputs())
pred = np.argsort(prob[0])[::-1]
# label_id (same as label if MNIST), score
prob2 = mod.get_outputs()[1].asnumpy()
pred2 = np.argsort(prob2[0])[::-1]
# prob3 = mod.get_outputs()[2].asnumpy()
# pred3 = np.argsort(prob3[0])[::-1]
end = time.clock()
print(str(pred[0])+" "+str(pred2[0]))
ccount = ccount+1
if pred[0] == 7:
rcount = rcount+1
print(rcount/ccount)
Thanks anyone who can help me.