def create_evaluation(): form = CreateEvaluationForm(request.form) if form.validate(): # first, check if GPU is enough total_used, total, process_usage = util.get_gpu_info(0) current_gpu_memory = float(total) - float(total_used) if current_gpu_memory < parameters.MINIMUM_EVAL_GPU_MEMORY: return response_util.json_error_response( msg='No enough GPU memory, it requires %s MB, but there is only %s MB' % ( str(parameters.MINIMUM_EVAL_GPU_MEMORY), str(current_gpu_memory))) if not os.path.exists(config.EVALUATION_PATH): os.makedirs(config.EVALUATION_PATH) classifier_id = form.classifier_id.data classifier = Classifier.query.filter(Classifier.id == classifier_id).first() if not classifier: return response_util.json_error_response(msg='classifier not exist') name = form.name.data video_list = form.video_list.data video_list = video_list.split(',') print 'create evaluation with name %s, video list %s ' % (str(name), str(video_list)) controller.create_evaluation(classifier_id, name, video_list) flash('Evaluation Job Created. Please refresh the page after a few minutes to see the ROC graph.', 'success') return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))
def create_iterative_classifier(): form = CreateIterativeClassifierForm(request.form) if form.validate(): # first, check if GPU is enough total_used, total, process_usage = util.get_gpu_info(0) current_gpu_memory = float(total) - float(total_used) if current_gpu_memory < parameters.MINIMUM_TRAIN_GPU_MEMORY: return response_util.json_error_response( msg='No enough GPU memory, it requires %s MB, but there is only %s MB' % ( str(parameters.MINIMUM_TRAIN_GPU_MEMORY), str(current_gpu_memory))) # one thing should care about is that for both iterative training and evaluation, # the base labels.txt (which stores the name and order for labels) should still be the # very original (that from the base classifier), thus the labels list should also be organized in # that order base_classifier_id = form.base_classifier_id.data classifier = Classifier.query.filter(Classifier.id == base_classifier_id).first() if not classifier: return response_util.json_error_response(msg='base classifier not exist') epoch = form.epoch.data video_list = form.video_list.data video_list = video_list.split(',') classifier_name = util.safe_docker_image_name(form.classifier_name.data) if db_helper.has_classifier_name_of_user(classifier_name, current_user): return response_util.json_error_response(msg='duplicate classifier name') controller.create_iterative_training_classifier(current_user, base_classifier_id, classifier_name, epoch, video_list) return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))
def create_training_classifier(): form = CreateClassifierForm(request.form) if form.validate(): # first, check if GPU is enough total_used, total, process_usage = util.get_gpu_info(0) current_gpu_memory = float(total) - float(total_used) if current_gpu_memory < parameters.MINIMUM_TRAIN_GPU_MEMORY: return response_util.json_error_response( msg='No enough GPU memory, it requires %s MB, but there is only %s MB' % ( str(parameters.MINIMUM_TRAIN_GPU_MEMORY), str(current_gpu_memory))) classifier_name = util.safe_docker_image_name(form.classifier_name.data) if db_helper.has_classifier_name_of_user(classifier_name, current_user): return response_util.json_error_response(msg='duplicate classifier name') epoch = form.epoch.data network_type = form.network_type.data video_list = form.video_list.data video_list = video_list.split(',') print 'creating training job' print 'video ids: {}'.format(video_list) label_list = form.label_list.data label_list = label_list.split(',') label_list = util.get_unique_label_name(label_list) print 'labels: {}'.format(label_list) controller.create_training_classifier(current_user, classifier_name, epoch, video_list, label_list) return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))
def create_test_classifier(): ''' : return: the status of test classifier (refresh current classifier page), or redirect to the test api ''' ''' inside the form, there are several parameters 1. if long running, if it's long running, then there is no redirect, just open the classifier 2. if short running, it's just a test, it contains image { long_running: true, base_classifier_id: 1234 img: {img content}, } ''' form = CreateTestClassifierForm(request.form) if form.validate(): # first, check if GPU is enough total_used, total, process_usage = util.get_gpu_info(0) current_gpu_memory = float(total) - float(total_used) if current_gpu_memory < parameters.MINIMUM_TEST_GPU_MEMORY: return response_util.json_error_response( msg='No enough GPU memory, it requires %s MB, but there is only %s MB' % ( str(parameters.MINIMUM_TEST_GPU_MEMORY), str(current_gpu_memory))) base_classifier_id = form.base_classifier_id.data long_running = form.long_running.data print 'parameter: base classifier %s , long running: %s ' % (str(base_classifier_id ), str(long_running)) if long_running == 'true': time_remains = 1000 if form.time_remains.data: time_remains = form.time_remains.data if not controller.create_test_classifier(current_user, base_classifier_id, time_remains): return response_util.json_error_response(msg='The base classifier not exist') else: return redirect(request.referrer) else: if len(request.files) > 1: logger.warning("onetime test received more than 1 image. only the first image is tested!") min_cf = str(request.form['confidence']) _, cur_file = request.files.items()[0] input_image_path = os.path.join('/tmp', str(random.getrandbits(32))+str(cur_file.filename)) cur_file.save(input_image_path) logger.debug('saved test file to {}'.format(input_image_path)) ret_file_path = controller.run_onetime_classifier_test(base_classifier_id, input_image_path, min_cf) if not ret_file_path: response_util.json_error_response(msg="Failed to find the classifier") return send_file(ret_file_path) return response_util.json_error_response(msg=str(form.errors))
def push_classifier(): form = PushClassifierForm(request.form) if form.validate(): classifier_id = form.classifier_id.data classifier = Classifier.query.filter(Classifier.id == classifier_id).first() if not classifier: return response_util.json_error_response(msg='classifier not exist') push_tag_name = 'tpod-image-' + current_user.username + '-' + classifier.name msg = controller.push_classifier(classifier, push_tag_name) flash(msg) return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))
def edit_label(): form = EditLabelForm(request.form) if form.validate(): label = Label.query.filter(Label.id == form.label_id.data).first() label.update(text=form.label_name.data) return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))
def delete_label(): form = DeleteLabelForm(request.form) if form.validate(): label = Label.query.filter(Label.id == form.label_id.data).first() video = Video.query.filter(Video.id == label.videoid).first() video.labels.remove(label) label.delete() db.session.commit() return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))
def add_label(): form = AddLabelForm(request.form) if form.validate(): label = Label(text=form.label_name.data, videoid=form.video_id.data) video = Video.query.filter(Video.id == form.video_id.data).first() video.labels.append(label) db.session.add(label) db.session.commit() turkic_replacement.publish() return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))
def login(): if current_user and current_user.is_authenticated: return redirect('/') if request.method == 'POST': form = LoginForm(request.form) if form.validate(): user = form.user print "login success " login_user(user) return response_util.json_success_response( redirect=url_for('video_page.list_video')) else: return response_util.json_error_response(msg=str(form.errors)) else: return render_template('login.html', csrf=app.config['CSRF_ENABLED'])
def delete_video(): form = DeleteVideoForm(request.form) if form.validate(): turkic_replacement.delete_video(form.video_id.data) return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))
def delete_evaluation(): form = DeleteEvaluationForm(request.form) if form.validate(): controller.delete_evaluation(form.evaluation_id.data) return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))
def delete_classifier(): form = DeleteClassifierForm(request.form) if form.validate(): controller.delete_classifier(form.classifier_id.data) return redirect(request.referrer) return response_util.json_error_response(msg=str(form.errors))