-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
53 lines (39 loc) · 2.01 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import argparse
import os
import shutil
import requests
import tarfile
from tqdm import tqdm
from utilities import datasets
from map_dataset import map_dataset
def parse_arguments():
parser = argparse.ArgumentParser(description='download and extract all dataset images and annotations with '
'optional mapping to all pre-defined dataset variants')
parser.add_argument('--data_root', type=str, default='../data',
help='directory for downloaded images and annotations')
parser.add_argument('--no_mapping', dest='with_mapping', action='store_false', default=True,
help='skip mapping for predefined dataset variants')
return parser.parse_args()
def setup(data_root, with_mapping):
url_prefix = 'https://vitro-testing.com/wp-content/uploads/2022/12/'
os.makedirs(data_root, exist_ok=True)
for file_name in tqdm(
['cropandweed_annotations', 'cropandweed_images1of4', 'cropandweed_images2of4', 'cropandweed_images3of4',
'cropandweed_images4of4'], desc='downloading and extracting files'):
response = requests.get(f'{url_prefix}{file_name}.tar', stream=True)
archive = tarfile.open(fileobj=response.raw, mode='r|')
archive.extractall(data_root)
shutil.move(os.path.join(data_root, 'bboxes'), os.path.join(data_root, 'CropAndWeed'))
shutil.move(os.path.join(data_root, 'CropAndWeed'), os.path.join(data_root, 'bboxes', 'CropAndWeed'))
if with_mapping:
for dataset in datasets.DATASETS:
if dataset != 'CropAndWeed':
map_dataset(os.path.join(data_root, 'bboxes'), os.path.join(data_root, 'labelIds'), 'CropAndWeed',
dataset)
for image_name in os.listdir('../images'):
shutil.copy(os.path.join('../images', image_name), os.path.join(data_root, 'images', image_name))
def main():
args = parse_arguments()
setup(args.data_root, args.with_mapping)
if __name__ == '__main__':
main()