def main(): sys.path.append(patch_path('..')) data_dir_path = patch_path('very_large_data') model_dir_path = patch_path('models/UCF-101') from keras_video_classifier.library.convolutional import CnnVideoClassifier from keras_video_classifier.library.utility.ucf.UCF101_loader import load_ucf, scan_ucf_with_labels config_file_path = CnnVideoClassifier.get_config_file_path(model_dir_path) weight_file_path = CnnVideoClassifier.get_weight_file_path(model_dir_path) np.random.seed(42) load_ucf(data_dir_path) predictor = CnnVideoClassifier() 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) 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)
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 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__), 'very_large_data') model_dir_path = os.path.join(os.path.dirname(__file__), 'models', 'UCF-101') 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) #debug # print([label for (label, label_index) in list(predictor.labels.items())[:3]]); # print([label for (label, label_index) in predictor.labels.items()]) #debug over videos = scan_ucf_with_labels( data_dir_path, [label for (label, label_index) in list(predictor.labels.items())[:3]]) 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('accuracy: ', accuracy)
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__), 'AM_data') model_dir_path = os.path.join(os.path.dirname(__file__), 'models', 'AM') 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, 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)
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)
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 VGG16LSTMVideoClassifier from keras_video_classifier.library.utility.ucf.UCF101_loader import load_ucf, scan_ucf_with_labels from keras_video_classifier.library.utility.plot_utils import plot_confusion_matrix from sklearn.metrics import confusion_matrix 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-101') 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) ### HARD_SPLIT = TRUE MEAN PREDICT IN UCF-101_Train folder #### videos = scan_ucf_with_labels(data_dir_path, [label for (label, label_index) in predictor.labels.items()],hard_split=True) #print("VIDEO KEY", videos) #print("VALUE",videos.values()) all_label = videos.values() #print("TYPE", type(all_label)) Total_label = [] [Total_label.append(x) for x in all_label if x not in Total_label] print("Label: ",Total_label) #print("Label shape",np.shape(Total_label)) with open("label.txt", "w") as output: output.write(str(Total_label)) 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 label_predicted = [] label_true = [] for video_file_path in video_file_path_list: label = videos[video_file_path] predicted_label = predictor.predict(video_file_path) label_predicted.append(predicted_label) label_true.append(label) 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) print("Label_Predicted",np.shape(label_predicted)) print("True Label",np.shape(label_true)) data_set_name = 'UCF-101' report_dir_path = os.path.join(os.path.dirname(__file__), 'reports', data_set_name) cm = confusion_matrix(label_true,label_predicted) recall = np.diag(cm) / np.sum(cm, axis = 1) precision = np.diag(cm) / np.sum(cm, axis = 0) import pandas as pd df = pd.DataFrame(cm) df.to_csv("CM.csv") df = pd.DataFrame(recall) df.to_csv("ReCall.csv") df = pd.DataFrame(precision) df.to_csv("Precision.csv") np.set_printoptions(precision=2) plot_confusion_matrix(cm, Total_label, title='Confusion matrix',normalize=True)
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))