Load Dataset

To clear all record and load all images to the /dataset. svg_w=960, svg_h=540


In [11]:
from app.models import Label,Image,Batch, STATUS_CHOICES
from django.contrib.auth.models import User
import os, fnmatch, uuid, shutil
from uuid import uuid4
def getbatchlist(filelist):
    def chunks(li, n):
        """Yield successive n-sized chunks from l."""
        for i in range(0, len(li), n):
            yield li[i:i + n]

    return list(chunks(filelist, 4))
print getbatchlist(range(10))


[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9]]

In [14]:
#FOR DEBUG ONLY !!!!
# Clear all batches and move images from /dataset to /raw
print "DELETE ALL RECORDS!!"
q=Batch.objects.all().delete()
static_path = settings.STATICFILES_DIRS[0]
raw_path = os.path.join(static_path,'raw')
dataset_path = os.path.join(static_path,'dataset')
raw_files = fnmatch.filter(os.listdir(dataset_path), '*.jpg')
for i in raw_files:
        _dst=os.path.join(raw_path, i )
        _src=os.path.join(dataset_path,i)
        print "moving to: %s"%(_dst)
        shutil.move(src=_src, dst=_dst)


DELETE ALL RECORDS!!
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\0dea1b3a-6d2d-460d-bb02-adb294c16c7e.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\24040a87-f580-4f80-ac1f-f622e22c6898.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\31e822ad-33bd-431c-b316-9ac26c8eb6e8.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\3f93002e-b003-466d-97a9-96e8de69062b.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\40beb221-a7c6-408f-8aa1-f88133b39866.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\4fb26a19-1916-403c-9812-47f827db0602.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\752f2073-b400-416f-9ab6-00b12957d3a4.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\75ce0b55-5db6-4c4a-9012-4fbbcd2f9154.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\b8c38912-b5aa-4efd-9250-e30eb8fc8b7a.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\alpha\visionmarker\static\raw\ca7ef3a4-d798-4f01-a3fb-569fdcf47d60.jpg

In [13]:
# moving from /raw/i to /dataset/j
static_path = settings.STATICFILES_DIRS[0]
raw_path = os.path.join(static_path,'raw')
dataset_path = os.path.join(static_path,'dataset')
raw_files = fnmatch.filter(os.listdir(raw_path), '*.jpg')
for chunk in getbatchlist(raw_files):
    b=Batch()
    b.save()
    for i in chunk:        
        j=unicode(uuid4())+'.jpg'
        print "batch: %s,src: %s, dst: %s"%(b,i,j)
        Image(batch=b, src_path=j, raw_path=i).save()
        _dst=os.path.join(dataset_path,j)
        _src=os.path.join(raw_path,i)
        
        shutil.move(src=_src, dst=_dst)


batch: BID000039,src: 26e99ff2-2ce2-4bf7-8d02-53c0652aa6d2.jpg, dst: 24040a87-f580-4f80-ac1f-f622e22c6898.jpg
batch: BID000039,src: 299bed08-1999-4b2d-89ba-da75ade979f1.jpg, dst: 75ce0b55-5db6-4c4a-9012-4fbbcd2f9154.jpg
batch: BID000039,src: 383e1243-3d51-4d14-9c96-fbdb02011a40.jpg, dst: 0dea1b3a-6d2d-460d-bb02-adb294c16c7e.jpg
batch: BID000039,src: 43121327-ccd4-4cae-878c-7196b277c0dc.jpg, dst: 40beb221-a7c6-408f-8aa1-f88133b39866.jpg
batch: BID000040,src: 686c8663-5374-4bdd-ad5d-26c881cb7308.jpg, dst: 752f2073-b400-416f-9ab6-00b12957d3a4.jpg
batch: BID000040,src: 97737281-bd83-4d3f-acf1-0db86134e5c1.jpg, dst: 4fb26a19-1916-403c-9812-47f827db0602.jpg
batch: BID000040,src: a0046d97-2685-49cb-825f-7da349051d0e.jpg, dst: 31e822ad-33bd-431c-b316-9ac26c8eb6e8.jpg
batch: BID000040,src: ba5d951b-2f35-497a-a07b-31771b1e8f4a.jpg, dst: b8c38912-b5aa-4efd-9250-e30eb8fc8b7a.jpg
batch: BID000041,src: c8354ad9-14e4-472f-b0cd-4c7d67741892.jpg, dst: ca7ef3a4-d798-4f01-a3fb-569fdcf47d60.jpg
batch: BID000041,src: e7c3d447-eb2a-46f3-a831-e26caf851d6a.jpg, dst: 3f93002e-b003-466d-97a9-96e8de69062b.jpg

In [22]:
x=Batch()
x.save()
x.id


Out[22]:
10

In [17]:
x.id

In [18]:
x.save()

In [12]:
_labeller=MyUser.objects.get(user=User.objects.get(username='mylabeller'))
_reviwer=MyUser.objects.get(user=User.objects.get(username='admin'))
Batch(reviewer=_reviwer, labeller=_labeller).save()

In [13]:
User.objects.all()[1].username


Out[13]:
u'mylabeller'

In [32]:
Batch.objects.filter(status='1').first().id


Out[32]:
14

In [4]:
import app.models as md
u=User.objects.get(username="admin")
mu=MyUser.objects.get(user=u)
b=Batch.objects.filter(status=md.TAGGING,labeller=mu).first()

In [10]:
if not b:
    print "foo"
else:
    print "bar"


foo

In [9]:
type(b)


Out[9]:
NoneType

In [ ]: