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 = 'AM' input_dir_path = os.path.join(os.path.dirname(__file__), 'AM_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, from_picture=True) plot_and_save_history( history, VGG16BidirectionalLSTMVideoClassifier.model_name, report_dir_path + '/' + VGG16BidirectionalLSTMVideoClassifier.model_name + '-hi-dim-history.png')
def main(): K.set_image_dim_ordering('tf') sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from keras_video_classifier.library.utility.plot_utils import plot_and_save_history, plot_history_2win from keras_video_classifier.library.recurrent_networks import ResnetLSTMVideoClassifier 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 = ResnetLSTMVideoClassifier() print("pass load model") print(type(classifier)) history = classifier.fit(data_dir_path=input_dir_path, model_dir_path=output_dir_path, resnet_include_top=False, data_set_name=data_set_name) plot_and_save_history( history, ResnetLSTMVideoClassifier.model_name, report_dir_path + '/' + ResnetLSTMVideoClassifier.model_name + '-hi-dim-history.png') plot_history_2win( history, ResnetLSTMVideoClassifier.model_name, report_dir_path + '/' + ResnetLSTMVideoClassifier.model_name + '-hi-dim-history2win.png')
def main(): sys.path.append(patch_path('..')) from keras_video_classifier.library.utility.plot_utils import plot_and_save_history from keras_video_classifier.library.convolutional import CnnVideoClassifier data_set_name = 'videos' 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 = CnnVideoClassifier() history = classifier.fit(data_dir_path=input_dir_path, model_dir_path=output_dir_path, data_set_name=data_set_name, max_frames=10) plot_and_save_history( history, CnnVideoClassifier.model_name, report_dir_path + '/' + CnnVideoClassifier.model_name + '-history.png')
def main(): K.set_image_dim_ordering('tf') sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from keras_video_classifier.library.utility.plot_utils import plot_and_save_history from keras_video_classifier.library.recurrent_networks import VGG16LSTMVideoClassifier 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) print('loading dataset') # 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) print('training classifier') classifier = VGG16LSTMVideoClassifier() history = classifier.fit(data_dir_path=input_dir_path, model_dir_path=output_dir_path, data_set_name=data_set_name) plot_and_save_history( history, VGG16LSTMVideoClassifier.model_name, report_dir_path + '/' + VGG16LSTMVideoClassifier.model_name + '-history.png') prnit('Training completed')
def main(): data_set_name = 'UCF-101' input_dir_path = patch_path('very_large_data') output_dir_path = patch_path('models/' + data_set_name) report_dir_path = patch_path('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 = CnnVideoClassifier() history = classifier.fit(data_dir_path=input_dir_path, model_dir_path=output_dir_path, data_set_name=data_set_name, max_frames=10) plot_and_save_history( history, CnnVideoClassifier.model_name, report_dir_path + '/' + CnnVideoClassifier.model_name + '-history.png')
def main(): K.set_image_data_format('channels_last') sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from keras_video_classifier.library.utility.plot_utils import plot_and_save_history from keras_video_classifier.library.recurrent_networks import ResnetLSTMVideoClassifier from keras_video_classifier.library.utility.ucf.UCF101_loader import load_ucf #from keras_video_classifier.library.utility.crime.UCF_Crime_loader import load_ucf data_set_name = 'UCF-Anomaly-Detection-Dataset' input_dir_path = os.path.join(os.path.dirname(__file__), '/content/drive/My Drive') output_dir_path = os.path.join(os.path.dirname(__file__), '/content/drive/My Drive/models', data_set_name) report_dir_path = os.path.join(os.path.dirname(__file__), '/content/drive/My Drive/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 = ResnetLSTMVideoClassifier() history = classifier.fit(data_dir_path=input_dir_path, model_dir_path=output_dir_path, resnet_include_top=False, data_set_name=data_set_name, test_size=0.1) plot_and_save_history( history, ResnetLSTMVideoClassifier.model_name, report_dir_path + '/' + ResnetLSTMVideoClassifier.model_name + '-hi-dim-history.png') plot_history_2win( history, ResnetLSTMVideoClassifier.model_name, report_dir_path + '/' + ResnetLSTMVideoClassifier.model_name + '-hi-dim-history2win.png')
def main(): testsetCount = 5 accuracies = [0, 0, 0, 0, 0] for testid in range(0, testsetCount): print(testid) K.set_image_dim_ordering('tf') sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from keras_video_classifier.library.utility.plot_utils import plot_and_save_history from keras_video_classifier.library.recurrent_networks import VGG16LSTMVideoClassifier #from keras_video_classifier.library.utility.ucf.UCF101_loader import load_ucf data_set_name = 'AM_pics_' + str(testid) input_dir_path = os.path.join(os.path.dirname(__file__), 'AM_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) print("input_dir_path", input_dir_path) print("output_dir_path", output_dir_path) print("report_dir_path", report_dir_path) np.random.seed(35) classifier = VGG16LSTMVideoClassifier() history = classifier.fit(data_dir_path=input_dir_path, model_dir_path=output_dir_path, data_set_name=data_set_name, from_picture=True) plot_and_save_history( history, VGG16LSTMVideoClassifier.model_name, report_dir_path + '/' + VGG16LSTMVideoClassifier.model_name + '-history_' + str(testid) + '.png') K.set_image_dim_ordering('tf') sys.path.append(os.path.join(os.path.dirname(__file__), '..')) print("predicting now !!!!!") data_set_name = 'AM_pics_' + str(testid) from keras_video_classifier.library.recurrent_networks import VGG16LSTMVideoClassifier 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__), 'AM_data') model_dir_path = os.path.join(os.path.dirname(__file__), 'models', data_set_name) config_file_path = VGG16LSTMVideoClassifier.get_config_file_path( model_dir_path, vgg16_include_top=vgg16_include_top) weight_file_path = VGG16LSTMVideoClassifier.get_weight_file_path( model_dir_path, vgg16_include_top=vgg16_include_top) np.random.seed(42) # load_ucf(data_dir_path) predictor = VGG16LSTMVideoClassifier() predictor.load_model(config_file_path, weight_file_path) print("Reading weights from :", weight_file_path) print("Reading Config from :", config_file_path) videos = scan_ucf_with_labels( data_dir_path, [label for (label, label_index) in predictor.labels.items()], testid) video_file_path_list = np.array( [file_path for file_path in videos.keys()]) np.random.shuffle(video_file_path_list) print(videos) 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, from_picture=True) 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('accuracy: ', accuracy) accuracies[testid] = accuracy print(accuracies) print(sum(accuracies) / len(accuracies))