def train(): print("Method", "facerec_service.train") align.align_dataset_mtcnn.main( align.align_dataset_mtcnn.parse_arguments( [IMAGE_ORIGINAL_DIR, IMAGE_PREPARED_DIR])) classifier.main( classifier.parse_arguments( ['TRAIN', IMAGE_PREPARED_DIR, MODEL_PATH, CLASSIFIER_PATH]))
def predict(): animals = ['Assult', 'Normal', 'Arrest', 'Explosion', 'Vandalism'] file = file_upload("Select a video:", accept="video/*") start = time.time() with put_loading(): f = open('temp.mp4', 'wb') f.write(file['content']) result, list_final = main('temp.mp4') # tx = "Prediction: "+str(result) #Prediction: "+str(result) img = open('output_img.jpg', 'rb').read() style(put_text('Middle frame from Video'), 'text-align: center') style(put_image(img, width='500px'), 'display: block; margin-left: auto; margin-right: auto') fig = go.Figure([go.Bar(x=animals, y=list_final)]) html = fig.to_html(include_plotlyjs="require", full_html=False) put_text('\n') style(put_text('Prediction Graph'), 'text-align: center') style(put_html(html), 'margin: auto') end = time.time() print("Time elapsed:", end - start) print(list_final) # put_text(tesxt) style(put_text('Prediction:'), 'text-align: center') style(put_text(str(result)), 'font-size: 200%;text-align: center')
def browseFiles(): filename = filedialog.askopenfilename(initialdir = "/home/mittooji/Downloads/", title = "Select a File", filetypes = (("Video files","*.mp4*"), ("all files","*.*"))) prediction = main(filename) label_file_explorer.configure(text="Anomaly Label: "+prediction)
import os import classifier if __name__ == '__main__': # Project root path to make it easier to reference files project_root_path = os.path.join(os.path.abspath(__file__), "..\\..") # Feel free to replace this and use actual commandline args instead, the main method will still work args = lambda: None args.data_dir = project_root_path + '\\training_data_aligned' args.seed = None args.use_split_dataset = False args.model = project_root_path + '\\facenet_model\\20170512-110547\\20170512-110547.pb' args.mode = 'TRAIN' args.batch_size = 460 args.image_size = 160 args.classifier_filename = project_root_path + '\\trained_classifier\\newglint_classifier.pkl' classifier.main(args)
def train(): sys.argv[1:] = [var3.get(), var1.get(), var2.get()] classifier.main(classifier.parse_arguments(sys.argv[1:])) from tkinter.messagebox import showinfo tk.messagebox.showinfo(title="tips", message="训练完毕")
def main(): return classifier.main((parameter))
#!/usr/bin/env python import classifier import sys if __name__ == "__main__": classifier.main(args=sys.argv[1:])
classify = cv2.CascadeClassifier( "C:\\Users\\ramakriy\\AppData\\Local\\Programs\\Python\\Python35\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_alt.xml" ) webcam = cv2.VideoCapture(0) while True: (rval, im) = webcam.read() im = cv2.flip(im, 1, 0) mini = cv2.resize(im, (int(im.shape[1] / size), int(im.shape[0] / size))) faces = classify.detectMultiScale(mini) # Draw rectangles around each face for f in faces: (x, y, w, h) = [v * size for v in f] cv2.rectangle(im, (x, y), (x + w, y + h), (0, 255, 0), 4) sub_face = im[y:y + h, x:x + w] FaceFileName = "test.jpg" #Saving the current image from the webcam for testing. cv2.imwrite(FaceFileName, sub_face) text = classifier.main( FaceFileName) # Getting the Result from the Classification Result. text = text.title() font = cv2.FONT_HERSHEY_TRIPLEX cv2.putText(im, text, (x + w, y), font, 1, (0, 0, 255), 2) # Show the image cv2.imshow('Capture', im) key = cv2.waitKey(10) # if Esc key is press then break out of the loop if key == 27: break
def test_one_instance(self, label_type, x_tuple, percent_tuple, run_num): x, x_value = x_tuple p, percent_sim_data = percent_tuple budget = x_value self.target_env.env.set_to_training_set() # Get data from oracle feedback num_seen_states, reviewed_blindspots = review.main(self.filenames, self.save_dir, self.target_env, label_type, budget, percent_sim_data, self.max_states, 0, self.percentile) if self.max_states == -1 or self.max_states < num_seen_states: self.max_states = num_seen_states prediction_probs_skene = None prediction_classes_skene = None for i in self.classifier_baselines: predicted_filename = os.path.join(self.save_dir, i+".csv") # Run approach given oracle data accuracy, mean_squared_error, error1s = self.run_approach(i, self.filenames["data"], predicted_filename, reviewed_blindspots, label_type) if i in self.estimation_baselines: self.estimation_results[label_type[0]]["accuracy"][i][x,run_num] = accuracy self.estimation_results[label_type[0]]["error"][i][x,run_num] = mean_squared_error self.estimation_results[label_type[0]]["error1s"][i][x,run_num] = error1s results, self.data_sizes[label_type[0]], prediction_probs, prediction_classes = classifier.main(self.save_dir, predicted_filename, self.filenames["true_sim"], label_type[0], i, self.classifier_metrics, self.filenames["sim_on_real"]) if i == "dawid_skene": prediction_probs_skene = prediction_probs prediction_classes_skene = prediction_classes for metric in self.classifier_metrics: for t in self.test_data_list: self.classifier_results[label_type[0]][metric][t][i][x,run_num] = results[t][metric] self.target_env.env.set_to_testing_set() for i in self.oracle_in_loop_baselines: probs = None classes = None if i == "model_query": probs = prediction_probs_skene classes = prediction_classes_skene # Run oracle-in-the-loop evaluation avg_reward, percent_queries = self.oracle_in_loop_eval(self.target_env, i, probs, classes) self.oracle_in_loop_results[label_type[0]]["avg_reward"][i][x,run_num] = avg_reward self.oracle_in_loop_results[label_type[0]]["percent_queries"][i][x,run_num] = percent_queries