1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- path: ../datasets/SKU-110K
- train: train.txt
- val: val.txt
- test: test.txt
- names:
- 0: object
- download: |
- import shutil
- from tqdm import tqdm
- from utils.general import np, pd, Path, download, xyxy2xywh
-
- dir = Path(yaml['path'])
- parent = Path(dir.parent)
- urls = ['http://trax-geometry.s3.amazonaws.com/cvpr_challenge/SKU110K_fixed.tar.gz']
- download(urls, dir=parent, delete=False)
-
- if dir.exists():
- shutil.rmtree(dir)
- (parent / 'SKU110K_fixed').rename(dir)
- (dir / 'labels').mkdir(parents=True, exist_ok=True)
-
- names = 'image', 'x1', 'y1', 'x2', 'y2', 'class', 'image_width', 'image_height'
- for d in 'annotations_train.csv', 'annotations_val.csv', 'annotations_test.csv':
- x = pd.read_csv(dir / 'annotations' / d, names=names).values
- images, unique_images = x[:, 0], np.unique(x[:, 0])
- with open((dir / d).with_suffix('.txt').__str__().replace('annotations_', ''), 'w') as f:
- f.writelines(f'./images/{s}\n' for s in unique_images)
- for im in tqdm(unique_images, desc=f'Converting {dir / d}'):
- cls = 0
- with open((dir / 'labels' / im).with_suffix('.txt'), 'a') as f:
- for r in x[images == im]:
- w, h = r[6], r[7]
- xywh = xyxy2xywh(np.array([[r[1] / w, r[2] / h, r[3] / w, r[4] / h]]))[0]
- f.write(f"{cls} {xywh[0]:.5f} {xywh[1]:.5f} {xywh[2]:.5f} {xywh[3]:.5f}\n")
|