def predict_top5(self, video_file_path): x = extract_vgg16_features_live(self.vgg16_model, video_file_path) frames = x.shape[0] if frames > self.expected_frames: x = x[0:self.expected_frames, :] elif frames < self.expected_frames: temp = np.zeros(shape=(self.expected_frames, x.shape[1])) temp[0:frames, :] = x x = temp predict = self.model.predict(np.array([x])) print(predict) predicted_class = np.argsort(predict[0])[-5:] print(predicted_class) predict_labels = [] #top_values= [class_prob[i] for i in np.argsort(class_prob)[-5:]] for _class in predicted_class: #print(_class) label = self.labels_idx2word[_class] predict_labels.append(label) #predicted_label = labels_idx2word_top5(predicted_class) #predicted_class = np.argmax(self.model.predict(np.array([x]))[:5]) #predicted_label = self.labels_idx2word[predicted_class] print(predict_labels) return predict_labels
def predict(self, video_file_path): x = extract_vgg16_features_live(self.vgg16_model, video_file_path) frames = x.shape[0] if frames > self.expected_frames: x = x[0:self.expected_frames, :] elif frames < self.expected_frames: temp = np.zeros(shape=(self.expected_frames, x.shape[1])) temp[0:frames, :] = x x = temp predicted_class = np.argmax(self.model.predict(np.array([x]))[0]) predicted_label = self.labels_idx2word[predicted_class] return predicted_label
def predict(self, video_file_path , from_picture=False): if from_picture: x = extract_vgg16_features_live_pictures(self.vgg16_model, video_file_path) else: x = extract_vgg16_features_live(self.vgg16_model, video_file_path) frames = x.shape[0] if frames > self.expected_frames: x = x[0:self.expected_frames, :] elif frames < self.expected_frames: temp = np.zeros(shape=(self.expected_frames, x.shape[1])) temp[0:frames, :] = x x = temp yourlist = self.model.predict(np.array([x]))[0] print("%.5f " * len(yourlist) % tuple(yourlist)) predicted_class = np.argmax(self.model.predict(np.array([x]))[0]) predicted_label = self.labels_idx2word[predicted_class] return predicted_label
def predict(self, video_file_path, interval=0, vgg16_include_top=True): predicted_labels = [] feature_dir_name = video_file_path + '-VGG16-Features' if not vgg16_include_top: feature_dir_name = video_file_path + '-VGG16-HiDimFeatures' if not os.path.exists(feature_dir_name): os.makedirs(feature_dir_name) if (interval != 0): print("Predicting each interval") features_arr = extract_vgg16_features_live_each_interval( self.vgg16_model, video_file_path, feature_dir_name, interval) for x in features_arr: frames = x.shape[0] if frames > self.expected_frames: x = x[0:self.expected_frames, :] elif frames < self.expected_frames: temp = np.zeros(shape=(self.expected_frames, x.shape[1])) temp[0:frames, :] = x x = temp predicted_class = np.argmax( self.model.predict(np.array([x]))[0]) predicted_label = self.labels_idx2word[predicted_class] predicted_labels.append(predicted_label) return predicted_labels else: print("Predicting entire video") x = extract_vgg16_features_live(self.vgg16_model, video_file_path, feature_dir_name) frames = x.shape[0] if frames > self.expected_frames: x = x[0:self.expected_frames, :] elif frames < self.expected_frames: temp = np.zeros(shape=(self.expected_frames, x.shape[1])) temp[0:frames, :] = x x = temp predicted_class = np.argmax(self.model.predict(np.array([x]))[0]) predicted_label = self.labels_idx2word[predicted_class] return predicted_label
def predict(self, video_file_path, label, correct_count, count): return extract_vgg16_features_live(self.vgg16_model, video_file_path, self.model, self.expected_frames, self.labels_idx2word, label, correct_count, count) """