def main():
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

    from keras_video_classifier.library.recurrent_networks import VGG16BidirectionalLSTMVideoClassifier
    #from keras_video_classifier.library.utility.ucf.UCF101_loader import load_ucf, scan_ucf_with_labels
    from keras_video_classifier.library.utility.ucf.UCF101_loader import scan_ucf_with_labels, scan_ucf_predict

    vgg16_include_top = True
    data_dir_path = os.path.join(os.path.dirname(__file__), 'very_large_data')
    model_dir_path = os.path.join(os.path.dirname(__file__), 'models',
                                  'videos')
    config_file_path = VGG16BidirectionalLSTMVideoClassifier.get_config_file_path(
        model_dir_path, vgg16_include_top=vgg16_include_top)
    weight_file_path = VGG16BidirectionalLSTMVideoClassifier.get_weight_file_path(
        model_dir_path, vgg16_include_top=vgg16_include_top)

    np.random.seed(42)

    #load_ucf(data_dir_path)

    predictor = VGG16BidirectionalLSTMVideoClassifier()
    predictor.load_model(config_file_path, weight_file_path)

    #videos = scan_ucf_with_labels(data_dir_path, [label for (label, label_index) in predictor.labels.items()])
    videos = scan_ucf_predict(data_dir_path)
    video_file_path_list = np.array(
        [video_file_path for video_file_path in videos.keys()])
    np.random.shuffle(video_file_path_list)

    correct_count = 0
    count = 0
    arr = []

    for video_file_path in video_file_path_list:
        #label = videos[video_file_path]
        video_number = video_file_path[video_file_path.rfind('/') +
                                       1:video_file_path.rfind('.')]
        video_number = int(video_number)
        predicted_label = predictor.predict(video_file_path)
        #print('predicted: ' + predicted_label + ' actual: ' + label)
        #correct_count = correct_count + 1 if label == predicted_label else correct_count
        count += 1
        #print('predicted: ' + predicted_label)
        if predicted_label == 'smoking':
            arr.append(video_number)
        #accuracy = correct_count*100 / count
        #print('accuracy: ', accuracy)

    arr.sort(key=lambda x: x)
    print('The timestamps are:\n')
    for num in arr:
        print(str(5 * num) + ' -> ' + str(5 * num + 5) + '\n')
Example #2
0
def main():
    K.set_image_dim_ordering('tf')
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

    from keras_video_classifier.library.recurrent_networks import VGG16BidirectionalLSTMVideoClassifier
    from keras_video_classifier.library.utility.plot_utils import plot_and_save_history
    from keras_video_classifier.library.utility.ucf.UCF101_loader import load_ucf

    data_set_name = 'UCF-101'
    input_dir_path = os.path.join(os.path.dirname(__file__), 'very_large_data')
    output_dir_path = os.path.join(os.path.dirname(__file__), 'models',
                                   data_set_name)
    report_dir_path = os.path.join(os.path.dirname(__file__), 'reports',
                                   data_set_name)

    np.random.seed(42)

    # this line downloads the video files of UCF-101 dataset if they are not available in the very_large_data folder
    load_ucf(input_dir_path)

    classifier = VGG16BidirectionalLSTMVideoClassifier()

    history = classifier.fit(data_dir_path=input_dir_path,
                             model_dir_path=output_dir_path,
                             vgg16_include_top=False,
                             data_set_name=data_set_name)

    plot_and_save_history(
        history, VGG16BidirectionalLSTMVideoClassifier.model_name,
        report_dir_path + '/' +
        VGG16BidirectionalLSTMVideoClassifier.model_name +
        '-hi-dim-history.png')
Example #3
0
def classify(file_path):
    # sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
    from keras_video_classifier.library.recurrent_networks import VGG16BidirectionalLSTMVideoClassifier

    vgg16_include_top = True
    model_dir_path = os.path.join(os.path.dirname(__file__), 'models/dataset')

    config_file_path = VGG16BidirectionalLSTMVideoClassifier.get_config_file_path(model_dir_path,
                                                                                  vgg16_include_top=vgg16_include_top)
    weight_file_path = VGG16BidirectionalLSTMVideoClassifier.get_weight_file_path(model_dir_path,
                                                                                  vgg16_include_top=vgg16_include_top)
    np.random.seed(42)
    predictor = VGG16BidirectionalLSTMVideoClassifier()
    predictor.load_model(config_file_path, weight_file_path)
    predicted_label, face_images = predictor.predict(file_path)

    return predicted_label, face_images
