Load Dataset

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


In [3]:
import django
from django.conf import settings
django.setup()

In [4]:
from app.models import Label,Image,Batch, Comment, 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, 5))
print(getbatchlist(range(10)))


[range(0, 5), range(5, 10)]

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)


In [11]:
# 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), '*.PNG')
for chunk in getbatchlist(raw_files):
    b=Batch()
    b.save()
    for i in chunk:        
        j=str(uuid4())+'.PNG'
        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: BID000005,src: 388C9BD3-546C-489D-8FD2-3CE967189503-2607-0000048535E9C9B8.PNG, dst: 41d1fe5c-f9c6-4bc0-80e8-dea24b5b1b17.PNG

In [ ]: