コード例 #1
0
ファイル: test_model.py プロジェクト: muhammadfaiz12/dsafdpi
def test_video(videoPath, model_file):
    """Return the genre type for each video input"""
    frames = list(get_frames(videoPath, time_step=1000))
    if len(frames) == 0:
        print("Error in video")
        return

    print("Processing", videoPath)
    modelName = model_file
    model = load_model(model_resource + modelName)

    videoFeatures = get_features_batch(frames)
    predictedClasses = model.predict_classes(videoFeatures)
    predictedScores = model.predict(videoFeatures)
    return predictedClasses, predictedScores
def test_video(videoPath):
    frames = list(get_frames(videoPath, time_step=1000))
    if len(frames)==0:
        print("Error in video")
        return
    
    print("Processing",videoPath)
    modelName = "lstmvgg16_9g_bs32_ep100.h5"
    model = load_model("/home/parkhi/Desktop/DIP_project/data/models/"+ modelName)
    videoFeatures = get_features_batch(frames)
    videoFeatures = np.array(videoFeatures)
    videoFeatures = np.reshape(videoFeatures, (videoFeatures.shape[0], 1, videoFeatures.shape[1]))
    predictedClasses = model.predict_classes(videoFeatures)
    predictedScores = model.predict(videoFeatures)
    return predictedClasses, predictedScores
def gather_training_data(genre, model_name=default_model_name):
    trainPath = os.path.join(video_resource, 'train', genre)
    videoPaths = glob(trainPath + '/*')
    genreFeatures = []
    for videoPath in videoPaths:
        print(videoPath, ":")
        frames = list(get_frames(videoPath, time_step=1000))
        print(len(frames))
        if len(frames) == 0:
            print("corrupt.")
            continue
        videoFeatures = get_features_batch(frames, model_name)
        print(videoFeatures.shape)
        genreFeatures.append(videoFeatures)
    outPath = genre + "_ultimate_" + model_name
    dump_pkl(genreFeatures, outPath)
コード例 #4
0
def _get_features_data(mode='val'):
    """ deprecated with old dataset """
    """ Includes every sample with plotFeatures, videoFeatures, movie_id and genreLabel """
    featureData = []
    allData = load_pkl(baseName+mode)
    plots = []

    """Process plot vectors"""

    for data in allData:
        movie_id = data['movie_id']
        plot = data['plot']
        plots.append(plot)

    if mode=='train':
        textObj = Text()
        plotFeatures_all = textObj.fit_transform(plots)
        dump_pkl(textObj, 'plot_object_train')
    else:
        try:
            textObj = load_pkl('plot_object_train')
            plotFeatures_all = textObj.transform(plots).toarray()
        except:
            print "Please train the plots first."
            return

    plotIndex = -1
    for data in allData:
        plotIndex += 1
        movie_id =  data['movie_id']
        path = glob(video_resource+str(movie_id)+'.*')[0]       
        plot = data['plot']
        genreLabel = data['genreLabel']
        print plotIndex,"out of ",len(allData)
        print "Gathering features for",movie_id
        try:
            frames = list(get_frames(path, start_time=1000, end_time=200000, time_step=1000))
            videoFeatures = get_features_batch(frames, 'vgg16')
        except Exception as e:
            print e
            continue # Omit the movie if one of the feature is bad
            # videoFeatures = None
        plotFeatures = plotFeatures_all[plotIndex]

        featureData.append({'videoFeatures':videoFeatures, 'plotFeatures':plotFeatures, 'movie_id':movie_id, 'genreLabel':genreLabel})

    dump_pkl(featureData, 'feature_data_'+mode)
コード例 #5
0
ファイル: create_data.py プロジェクト: colinsongf/MovieScope
def gather_training_data(genre, model_name=default_model_name):
    """Driver function to collect frame features for a genre"""

    trainPath = os.path.join(video_resource,'train',genre)
    print trainPath
    videoPaths = glob(trainPath+'/*')
    genreFeatures = []
    for videoPath in videoPaths:
        print videoPath,":",
        frames =list(get_frames(videoPath, time_step=1000))
        print len(frames),
        if len(frames)==0:
            print "corrupt."
            continue
        videoFeatures = get_features_batch(frames, model_name)
        print videoFeatures.shape
        genreFeatures.append(videoFeatures)

    outPath = genre+"_ultimate_"+model_name
    dump_pkl(genreFeatures, outPath)
コード例 #6
0
ファイル: test_model.py プロジェクト: muhammadfaiz12/dsafdpi
def gather_testing_data(genre, model_name=default_model_name):
    """Driver function to collect frame features for a genre"""

    testPath = os.path.join(video_resource, 'test', genre)
    print(testPath)
    videoPaths = glob(testPath + '/*')
    genreFeatures = []
    for videoPath in videoPaths:
        print(
            videoPath,
            ":",
        )
        frames = list(get_frames(videoPath, time_step=1000))
        print(len(frames), )
        if len(frames) == 0:
            print("corrupt.")
            continue
        videoFeatures = get_features_batch(frames)
        print(videoFeatures.shape)
        genreFeatures.append(videoFeatures)

    outPath = genre + "_test_" + model_name
    dump_pkl(genreFeatures, outPath)