Buckets:
| import os, shutil, collections | |
| from PIL import Image, ImageDraw | |
| A='Annotations1024'; I='Vehicules1024'; O='vedai_obb'; S=1024.0 | |
| rows=collections.defaultdict(list) | |
| for l in open(f'{A}/annotation1024.txt'): | |
| p=l.split() | |
| if len(p)<15: continue | |
| rows[p[0]].append(p) | |
| ids=sorted({p[12] for r in rows.values() for p in r}); cmap={c:i for i,c in enumerate(ids)} | |
| tr=[x.strip() for x in open(f'{A}/fold01.txt') if x.strip()]; va=[x.strip() for x in open(f'{A}/fold01test.txt') if x.strip()] | |
| assert not set(tr)&set(va) | |
| bad=0 | |
| for split,lst in (('train',tr),('val',va)): | |
| os.makedirs(f'{O}/images/{split}',exist_ok=True); os.makedirs(f'{O}/labels/{split}',exist_ok=True) | |
| for i in lst: | |
| os.symlink(os.path.abspath(f'{I}/{i}_co.png'),f'{O}/images/{split}/{i}.png') | |
| out=[] | |
| for p in rows.get(i,[]): | |
| xs=[float(v) for v in p[4:8]]; ys=[float(v) for v in p[8:12]] | |
| if min(xs+ys)<-1 or max(xs+ys)>S+1: bad+=1 | |
| out.append(f"{cmap[p[12]]} "+" ".join(f"{min(max(x/S,0),1):.6f} {min(max(y/S,0),1):.6f}" for x,y in zip(xs,ys))) | |
| open(f'{O}/labels/{split}/{i}.txt','w').write("\n".join(out)+("\n" if out else "")) | |
| open(f'{O}/data.yaml','w').write(f"path: {os.path.abspath(O)}\ntrain: images/train\nval: images/val\nnames:\n"+"".join(f" {i}: c{c}\n" for i,c in enumerate(ids))) | |
| print(len(tr),len(va),'out-of-range',bad,cmap) | |
| # viz | |
| for k,i in enumerate([x for x in tr if os.path.getsize(f'{O}/labels/train/{x}.txt')>0][:2]): | |
| im=Image.open(f'{I}/{i}_co.png').convert('RGB'); d=ImageDraw.Draw(im) | |
| for l in open(f'{O}/labels/train/{i}.txt'): | |
| v=l.split(); pts=[(float(v[1+2*j])*S,float(v[2+2*j])*S) for j in range(4)] | |
| d.polygon(pts,outline=(255,0,0)); d.ellipse([pts[0][0]-5,pts[0][1]-5,pts[0][0]+5,pts[0][1]+5],fill=(255,255,0)) | |
| im.save(f'viz{k}.png') | |
Xet Storage Details
- Size:
- 1.83 kB
- Xet hash:
- 1615abbbf5782991ea50cc9e3b82c9c7e0c2e588c654ffe2f1a1700a29c2fe24
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.