Example #4
0
def main():
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

    from keras_video_classifier.library.recurrent_networks import VGG16BidirectionalLSTMVideoClassifier
    from keras_video_classifier.library.utility.ucf.UCF101_loader import load_ucf, scan_ucf_with_labels

    vgg16_include_top = True
    data_dir_path = os.path.join(os.path.dirname(__file__), 'very_large_data')
    model_dir_path = os.path.join(os.path.dirname(__file__), 'models',
                                  'UCF-101')
    config_file_path = VGG16BidirectionalLSTMVideoClassifier.get_config_file_path(
        model_dir_path, vgg16_include_top=vgg16_include_top)
    weight_file_path = VGG16BidirectionalLSTMVideoClassifier.get_weight_file_path(
        model_dir_path, vgg16_include_top=vgg16_include_top)

    np.random.seed(42)

    load_ucf(data_dir_path)

    predictor = VGG16BidirectionalLSTMVideoClassifier()
    predictor.load_model(config_file_path, weight_file_path)

    print('reaching here three')

    videos = scan_ucf_with_labels(
        data_dir_path,
        [label for (label, label_index) in predictor.labels.items()])

    video_file_path_list = np.array([file_path for file_path in videos.keys()])
    np.random.shuffle(video_file_path_list)

    correct_count = 0
    count = 0

    for video_file_path in video_file_path_list:
        label = videos[video_file_path]
        predicted_label = predictor.predict(video_file_path)
        print('predicted: ' + predicted_label + ' actual: ' + label)
        correct_count = correct_count + 1 if label == predicted_label else correct_count
        count += 1
        accuracy = correct_count / count
        print('correct_count: ' + str(correct_count) + ' count: ' + str(count))
        print('accuracy: ', accuracy)
Example #5
0
def main():
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

    from keras_video_classifier.library.recurrent_networks import VGG16BidirectionalLSTMVideoClassifier
    from keras_video_classifier.library.utility.ucf.UCF101_loader import load_ucf, scan_ucf_with_labels

    vgg16_include_top = False
    data_dir_path = os.path.join(os.path.dirname(__file__), 'very_large_data')
    model_dir_path = os.path.join(os.path.dirname(__file__), 'models/giri')

    config_file_path = VGG16BidirectionalLSTMVideoClassifier.get_config_file_path(
        model_dir_path, vgg16_include_top=vgg16_include_top)
    weight_file_path = VGG16BidirectionalLSTMVideoClassifier.get_weight_file_path(
        model_dir_path, vgg16_include_top=vgg16_include_top)

    np.random.seed(42)

    load_ucf(data_dir_path)

    predictor = VGG16BidirectionalLSTMVideoClassifier()
    predictor.load_model(config_file_path, weight_file_path)

    videos = scan_ucf_with_labels(
        data_dir_path,
        [label for (label, label_index) in predictor.labels.items()])

    video_file_path_list = np.array([file_path for file_path in videos.keys()])
    np.random.shuffle(video_file_path_list)

    correct_count = 0
    count = 0

    for video_file_path in video_file_path_list:
        label = videos[video_file_path]
        correct_count, count = predictor.predict(video_file_path, label,
                                                 correct_count, count)
