code: def download_objects365v2(
      url, dir, unzip=True, delete=False, threads=1
  ):
      def download_single(url, dir):
          if "train" in url:
              saving_dir = dir / Path("train_zip")
              mkdir_or_exist(saving_dir)
              f = saving_dir / Path(url).name
  
              unzip_dir = dir / Path("train")
              mkdir_or_exist(unzip_dir)
          elif "val" in url:
              saving_dir = dir / Path("val")
              mkdir_or_exist(saving_dir)
              f = saving_dir / Path(url).name
  
              unzip_dir = dir / Path("val")
              mkdir_or_exist(unzip_dir)
          else:
              raise NotImplementedError
  
          if Path(url).is_file():
              Path(url).rename(f)
          elif not f.exists():
              print(f"Downloading {url} to {f}")
              torch.hub.download_url_to_file(url, f, progress=True)
  
          if unzip and str(f).endswith(".tar.gz"):
              print(f"Unzipping {f.name}")
              tar = tarfile.open(f)
              tar.extractall(path=unzip_dir)
              if delete:
                  f.unlink()
                  print(f"Delete {f}")
  
      # process annotations
      full_url = []
      for _url in url:
          if (
              "zhiyuan_objv2_train.tar.gz" in _url
              or "zhiyuan_objv2_val.json" in _url
          ):
              full_url.append(_url)
          elif "train" in _url:
              for i in range(51):
                  full_url.append(f"{_url}patch{i}.tar.gz")
          elif "val/images/v1" in _url:
              for i in range(16):
                  full_url.append(f"{_url}patch{i}.tar.gz")
          elif "val/images/v2" in _url:
              for i in range(16, 44):
                  full_url.append(f"{_url}patch{i}.tar.gz")
          else:
              raise NotImplementedError
  
      dir = Path(dir)
      if threads > 1:
          pool = ThreadPool(threads)
          pool.imap(
              lambda x: download_single(*x), zip(full_url, repeat(dir))
          )
          pool.close()
          pool.join()
      else:
          for u in full_url:
              download_single(u, dir)
  
file_path: mmdetection/tools/misc/download_dataset.py
imports: import argparse
  import tarfile
  from itertools import repeat
  from multiprocessing.pool import ThreadPool
  from pathlib import Path
  from tarfile import TarFile
  from zipfile import ZipFile
  import torch
  from mmengine.utils.path import mkdir_or_exist
label_desc: Use image node_id 3 for calling a global function with example usage: download_objects365v2(url, dir, unzip, delete, threads) without return types