コード例 #1
0
def training(request):
    context = {}
    context["videos"] = Video.objects.all().filter()
    context["detectors"] = CustomDetector.objects.all()
    if request.method == 'POST':
        if request.POST.get('action') == 'estimate':
            args = request.POST.get('args')
            args = json.loads(args) if args.strip() else {}
            args['name'] = request.POST.get('name')
            args['labels'] = [k.strip() for k in request.POST.get('labels').split(',') if k.strip()]
            args['object_names'] = [k.strip() for k in request.POST.get('object_names').split(',') if k.strip()]
            args['excluded_videos'] = request.POST.getlist('excluded_videos')
            labels = set(args['labels']) if 'labels' in args else set()
            object_names = set(args['object_names']) if 'object_names' in args else set()
            class_distribution, class_names, rboxes, rboxes_set, frames, i_class_names = create_detector_dataset(object_names, labels)
            context["estimate"] = {
                'args':args,
                'class_distribution':class_distribution,
                'class_names':class_names,
                'rboxes':rboxes,
                'rboxes_set':rboxes_set,
                'frames':frames,
                'i_class_names':i_class_names
            }
        else:
            args = request.POST.get('args')
            args = json.loads(args) if args.strip() else {}
            args['name'] = request.POST.get('name')
            args['labels'] = [k.strip() for k in request.POST.get('labels').split(',') if k.strip()]
            args['object_names'] = [k.strip() for k in request.POST.get('object_names').split(',') if k.strip()]
            args['excluded_videos'] = request.POST.getlist('excluded_videos')
            detector = CustomDetector()
            detector.name = args['name']
            detector.algorithm = "yolo"
            detector.arguments = json.dumps(args)
            detector.save()
            args['detector_pk'] = detector.pk
            operation = "train_yolo_detector"
            train_event = TEvent()
            train_event.operation = operation
            train_event.arguments = args
            train_event.save()
            detector.source = train_event
            detector.save()
            app.send_task(name=operation, args=[train_event.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[operation])
    return render(request, 'training.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: pustar/DeepVideoAnalytics
def detections(request):
    context = {}
    context["videos"] = Video.objects.all().filter(
        parent_query__count__isnull=True)
    context["detectors"] = CustomDetector.objects.all()
    detector_stats = []
    for d in CustomDetector.objects.all():
        class_dist = json.loads(
            d.class_distribution) if d.class_distribution.strip() else {}
        detector_stats.append({
            'name': d.name,
            'classes': class_dist,
            'frames_count': d.frames_count,
            'boxes_count': d.boxes_count,
            'pk': d.pk
        })
    context["detector_stats"] = detector_stats
    if request.method == 'POST':
        if request.POST.get('action') == 'detect':
            detector_pk = request.POST.get('detector_pk')
            video_pk = request.POST.get('video_pk')
            task_name = "detect_custom_objects"
            apply_event = TEvent()
            apply_event.video_id = video_pk
            apply_event.operation = task_name
            apply_event.arguments_json = json.dumps(
                {'detector_pk': int(detector_pk)})
            apply_event.save()
            app.send_task(name=task_name,
                          args=[
                              apply_event.pk,
                          ],
                          queue=settings.TASK_NAMES_TO_QUEUE[task_name])
        elif request.POST.get('action') == 'estimate':
            args = request.POST.get('args')
            args = json.loads(args) if args.strip() else {}
            args['name'] = request.POST.get('name')
            args['labels'] = [
                k.strip() for k in request.POST.get('labels').split(',')
                if k.strip()
            ]
            args['object_names'] = [
                k.strip() for k in request.POST.get('object_names').split(',')
                if k.strip()
            ]
            args['excluded_videos'] = request.POST.getlist('excluded_videos')
            labels = set(args['labels']) if 'labels' in args else set()
            object_names = set(
                args['object_names']) if 'object_names' in args else set()
            class_distribution, class_names, rboxes, rboxes_set, frames, i_class_names = create_detector_dataset(
                object_names, labels)
            context["estimate"] = {
                'args': args,
                'class_distribution': class_distribution,
                'class_names': class_names,
                'rboxes': rboxes,
                'rboxes_set': rboxes_set,
                'frames': frames,
                'i_class_names': i_class_names
            }
        else:
            args = request.POST.get('args')
            args = json.loads(args) if args.strip() else {}
            args['name'] = request.POST.get('name')
            args['labels'] = [
                k.strip() for k in request.POST.get('labels').split(',')
                if k.strip()
            ]
            args['object_names'] = [
                k.strip() for k in request.POST.get('object_names').split(',')
                if k.strip()
            ]
            args['excluded_videos'] = request.POST.getlist('excluded_videos')
            detector = CustomDetector()
            detector.name = args['name']
            detector.algorithm = "yolo"
            detector.arguments = json.dumps(args)
            detector.save()
            args['detector_pk'] = detector.pk
            task_name = "train_yolo_detector"
            train_event = TEvent()
            train_event.operation = task_name
            train_event.arguments_json = json.dumps(args)
            train_event.save()
            detector.source = train_event
            detector.save()
            app.send_task(name=task_name,
                          args=[
                              train_event.pk,
                          ],
                          queue=settings.TASK_NAMES_TO_QUEUE[task_name])
    return render(request, 'detections.html', context)
コード例 #3
0
ファイル: views.py プロジェクト: ycaihua/DeepVideoAnalytics
def training(request):
    context = {}
    context["videos"] = Video.objects.all().filter(parent_query__isnull=True)
    context["detectors"] = CustomDetector.objects.all()
    if request.method == 'POST':
        if request.POST.get('action') == 'estimate':
            args = request.POST.get('args')
            args = json.loads(args) if args.strip() else {}
            args['name'] = request.POST.get('name')
            args['labels'] = [k.strip() for k in request.POST.get('labels').split(',') if k.strip()]
            args['object_names'] = [k.strip() for k in request.POST.get('object_names').split(',') if k.strip()]
            args['excluded_videos'] = request.POST.getlist('excluded_videos')
            labels = set(args['labels']) if 'labels' in args else set()
            object_names = set(args['object_names']) if 'object_names' in args else set()
            class_distribution, class_names, rboxes, rboxes_set, frames, i_class_names = create_detector_dataset(object_names, labels)
            context["estimate"] = {
                'args':args,
                'class_distribution':class_distribution,
                'class_names':class_names,
                'rboxes':rboxes,
                'rboxes_set':rboxes_set,
                'frames':frames,
                'i_class_names':i_class_names
            }
        else:
            args = request.POST.get('args')
            args = json.loads(args) if args.strip() else {}
            args['name'] = request.POST.get('name')
            args['labels'] = [k.strip() for k in request.POST.get('labels').split(',') if k.strip()]
            args['object_names'] = [k.strip() for k in request.POST.get('object_names').split(',') if k.strip()]
            args['excluded_videos'] = request.POST.getlist('excluded_videos')
            detector = CustomDetector()
            detector.name = args['name']
            detector.algorithm = "yolo"
            detector.arguments = json.dumps(args)
            detector.save()
            args['detector_pk'] = detector.pk
            task_name = "train_yolo_detector"
            train_event = TEvent()
            train_event.operation = task_name
            train_event.arguments_json = json.dumps(args)
            train_event.save()
            detector.source = train_event
            detector.save()
            app.send_task(name=task_name, args=[train_event.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name])
    return render(request, 'training.html', context)