Example #6
0
def main():
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

    from keras_video_classifier.library.recurrent_networks import VGG16BidirectionalLSTMVideoClassifier
    from keras_video_classifier.library.utility.crime.UCF_Crime_loader import load_ucf, scan_ucf_with_labels

    vgg16_include_top = False
    data_dir_path = os.path.join(os.path.dirname(__file__), 'very_large_data')
    model_dir_path = os.path.join(os.path.dirname(__file__), 'models',
                                  'UCF-Anomaly-Detection-Dataset')

    config_file_path = VGG16BidirectionalLSTMVideoClassifier.get_config_file_path(
        model_dir_path, vgg16_include_top=vgg16_include_top)
    weight_file_path = VGG16BidirectionalLSTMVideoClassifier.get_weight_file_path(
        model_dir_path, vgg16_include_top=vgg16_include_top)

    np.random.seed(42)

    load_ucf(data_dir_path)

    predictor = VGG16BidirectionalLSTMVideoClassifier()
    predictor.load_model(config_file_path, weight_file_path)

    videos = scan_ucf_with_labels(
        data_dir_path,
        [label for (label, label_index) in predictor.labels.items()])

    print("PREDICT_VIDEOS", videos)

    video_file_path_list = np.array([file_path for file_path in videos.keys()])

    print("video_file_path_list:", video_file_path_list)
    np.random.shuffle(video_file_path_list)

    correct_count = 0
    count = 0

    top5_correct_count = 0

    print("Begin Predict Using UCF-CRIME-Model: ")
    print("Video_file_path_list: ", video_file_path_list)
    print(len(video_file_path_list))
    for video_file_path in video_file_path_list:
        label = videos[video_file_path]
        predicted_label = predictor.predict_top5(video_file_path)
        print('Top 1 predicted: ' + str(predicted_label[-1]) + ' actual: ' +
              label)
        correct_count = correct_count + 1 if label == predicted_label[
            -1] else correct_count
        count += 1
        accuracy = correct_count / count

        print('Top 5 predicted: ' + str(predicted_label) + ' actual: ' + label)
        top5_correct_count = top5_correct_count + 1 if [
            s for s in predicted_label if label in s
        ] else top5_correct_count
        accuracy_5 = top5_correct_count / count
        print('correct_count: ' + str(correct_count) + ' count: ' + str(count))
        print('top5_correct_count: ' + str(top5_correct_count) + ' count: ' +
              str(count))

        print('accuracy: ', accuracy)
        print('accuracy_top_5: ', accuracy_5)
    def Detect(self, fullname):
        sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

        from keras_video_classifier.library.recurrent_networks import VGG16BidirectionalLSTMVideoClassifier
        from keras_video_classifier.library.utility.ucf.UCF101_loader import load_ucf, scan_ucf_with_labels

        vgg16_include_top = True
        data_dir_path = os.path.join(os.path.dirname(__file__),
                                     'very_large_data')
        model_dir_path = os.path.join(os.path.dirname(__file__), 'models',
                                      'UCF-101')
        demo_dir_path = os.path.join(os.path.dirname(__file__), 'real-data')
        config_file_path = VGG16BidirectionalLSTMVideoClassifier.get_config_file_path(
            model_dir_path, vgg16_include_top=vgg16_include_top)
        weight_file_path = VGG16BidirectionalLSTMVideoClassifier.get_weight_file_path(
            model_dir_path, vgg16_include_top=vgg16_include_top)

        np.random.seed(42)

        load_ucf(data_dir_path)

        predictor = VGG16BidirectionalLSTMVideoClassifier()
        predictor.load_model(config_file_path, weight_file_path)

        print('reaching here three')

        unusual_actions = []
        usual_actions = []
        interval = 3
        txtFile = open('./reports/prediction_Each_Interval_Report' + '.txt',
                       'w')

        if os.path.isfile(fullname):
            print("Predicting video: {}".format(os.path.basename(fullname)))
            predicted_labels = predictor.predict(fullname, interval=interval)
            print("TOTAL {} ACTIONS".format(len(predicted_labels)))
            for index in range(len(predicted_labels)):
                if (predicted_labels[index] == "Unusual action"):
                    time = str(datetime.timedelta(seconds=index))
                    print('predicted: ' + predicted_labels[index] +
                          ' at: {0}'.format(time))
                    unusual_actions.append(list((fullname, time)))
                elif (predicted_labels[index] == "Usual action"):
                    time = str(datetime.timedelta(seconds=index))
                    print('predicted: ' + predicted_labels[index] +
                          ' at: {0}'.format(time))
                    usual_actions.append(list((fullname, time)))
        print("TOTAL: {} unusual actions and {} usual actions".format(
            len(unusual_actions), len(usual_actions)))
        txtFile.write("Unsual actions")
        txtFile.write('\n')
        for item in unusual_actions:
            txtFile.write(item[0] + ' at ' + item[1])
            txtFile.write('\n')
        txtFile.write("Usual actions")
        txtFile.write('\n')
        for item in usual_actions:
            txtFile.write(item[0] + ' at ' + item[1])
            txtFile.write('\n')
        txtFile.close()
        self.SplitVideo(fullname, unusual_actions)
        return self.DrawToVideo(fullname, unusual_actions)