gulou 645fed2d1b
add data source and support for automatic download (#206)
* add data_source imagenet

* modify data_source imagenet and add unittest

* modify data_source imagenet and modify unittest

* modify voc data_source and modify voc unittest and download Part

* modify coco data_source and modify coco unittest and  add download Part , modify voc data_source

* add dataset metadata Format specification

* add pose download data , modify coco.py and modiy download file function ,add test coco download a part

* modify download file function

* modify download of cifar10 and cifar100

* modify dataset_name  to target_dir

* create download_util and modify function

* modify function

* modify function

* add test case , modify

* modify something

* modify something

* modify something

* modify something

* modify something

* modify something

* add wget

* add wget

* modify

* add new modify

* add new modify

* modify something

* modify something and add something

* modify something and add something

* modify something and add something

* modify something and add something

* modify something and add something

* modify test case

* modify test case

* modify test case

* modify test case

* modify test case
2022-11-04 19:36:37 +08:00

53 lines
1.4 KiB
Python

# Copyright (c) Alibaba, Inc. and its affiliates.
import os
from easycv.utils.constant import CACHE_DIR
from .commont import VOC_CFG, check_path_exists, download
# Check whether the data exists
def check_data_exists(name, target_dir, split):
root_path = os.path.join(target_dir, 'VOCdevkit', name.upper())
if os.path.exists(root_path):
return check_path_exists({'path': process_voc(root_path, split=split)})
else:
return False
# return abs path
def process_voc(path, split='train'):
if split == 'train':
return os.path.join(path, 'ImageSets/Main/train.txt')
else:
return os.path.join(path, 'ImageSets/Main/val.txt')
# xtract the data
def extract(name, file, target_dir=CACHE_DIR):
cmd = f'tar -xvf {file} -C {target_dir}'
print('begin Unpack.....................')
os.system(cmd)
print('Unpack is finished.....................')
def download_voc(name, split='train', target_dir=CACHE_DIR, **kwargs):
# Declare a global
global cfg
# Use it for testing
if kwargs.get('cfg'):
cfg = kwargs.get('cfg')
else:
cfg = VOC_CFG
if check_data_exists(name, target_dir, split):
return check_data_exists(name, target_dir, split)
# Start the download
file_path = download(cfg.get(name), target_dir=target_dir)
# began to unpack
extract(name, file_path, target_dir=target_dir)
return check_data_exists(name, target_dir, split)