def generate_precision_recall_text(mode='val'):

    model = load_moviescope_model('text')
    yTrue, plotFeatures = gather_features(mode, return_video=False, reverse=True)
    plotFeatures = np.array(map(list, zip(*plotFeatures)))
    yPreds = model.predict([plotFeatures[0], plotFeatures[1]])
    dump_pkl((yTrue, yPreds), mode+'_pred_text')

    return
def generate_precision_recall_video(mode='val'):

    model = load_moviescope_model('wiki_im_video_sgd')
    yTrue, videoFeatures = gather_features(mode, return_plot=False)
    _, videoFeatures = augment_labels_lstm(yTrue, videoFeatures, 200)
    yPreds = model.predict(videoFeatures)

    dump_pkl((yTrue, yPreds), mode+'_pred_video_sgd')

    return
def generate_precision_recall_vislang(mode='val', merge_mode='sum'):

    if merge_mode == 'bilinear':
        model = vislang_model(merge_mode)
        model.load_weights('data/weights/weights_min_loss_%s.h5' % merge_mode)
    else:
        model = load_moviescope_model('eq_VisLang_%s' % merge_mode)

    yTrue, plotFeatures, videoFeatures = gather_features(mode, reverse=True)
    plotFeatures = np.array(map(list, zip(*plotFeatures)))
    _, videoFeatures = augment_labels_lstm(yTrue, videoFeatures, 200)
    yPreds = model.predict([videoFeatures, plotFeatures[0], plotFeatures[1]])
    dump_pkl((yTrue, yPreds), mode+'_pred_eq_vislang_'+merge_mode)
def return_confident_results(mode='val'):
    
    model = load_moviescope_model('wiki_im_VisLang')
    genrePredictionDict = dict((i,[]) for i in range(26))
    textObj = load_pkl('plot_object_train')
    labels, plotFeatures, videoFeatures, movieIds = gather_features(mode, return_id=True)
    _, videoFeatures = augment_labels_lstm(labels, videoFeatures, 200)
    predictionScores = model.predict([videoFeatures, plotFeatures])
    for index  in range(len(predictionScores)):
        for i in range(26):
            genrePredictionDict[i].append((predictionScores[index][i],movieIds[index]))

    dump_pkl(genrePredictionDict, 'genrePredictionDict_'+mode)
    
    for i in range(26):
        print sorted(genrePredictionDict[i], reverse=True)[:10]
    return
示例#5
0
    prediction_scores = model.predict(videoFeatures,verbose=0)
    prediction_scores = np.mean(prediction_scores, axis=0)
    predCount = np.bincount(predictions)
    return prediction_scores, predCount
            
def test_video(videoPath):
    videoFeatures = np.array(list(extract_feature_video(videoPath, verbose=True)))
    print trial_video(videoFeatures)


def test_videos(testPath):
    videoPaths = glob(testPath+'/*')
    for videoPath in videoPaths:
        test_video(videoPath)


def trials(genre):
    genreFeatures = gather_videos(genre,limit_videos=40)
    for videoFeatures in genreFeatures:
        count = trial_video(videoFeatures)
        print count


if __name__=="__main__":
    model = load_moviescope_model('spatial_3g_bs32_ep50_nf_75')
#    model = load_moviescope_model('all_bs_16_ep_50_nf_35')
    from time import time
    s = time()
    test_video(argv[1])
    print time()-s,"seconds."
示例#6
0
              "%\n")
        print("Recall of " + genres[i] + " is " + str(round(rec, 2)) + "%\n")
        print("F1 of " + genres[i] + " is " + str(round(f1, 2)) + "%\n")
        print("Accuracy of " + genres[i] + " is " + str(round(acc, 2)) + "%\n")
        print("---------------")
        total_acc = total_acc + acc
    total_acc = total_acc / 3
    print("Overall Accuracy is " + str(round(total_acc, 2)) + "%\n")


#
if __name__ == "__main__":
    from sys import argv

    if (argv[1] == 'test'):
        model = load_moviescope_model(argv[2])
        extractor = argv[3]
        ultimate_evaluate(model, extractor)
    elif (argv[1] == 'video'):
        """to call test_video"""
        genres, scores = test_video(argv[2], argv[3])
        #print("genresArr", genres)
        print("jumlah per genre: ", np.bincount(genres))
        predictedGenre = np.argmax(np.bincount(genres))
        genreDict = {0: 'action', 1: 'horror', 2: 'romance'}
        frameSequence = ' | '.join([genreDict[key] for key in genres])

        print(predictedGenre)
        print(frameSequence)

        print("\nGenre of this video is ", genreDict[predictedGenre])
def test_vislang(mode='val'):
    model = load_moviescope_model('wiki_im_vislang')
    labels, plotFeatures, videoFeatures = gather_features(mode)
    evaluate_vislang(model, videoFeatures, plotFeatures, labels)
def test(mode='val'):
    valLabels, plotFeatures, videoFeatures = gather_features(mode)
    plotModel = load_moviescope_model(best_plot_model)
    videoModel = load_moviescope_model(best_video_model)
    evaluate_text(plotModel, plotFeatures, valLabels)
    evaluate_visual(videoModel, videoFeatures, valLabels)
def test_text():
    valLabels, valFeatures = gather_features(mode='val', return_video=False)
    model = load_moviescope_model(best_plot_model)
    evaluate_text(model, valFeatures, valLabels)
def test_visual():
    valLabels, valFeatures = gather_features('val', return_plot=False)
    model = load_moviescope_model(best_video_model)
    evaluate_visual(model, valFeatures, valLabels)