def vote(): annotator = utils.get_current_annotator() if annotator is not None: if annotator.prev.id == int( request.form['prev_id']) and annotator.next.id == int( request.form['next_id']): if request.form['action'] == 'Skip': annotator.ignore.append(annotator.next) else: if request.form['action'] == 'Previous': utils.perform_vote(annotator, next_won=False) decision = Decision(annotator, winner=annotator.prev, loser=annotator.next) elif request.form['action'] == 'Current': utils.perform_vote(annotator, next_won=True) decision = Decision(annotator, winner=annotator.next, loser=annotator.prev) db.session.add(decision) annotator.next.viewed.append(annotator) annotator.prev = annotator.next annotator.ignore.append(annotator.prev) annotator.next = utils.choose_next(annotator) db.session.commit() return redirect(url_for('index'))
def create_decision(request, status, template_name): decision = Decision(status=status) decision.author = request.user if request.method == "POST": return _process_post_and_redirect(request, decision, template_name) form = DecisionForm(instance=decision) data = dict(form=form,tab=status) context = RequestContext(request, data) return render_to_response(template_name, context)
def main(): args = get_arguments() print(args) MODEL_DIR = os.path.join(ROOT_DIR, "logs/decision") data_dir = "./data/" config = CityscapeConfig() config.FLOW = args.flowmodel decision = Decision(config, dropout=0.5) decision.train(data_dir, MODEL_DIR, epochs=200)
def modify_decision(request, decision_id = None, status_id = None): if decision_id is None: decision = Decision() if status_id is not None: decision.status = int(status_id) else: decision = get_object_or_404(Decision, id = decision_id) if request.method == "POST": if request.POST.get('submit', None) == "Cancel": return_page = unicode(decision.status_text()) return HttpResponseRedirect(reverse(listing, args=[return_page])) else: decision_form = DecisionForm(data=request.POST, instance=decision) feedback_formset = FeedbackFormSet(data=request.POST, instance=decision) if decision_form.is_valid(): decision = decision_form.save(commit=False) feedback_formset = FeedbackFormSet(request.POST, instance=decision) if feedback_formset.is_valid(): decision.save(request.user) if decision_form.cleaned_data['watch']: decision.add_watcher(request.user) else: decision.remove_watcher(request.user) feedback_formset.save() return_page = unicode(decision.status_text()) return HttpResponseRedirect(reverse(listing, args=[return_page])) else: feedback_formset = FeedbackFormSet(instance=decision) decision_form = DecisionForm(instance=decision) return render_to_response('decision_edit.html', RequestContext(request, dict(decision_form=decision_form, feedback_formset=feedback_formset)))
def _get_test_contest_decisions(contest): random.seed() decisions = [] ballot_ids = [str(uuid.uuid4()) for x in range(7)] num_decisions = random.randint(90, 200) for i in range(num_decisions): voter_opinions = {} write_in_names = [] if contest.decision_type == contest.DECISION_TYPE_VOTE_YES_NO: voter_opinions[0] = random.randint(0, 1) else: if contest.allow_write_ins and (random.randint(1, 10000) % 25) == 0: # # enter a write in write_in_names.append("Write In {0}".format( random.randint(1, 4))) voter_opinions[len(contest.contestants)] = 1 else: # #pick a candidate ar random voter_opinions[random.randint(0, len(contest.contestants) - 1)] = 1 decision = Decision( contest, { 'decision_id': str(uuid.uuid4()), 'contest_id': contest.id, 'ballot_id': ballot_ids[random.randint(1, 10000) % 7], 'timestamp': datetime.now(), 'contest': contest, 'authoritative': True, 'latest': True, 'voter_id': str(uuid.uuid4()), 'voter_opinions': voter_opinions, 'write_in_names': write_in_names }) decisions.append(decision) return decisions
config.BACKBONE = args.resnetmodel config.IMAGE_SHAPE = [1024, 1024, 6] config.POST_NMS_ROIS_INFERENCE = 500 #config.display() # Validation dataset dataset = CityscapeDataset() dataset.load_cityscape(args.data_dir, "val", args.num_frames, args.fix) dataset.prepare() print("Image Count: {}".format(len(dataset.image_ids))) resnet = ResNet(config=config) flownet = FlowNet(config=config) maskrcnn = MaskRCNN(config=config) warp = Warp(config=config) decision = Decision(config=config) model_path = args.restore_from resnet.load_weights(model_path, by_name=True) flownet.load_weights(model_path, by_name=True) maskrcnn.load_weights(model_path, by_name=True) decision.load_weights(args.decision_from, by_name=True) AP50s = [] APs = [] seg_step = 0 flow_step = 0 score = 0 if args.method == 2: target = -args.target else:
def main(): args = get_arguments() print(args) config = CityscapeConfig() config.FLOW = args.flowmodel config.BACKBONE = args.resnetmodel config.IMAGE_SHAPE = [1024, 1024, 6] config.POST_NMS_ROIS_INFERENCE = 500 #config.display() resnet = ResNet(config=config) flownet = FlowNet(config=config) maskrcnn = MaskRCNN(config=config) warp = Warp(config=config) decision = Decision(config=config) model_path = args.restore_from resnet.load_weights(model_path, by_name=True) flownet.load_weights(model_path, by_name=True) maskrcnn.load_weights(model_path, by_name=True) decision.load_weights(args.decision_from, by_name=True) seg_step = 0 flow_step = 0 target = args.target list_file = open(args.data_list, 'r') if args.is_save and not os.path.exists(args.save_dir): os.makedirs(args.save_dir) for step in range(args.num_steps): f1 = list_file.readline().split('\n')[0] f1 = os.path.join(args.data_dir, f1) current = np.expand_dims(skimage.io.imread(f1), 0) current, image_metas, window = mold_inputs(config, current) image = current[0] + config.MEAN_PIXEL if step == 0: seg_step += 1 key_P2, key_P3, key_P4, key_P5, key_P6 = resnet.keras_model.predict( current) key = current P2, P3, P4, P5, P6 = key_P2, key_P3, key_P4, key_P5, key_P6 else: images = np.concatenate([current, key], 3) flow, flow_feature = flownet.keras_model.predict(images) score = decision.keras_model.predict(flow_feature)[0][0] print("step: {:4d} predict score: {:.3f} target: {:.2f}".format( step, score, target)) if score < target: if args.dynamic and target < 50: target -= 0.5 seg_step += 1 key_P2, key_P3, key_P4, key_P5, key_P6 = resnet.keras_model.predict( current) key = current P2, P3, P4, P5, P6 = key_P2, key_P3, key_P4, key_P5, key_P6 else: if args.dynamic and target < 95: target += 0.25 flow_step += 1 P2, P3, P4, P5, P6 = warp.predict( [key_P2, key_P3, key_P4, key_P5, key_P6, flow]) inputs = [image_metas, P2, P3, P4, P5, P6] result = maskrcnn.detect_molded(inputs) # Save if args.is_save: save_name = args.save_dir + 'mask' + str(step) + '.png' colors = np.array(label_colors) / 255.0 pred_img = visualize.display_instances(image, result['rois'], result['masks'], result['class_ids'], class_names, result['scores'], colors=colors, save_name=save_name) print("segmentation steps:", seg_step, "flow steps:", flow_step)
def get_decision(self): return Decision(datetime.utcnow(), self.__decision, self.name)
def modify_decision(request, decision_id=None, status_id=None): if decision_id is None: decision = Decision() if status_id is not None: decision.status = int(status_id) else: decision = get_object_or_404(Decision, id=decision_id) if request.method == "POST": if request.POST.get('submit', None) == "Cancel": return_page = unicode(decision.status_text()) return HttpResponseRedirect(reverse(listing, args=[return_page])) else: decision_form = DecisionForm(data=request.POST, instance=decision) feedback_formset = FeedbackFormSet(data=request.POST, instance=decision) if decision_form.is_valid(): decision = decision_form.save(commit=False) feedback_formset = FeedbackFormSet(request.POST, instance=decision) if feedback_formset.is_valid(): decision.save(request.user) if decision_form.cleaned_data['watch']: decision.add_watcher(request.user) else: decision.remove_watcher(request.user) feedback_formset.save() return_page = unicode(decision.status_text()) return HttpResponseRedirect( reverse(listing, args=[return_page])) else: feedback_formset = FeedbackFormSet(instance=decision) decision_form = DecisionForm(instance=decision) return render_to_response( 'decision_edit.html', RequestContext( request, dict(decision_form=decision_form, feedback_formset=feedback_formset)))
def _get_real_contest_decisions(contest): decisions = [] results = api.ballot_get_decisions_by_contest(contest.id) if results: decisions = [Decision(contest, d) for d in results] return decisions