Esempio n. 1
0
    cPickle.dump(joints,
                 open(
                     "./eval/{}/result_{}_{}.pkl".format(
                         eval_prefix,
                         os.path.split(__file__)[1], eval_prefix), "wb"),
                 protocol=cPickle.HIGHEST_PROTOCOL)

    print "Testing baseline"

    #################################
    # BASELINE
    # Load the evaluation
    data_baseline = di.loadBaseline('../data/NYU/test/test_predictions.mat',
                                    numpy.asarray(gt3D))

    hpe_base = NYUHandposeEvaluation(gt3D, data_baseline)
    hpe_base.subfolder += '/' + eval_prefix + '/'
    print("Mean error: {}mm".format(hpe_base.getMeanError()))
    hpe.plotEvaluation(eval_prefix,
                       methodName='Our regr',
                       baseline=[('Tompson et al.', hpe_base)])

    ind = 0
    for i in testSeqs[0].data:
        if ind % 20 != 0:
            ind += 1
            continue
        jtI = transformPoints2D(di.joints3DToImg(joints[ind]), i.T)
        hpe.plotResult(i.dpt, i.gtcrop, jtI, "{}_{}".format(eval_prefix, ind))
        ind += 1
    # save results
    cPickle.dump(joints, open("./eval/{}/result_{}_{}.pkl".format(eval_prefix,os.path.split(__file__)[1],eval_prefix), "wb"), protocol=cPickle.HIGHEST_PROTOCOL)

    print "Testing baseline"

    #################################
    # BASELINE
    # Load the evaluation
    data_baseline = di.loadBaseline('../data/NYU/test/test_predictions.mat', numpy.asarray(gt3D))

    hpe_base = NYUHandposeEvaluation(gt3D, data_baseline)
    hpe_base.subfolder += '/'+eval_prefix+'/'
    print("Mean error: {}mm".format(hpe_base.getMeanError()))

    hpe.plotEvaluation(eval_prefix, methodName='Our regr',baseline=[('Tompson et al.',hpe_base)])

    ind = 0
    for i in testSeqs[0].data:
        if ind % 20 != 0:
            ind += 1
            continue
        jt = joints[ind]
        jtI = di.joints3DToImg(jt)
        for joint in range(jt.shape[0]):
            t=transformPoint2D(jtI[joint], i.T)
            jtI[joint, 0] = t[0]
            jtI[joint, 1] = t[1]
        hpe.plotResult(i.dpt, i.gtcrop, jtI, "{}_{}".format(eval_prefix, ind))
        ind+=1
            subM = Ms_train[start:end].copy()
            subgt3Dcrop = gt3Dcrops_train[start:end].copy()
            resdata=np.ones_like(subdata)
            resgt3D=np.ones_like(subgt3Dcrop)
            hts=np.zeros(shape=(batch_size,24,24,14))
            jtIs=np.zeros(shape=(batch_size,42))

            for idx in range(batch_size):
                dm = norm_dm(subdata[idx], subcom[idx], subcube[idx])
                s = augmentCrop(dm, subgt3Dcrop[idx], di_train.joint3DToImg(subcom[idx]),
                                subcube[idx], subM[idx],['com', 'rot', 'none','sc'], hd, False, rng=rng)
                resdata[idx] = s[0]
                resgt3D[idx] = s[2]
                mode=s[7]
                gt3D_ = resgt3D[idx] * subcube[idx][0] / 2. + subcom[idx]
                jtI_ = transformPoints2D(di_train.joints3DToImg(gt3D_), subM[idx])
                jtI_=np.reshape(jtI_,(1,42))
                ht_=joints_heatmap_gen([1],jtI_,(24,24),points=14)
                hts[idx]=np.transpose(ht_,(0,2,3,1))/255.


            feed_dict = {inputs: resdata.reshape(-1, 96, 96, 1),
                         label: resgt3D.reshape(-1, 42),
                         gt_ht:hts,
                         is_train:True,
                         kp:kpv
                         }
            _, losses,summs,steps = sess.run([optimizer, loss,summ,global_step], feed_dict=feed_dict)

            #writer.add_summary(summs,steps)
            print itrain,start/batch_size,losses,mode
    return np.nanmean(
        np.nanmean(np.sqrt(np.square(gt - joints).sum(axis=2)), axis=1))


meane = getMeanError(gt_hands, pred_hands)
sub1 = getMeanError(gt_hands[0:2440], pred_hands[0:2440])
sub2 = getMeanError(gt_hands[2440:], pred_hands[2440:])
print "meane is {}".format(meane)
print "sub1 is {}".format(sub1)
print "sub2 is {}".format(sub2)

print[getJointMeanError(j, gt_hands, pred_hands) for j in range(14)]

f = open('../../results/end_nyu.txt', 'a+')
for i in range(pred_hands.shape[0]):
    uvds = di_1.joints3DToImg(pred_hands[i])
    uvds = np.reshape(uvds, (1, 42))
    for j in range(42):
        f.write(str(round(uvds[0, j], 4)))
        f.write(' ')
    f.write('\n')

f.close()
plt.get_cmap()
hand_edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [9, 10], [13, 10],
              [13, 1], [13, 3], [13, 5], [13, 7], [13, 11], [13, 12]]
if visual:

    for i in range(0, 8252, 10):

        plt.imshow(np.squeeze(test_data[i]), cmap='gray')