else:
        svm = classify_library.load_model('../data/models/svm_nopca.sav')
    gmm_list = np.load(gmm_list + ".npz")['gmm_list']
    index_class = np.load(class_index)['index_class']
    index_class = index_class[()]

    points = []  # a list of IDT features.
    frame_lim = frame_step
    for line in sys.stdin:
        if line[0] != '[':  # avoid getting info message as data
            frame = int(line.split()[0])
            if frame_lim <= frame:
                frame_lim = frame_lim + frame_step
                # print frame_lim<=frame
                if points != []:
                    video_desc = IDT_feature.vid_descriptors(points)
                    fish = computeFV.create_fisher_vector_unsaved(
                        gmm_list, video_desc)
                    fish = np.array(fish).reshape(1, -1)
                    if args.no_pca:
                        result = svm.predict(fish)
                    else:
                        fish_pca = pca.transform(fish)
                        result = svm.predict(fish_pca)

                    print '\n' + 'RESULT: ' + OKGREEN + BOLD + index_class[
                        result[0]] + ENDC + '\n'

                points = []
            points.append(IDT_feature.IDTFeature(line))
Exemplo n.º 2
0
    video = args.video_name

    vid = os.path.join(video_dir, video)
    if not check_resolution(vid):
        resizedName = os.path.join(tmp_dir, video)
        if ffmpeg.resize(vid, resizedName):
            vid = resizedName
    command = dtBin + ' ' + vid
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
    raw_features, _ = p.communicate()
    features = raw_features.split("\n")
    points = []
    for point in features:
        if point != '' and point[
                0] != '[':  #to delete info messages from DenseTrackStab
            points.append(IDT_feature.IDTFeature(point))
    video_desc = IDT_feature.vid_descriptors(points)
    gmm_list = np.load(gmm_list + ".npz")['gmm_list']
    fish = computeFV.create_fisher_vector_unsaved(gmm_list, video_desc)
    if not args.no_pca:
        pca = classify_library.load_model('../data/models/pca.sav')
        svm = classify_library.load_model('../data/models/svm.sav')
    else:
        svm = classify_library.load_model('../data/models/svm_nopca.sav')

    fish = np.array(fish).reshape(1, -1)
    if args.no_pca:
        fish_pca = fish
    else:
        fish_pca = pca.transform(fish)
    result = svm.predict(fish_pca)