def api_register(): if not request.files: print("nofile") return jsonify({'status': 'failed', 'error': 'no_file'}), 400 if not 'username' in request.form: print('no name') return jsonify({'status': 'failed', 'error': 'no_name'}), 400 file = request.files['file'] name = request.form['username'] file.save(path.join(app.config['UPLOAD_FOLDER'], name + ".png")) encoding = None try: encoding = api.train(file) except api.NoFaceDetectedError: print('no face detected') if not encoding is None: encoded = encoding.tostring() user = database.create_user(name, encoded) if not user: return jsonify({'state': False, 'error': 'cannot insert new user'}) encodings[name] = encoding with open('encodings.pickle', 'wb') as f: pickle.dump(encodings, f) return jsonify({'state': True}) else: return jsonify({ 'state': False, 'error': 'cannot find a face in the picture' })
def main(args): batch_size = 32 # Default k = 10 # Default if len(args) >= 2: batch_size = int(args[1]) if len(args) >= 3: k = int(args[2]) if args[0] == "train": print("Training from scratch ...") print("Batch size is ", batch_size) api.train(batch_size, True, True, True, 100) elif args[0] == "finetune": print("Finetune checkpoint ...") print("Batch size is ", batch_size) api.train(batch_size, False, True, True, 100) elif args[0] == "validate": print("Validate The System ...") print("Batch size is ", batch_size) api.validate_system(batch_size) elif args[0] == "preprocess_questions": print("Preprocess Questions ...") api.prepare_data() elif args[0] == "extract_all_features": print("Extract Images Features ...") print("Batch size is ", batch_size) api.extract_features(batch_size) elif args[0] == "evaluate": print("Evaluating Example ...") print("Image Path: ", args[1]) print("Question words: ", args[1:]) api.evaluate_example_url(args[1], args[1:]) elif args[0] == "trace": print("Trace Statistics of a Batch of Validation Set ...") print("Batch size is ", batch_size) print("K is ", k) api.trace(batch_size, k)
print('%d frames extracted' % len(faces)) print('PersonId: %s' % person_id) print('FaceIds') print('=======') for face in faces: print(add_face(face, person_id)) if args.list: list_ids = list_people_ids() if len(list_ids) == 0: print_error('No persons found') print('Persons IDs:') for id in list_ids: print(id) if args.delete: id = args.delete[0] delete_person(id) print('Person deleted') if args.train: train() print('Training successfully started')
'%(asctime)s - %(name)s - %(levelname)s - %(message)s') if args.log_path: file_handler = logging.FileHandler(args.log_path) file_handler.setLevel(logging.INFO) file_handler.setFormatter(formatter) logger.addHandler(file_handler) else: console_handler = logging.StreamHandler() console_handler.setLevel(logging.INFO) console_handler.setFormatter(formatter) logger.addHandler(console_handler) logger.info('Running with args : {}'.format(args)) os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" if args.gpu is not None: os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu random.seed(args.seed) np.random.seed(args.seed) tf.set_random_seed(args.seed) if args.prepare: prepare(args) if args.train: train(args) if args.evaluate: evaluate(args) if args.segment: segment(args)