用kafka接收消息
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7KB

  1. """Prepare ADE20K dataset"""
  2. import os
  3. import sys
  4. import argparse
  5. import zipfile
  6. # TODO: optim code
  7. cur_path = os.path.abspath(os.path.dirname(__file__))
  8. root_path = os.path.split(os.path.split(os.path.split(cur_path)[0])[0])[0]
  9. sys.path.append(root_path)
  10. from core.utils import download, makedirs
  11. _TARGET_DIR = os.path.expanduser('~/.torch/datasets/ade')
  12. def parse_args():
  13. parser = argparse.ArgumentParser(
  14. description='Initialize ADE20K dataset.',
  15. epilog='Example: python setup_ade20k.py',
  16. formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  17. parser.add_argument('--download-dir', default=None, help='dataset directory on disk')
  18. args = parser.parse_args()
  19. return args
  20. def download_ade(path, overwrite=False):
  21. _AUG_DOWNLOAD_URLS = [
  22. ('http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip',
  23. '219e1696abb36c8ba3a3afe7fb2f4b4606a897c7'),
  24. (
  25. 'http://data.csail.mit.edu/places/ADEchallenge/release_test.zip',
  26. 'e05747892219d10e9243933371a497e905a4860c'), ]
  27. download_dir = os.path.join(path, 'downloads')
  28. makedirs(download_dir)
  29. for url, checksum in _AUG_DOWNLOAD_URLS:
  30. filename = download(url, path=download_dir, overwrite=overwrite, sha1_hash=checksum)
  31. # extract
  32. with zipfile.ZipFile(filename, "r") as zip_ref:
  33. zip_ref.extractall(path=path)
  34. if __name__ == '__main__':
  35. args = parse_args()
  36. makedirs(os.path.expanduser('~/.torch/datasets'))
  37. if args.download_dir is not None:
  38. if os.path.isdir(_TARGET_DIR):
  39. os.remove(_TARGET_DIR)
  40. # make symlink
  41. os.symlink(args.download_dir, _TARGET_DIR)
  42. download_ade(_TARGET_DIR, overwrite=False)