Load Dataset

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


In [1]:
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))


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

In [2]:
#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\beta\static\raw\15185e10-3d59-4129-b5c4-314fdb228a59.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\beta\static\raw\25136c78-05f6-422c-9b82-cbbd42deb261.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\beta\static\raw\34c84071-abd7-4f01-86e6-3f2dc6c96a0b.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\beta\static\raw\50b41b0a-1fa7-473b-8330-9a26310380b7.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\beta\static\raw\54e9550f-5c1f-46d8-b4d5-45899bf0554f.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\beta\static\raw\693a478e-439a-45de-8b20-20f4d0e0f240.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\beta\static\raw\7696acee-37df-4d8c-b85b-30220ac00020.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\beta\static\raw\88634d71-c69f-4582-b54c-926719da1020.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\beta\static\raw\92506a5f-1f28-482a-98ad-e377c7ddfed3.jpg
moving to: C:\Users\Wasit\Documents\GitHub\visionmarker\beta\static\raw\bbd100a5-82e3-4bcd-8213-24d6ad73ffc6.jpg

In [3]:
# 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: BID000001,src: 15185e10-3d59-4129-b5c4-314fdb228a59.jpg, dst: 6c35c307-30ca-48c1-a92e-7b7dd9b60108.jpg
batch: BID000001,src: 25136c78-05f6-422c-9b82-cbbd42deb261.jpg, dst: ba0d77ca-d6da-4213-b396-944580bfccea.jpg
batch: BID000001,src: 34c84071-abd7-4f01-86e6-3f2dc6c96a0b.jpg, dst: 2ed9b9ed-bcec-45a2-a068-8806e9e83764.jpg
batch: BID000001,src: 50b41b0a-1fa7-473b-8330-9a26310380b7.jpg, dst: f92dd495-e108-401d-9cfc-d498cc768004.jpg
batch: BID000001,src: 54e9550f-5c1f-46d8-b4d5-45899bf0554f.jpg, dst: f1093aab-7a1b-4ef4-bd5c-86174cc86f8c.jpg
batch: BID000002,src: 693a478e-439a-45de-8b20-20f4d0e0f240.jpg, dst: d97782e1-404a-47c3-8f12-decb80c9abf4.jpg
batch: BID000002,src: 7696acee-37df-4d8c-b85b-30220ac00020.jpg, dst: 0d3e864c-fad3-4d30-9580-b61c7ec9fb47.jpg
batch: BID000002,src: 88634d71-c69f-4582-b54c-926719da1020.jpg, dst: f5bed359-f260-41d5-8fc5-2181e9441f7d.jpg
batch: BID000002,src: 92506a5f-1f28-482a-98ad-e377c7ddfed3.jpg, dst: 648e13bf-3aa9-46d6-85ff-6393cf870e00.jpg
batch: BID000002,src: bbd100a5-82e3-4bcd-8213-24d6ad73ffc6.jpg, dst: 8466c83f-6873-4340-ab13-229322640162.jpg

In [ ]: