示例#1
0
            frame = cv2.imread(from_img_path + picName)
            numFrame += 1
            handcls, handbox, handscore = demo(net, frame)
            nhand = handbox.shape[0]
            nTP = 0
            if nhand > 0:
                # cv2.imwrite(toDir+picName, frame)
                writeFile.write(picName + ' ' + str(nhand))
                for i in xrange(0, nhand):
                    writeFile.write(' hand %d %d %d %d' %
                                    (handbox[i][0], handbox[i][1],
                                     handbox[i][2], handbox[i][3]))
                    if (n_hand_gt) == 0:
                        n_false_re += 1
                    elif (IOU_multi(handbox[i], box_gt) < iouN):
                        n_false_re += 1
                writeFile.write("\n")

            if numFrame % 100 == 0:
                print numFrame, "faults=%d" % (n_false_re)

        print "model%3dw: %6d faults in %6d frame" % (model_idx, n_false_re,
                                                      numFrame)
        totalResultsFile.write("\nmodel%3dw: %6d faults in  %6d frame" %
                               (model_idx, n_false_re, numFrame))
        negSet = np.append(negSet, n_false_re)
        writeFile.close()
    print negSet
    print np.where(negSet == min(negSet))
    print "best model %d negs, at %d" % (np.min(negSet),
                '.xml')

            n_pos_gt += nhand_gt
            frame = cv2.imread(from_img_path + picName)
            numFrame += 1
            handcls, handbox, handscore = demo(net, frame)
            nhand = handbox.shape[0]
            n_pos_re += nhand
            nTP = 0
            if nhand > 0:
                writeFile.write(picName + ' ' + str(nhand))
                for i in xrange(0, nhand):
                    writeFile.write(' hand %d %d %d %d' %
                                    (handbox[i][0], handbox[i][1],
                                     handbox[i][2], handbox[i][3]))
                    if (IOU_multi(handbox[i], box_gt) > iouP):
                        nTP += 1
                writeFile.write("\n")
            n_pos_tp += nTP
        modelrecall = float(n_pos_tp) / float(n_pos_gt)
        recallSet = np.append(recallSet, modelrecall)
        modelprec = float(n_pos_tp) / float(n_pos_re)
        precSet = np.append(precSet, modelprec)
        print "model%3dw: gt =%4d, re =%4d, tp =%4d, prec=%.4f, recall=%.4f"%(model_idx, n_pos_gt,n_pos_re,  n_pos_tp, \
                                                                    float(n_pos_tp) / float(n_pos_re), float(n_pos_tp) / float(n_pos_gt))
        totalResultsFile.write( "\nmodel%3dw: gt =%4d, re =%4d, tp =%4d, prec=%.4f, recall=%.4f"%(model_idx, n_pos_gt,n_pos_re,  n_pos_tp, \
                                                                    float(n_pos_tp) / float(n_pos_re), float(n_pos_tp) / float(n_pos_gt)) )
        writeFile.close()
    print np.min(precSet), np.where(precSet == min(precSet))
    print np.max(recallSet), np.where(recallSet == max(recallSet))
    print np.mean(recallSet)
        for gt_idx in xrange(box_gt.shape[0]):
            if min(box_gt[gt_idx][3] - box_gt[gt_idx][1],
                   box_gt[gt_idx][2] - box_gt[gt_idx][0]) < min(
                       frame.shape[0], frame.shape[1]) / 6.:
                # print box_gt[gt_idx], frame.shape
                small_flag = True
        if (small_flag):  #small box in gt: no need to recall
            write_small.write(fileame + "\n")
            continue
        copyframe = frame.copy()
        numFrame += 1
        handcls, handbox, handscore = demo(net, frame, CONF_THRESH, NMS_THRESH)
        nhand = handbox.shape[0]
        nTP = 0
        if nhand > 0:  #recalled: find iou unright
            for i in xrange(0, nhand):
                iou = IOU_multi(handbox[i], box_gt)
                if (iou <= iouM and iou > iouS):
                    cv2.imwrite(toDir + "_S/" + fileame + '.jpg', frame)
                    write_iouS.write(fileame + "\n")
                elif (iou <= iouB and iou > iouM):
                    cv2.imwrite(toDir + "_B/" + fileame + '.jpg', frame)
                    write_iouB.write(fileame + "\n")
        else:  #unrecalled: savelists
            write_unrecall.write(fileame + "\n")
            cv2.imwrite(toDir + "_U/" + fileame + '.jpg', frame)
    if numFrame % 100 == 0:
        print numFrame
    print "%6d negInNeg and %6d negInNull in %6d frame" % (
        n_false_neg, n_false_null, numFrame)