Exemplo n.º 1
0
def create(request):
    if request.method == 'POST':
        dataset = Dataset()
        dataset.owner = request.user
        dataset.name = request.POST['name']
        dataset.number_of_labels = request.POST['number_of_labels']
        dataset.description = request.POST['description']

        if not dataset.privacy_validation(request.POST['privacy']):
            return render(request, '400.html', status=400)

        dataset_file = request.FILES['dataset']
        reader = csv.reader(dataset_file, encoding='utf-8')
        header_list = reader.next()

        label_name = request.POST.get('label_name', 'CLASS')
        append_label_column = request.POST.get('append_label_column', False)
        if not append_label_column:
            label_index = header_list.index(label_name)
            header_list.pop(label_index)

        header_list.append(label_name)
        dataset.header = csvlist_to_string(header_list).strip()
        dataset.save()

        samples_count = 0
        for row_list in reader:
            samples_count += 1
            if not append_label_column:
                label_string = row_list.pop(label_index)

            row = csvlist_to_string(row_list).strip()
            sample = Sample(dataset=dataset,
                            data=row,
                            original_index=samples_count)
            sample.save()

            if not append_label_column and label_string:
                label = Label(owner=request.user,
                              sample=sample,
                              label=label_string)
                label.save()
                sample.times_labeled = 1
                sample.save()

        dataset.number_of_samples = samples_count
        dataset.save()

        return HttpResponseRedirect(
            reverse('datasets_show', args=(dataset.id, )))
Exemplo n.º 2
0
def add(label_dict=None, raw=False):
    content = label_dict if label_dict else request.json
    user_id = label_dict["user_id"] if label_dict else get_jwt_identity()
    user = User.objects(id=user_id).first()
    task = Task.objects(id=content["task_id"]).first()
    if task in user.tasks:
        label = Label()
        label.color = content["color"]
        label.name = content["name"]
        label.isthing = content["isthing"]
        label.save()
        task.labels.append(label)
        task.save()
        return (label.to_json(), 200) if not raw else label
    abort(404)
Exemplo n.º 3
0
def create(request):
    if request.method == 'POST':
        dataset = Dataset()
        dataset.owner = request.user
        dataset.name = request.POST['name']
        dataset.number_of_labels = request.POST['number_of_labels']
        dataset.description = request.POST['description']

        if not dataset.privacy_validation(request.POST['privacy']):
            return render(request, '400.html', status=400)

        dataset_file = request.FILES['dataset']
        reader = csv.reader(dataset_file, encoding='utf-8')
        header_list = reader.next()

        label_name = request.POST.get('label_name', 'CLASS')
        append_label_column = request.POST.get('append_label_column', False)
        if not append_label_column:
            label_index = header_list.index(label_name)
            header_list.pop(label_index)

        header_list.append(label_name)
        dataset.header = csvlist_to_string(header_list).strip()
        dataset.save()

        samples_count = 0
        for row_list in reader:
            samples_count += 1
            if not append_label_column:
                label_string = row_list.pop(label_index)

            row = csvlist_to_string(row_list).strip()
            sample = Sample(dataset=dataset, data=row,
                            original_index=samples_count)
            sample.save()

            if not append_label_column and label_string:
                label = Label(owner=request.user, sample=sample,
                              label=label_string)
                label.save()
                sample.times_labeled = 1
                sample.save()

        dataset.number_of_samples = samples_count
        dataset.save()

        return HttpResponseRedirect(
            reverse('datasets_show', args=(dataset.id,)))
Exemplo n.º 4
0
def batch(request, batch_id):
    if request.method == 'GET':
        _labels = [
            {
                "id": "rec0",
                "x": 290,
                "y": 245,
                "width": 650,
                "height": 341,
                "brand": "b0",
                "model": "m0",
                "color": "c0",
                "nn": "n0"
            },
        ]
        _images = [
            {
                "src": "static/dataset/_00.jpg",
                "labels": _labels
            },
        ]

        #x=Batch.objects.get(pk=batch_id)
        BID = Batch.objects.get(pk=batch_id)
        IMGS = Image.objects.filter(batch=BID)
        data = []
        for I in IMGS:
            labels = []
            for L in Label.objects.filter(image=I):
                labels.append({
                    #"id":"rec%d"%L.id,
                    "x": L.x,
                    "y": L.y,
                    "width": L.width,
                    "height": L.height,
                    "brand": L.brand,
                    "model": L.model,
                    "color": L.color,
                    "nn": L.nickname,
                })
            item = {'src': I.src_path, 'labels': labels}
            data.append(item)
        return JsonResponse(data, safe=False)
    if request.method == 'POST':
        client_data = json.loads(request.POST.get('client_data'))
        print client_data
        images = client_data
        for i in images:
            print "i: %s" % i
            m = Image.objects.get(src_path=i['src'])
            Label.objects.filter(image=m).delete()
            for j in i['labels']:
                m = Image.objects.get(src_path=i['src'])
                q = Label(image=m,
                          x=j['x'],
                          y=j['y'],
                          width=j['width'],
                          height=j['height'],
                          brand=j['brand'],
                          model=j['model'],
                          color=j['color'],
                          nickname=j['nn'])
                q.save()
        if request.POST.get('rework'):
            b = Batch.objects.get(pk=batch_id)
            b.num_rework = b.num_rework + 1
            b.status = md.TAGGING
            b.save()
        else:
            if request.POST.get('submission'):
                if request.POST.get(
                        'submission'
                ) == '1' and 'username' in request.session:  #reviewer
                    _username = request.session['username']
                    u = User.objects.get(username=_username)
                    mu = MyUser.objects.get(user=u)
                    b = Batch.objects.get(pk=batch_id)
                    b.reviewer = mu
                    b.status = md.DONE
                    b.save()
                    print "DONE:: batch: %s, status: %s, submission: %s" % (
                        b, b.status, request.POST.get('submission'))
                else:  #labeller
                    b = Batch.objects.get(pk=batch_id)
                    b.status = md.REVIEWING
                    b.save()
                    print "TO REVIEWER:: batch: %s, status: %s, submission: %s" % (
                        b, b.status, request.POST.get('submission'))
            else:
                #				b=Batch.objects.get(pk=batch_id)
                #				if 'username' in request.session:				#debug view92
                #					_username=request.session['username']
                #					print "#debug view92:: username: %s"%_username
                #					if b.labeller:
                #						print "#debug view92:: the batch being labelled"
                #					else:										#labelling for the first time
                #						u=User.objects.get(username=_username)
                #						mu=MyUser.objects.get(user=u)
                #						b.status=md.TAGGING
                #						b.labeller=mu
                #						b.save()
                print "batch: %s, status: %s" % (b, b.status)
        return JsonResponse(images, safe=False)