bdlb/diabetic_retinopathy_diagnosis/benchmark.py
def _extract() -> None:
    """Extracts zip files downloaded from Kaggle."""
    import glob
    import tqdm
    import zipfile
    import tempfile

    # Extract train and test original images
    for split in ["train", "test"]:
      # Extract "<split>.zip.00*"" files to "<split>"
      with tempfile.NamedTemporaryFile() as tmp:
        # Concatenate "<split>.zip.00*" to "<split>.zip"
        for fname in tqdm.tqdm(
            sorted(
                glob.glob(
                    os.path.join(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR,
                                 "{split}.zip.00*".format(split=split))))):
          # Unzip "<split>.zip" to "<split>"
          with open(fname, "rb") as ztmp:
            tmp.write(ztmp.read())
        with zipfile.ZipFile(tmp) as zfile:
          for image in tqdm.tqdm(iterable=zfile.namelist(),
                                 total=len(zfile.namelist())):
            zfile.extract(member=image,
                          path=_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR)
      # Delete "<split>.zip.00*" files
      for splitzip in os.listdir(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR):
        if "{split}.zip.00".format(split=split) in splitzip:
          os.remove(
              os.path.join(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR, splitzip))

    # Extract "sample.zip", "trainLabels.csv.zip"
    for fname in ["sample", "trainLabels.csv"]:
      zfname = os.path.join(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR,
                            "{fname}.zip".format(fname=fname))
      with zipfile.ZipFile(zfname) as zfile:
        zfile.extractall(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR)
      os.remove(zfname)
Extracts zip files downloaded from Kaggle.
Extracts zip files downloaded from Kaggle.
Extracts zip files downloaded from Kaggle .
def _extract() -> None:
    import glob
    import tqdm
    import zipfile
    import tempfile
    for split in ["train", "test"]:
      with tempfile.NamedTemporaryFile() as tmp:
        for fname in tqdm.tqdm(
            sorted(
                glob.glob(
                    os.path.join(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR,
                                 "{split}.zip.00*".format(split=split))))):
          with open(fname, "rb") as ztmp:
            tmp.write(ztmp.read())
        with zipfile.ZipFile(tmp) as zfile:
          for image in tqdm.tqdm(iterable=zfile.namelist(),
                                 total=len(zfile.namelist())):
            zfile.extract(member=image,
                          path=_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR)
      for splitzip in os.listdir(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR):
        if "{split}.zip.00".format(split=split) in splitzip:
          os.remove(
              os.path.join(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR, splitzip))
    for fname in ["sample", "trainLabels.csv"]:
      zfname = os.path.join(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR,
                            "{fname}.zip".format(fname=fname))
      with zipfile.ZipFile(zfname) as zfile:
        zfile.extractall(_DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR)
      os.remove(zfname)
def _extract ( ) -> None : import glob import tqdm import zipfile import tempfile for split in [ "train" , "test" ] : with tempfile . NamedTemporaryFile ( ) as tmp : for fname in tqdm . tqdm ( sorted ( glob . glob ( os . path . join ( _DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR , "{split}.zip.00*" . format ( split = split ) ) ) ) ) : with open ( fname , "rb" ) as ztmp : tmp . write ( ztmp . read ( ) ) with zipfile . ZipFile ( tmp ) as zfile : for image in tqdm . tqdm ( iterable = zfile . namelist ( ) , total = len ( zfile . namelist ( ) ) ) : zfile . extract ( member = image , path = _DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR ) for splitzip in os . listdir ( _DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR ) : if "{split}.zip.00" . format ( split = split ) in splitzip : os . remove ( os . path . join ( _DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR , splitzip ) ) for fname in [ "sample" , "trainLabels.csv" ] : zfname = os . path . join ( _DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR , "{fname}.zip" . format ( fname = fname ) ) with zipfile . ZipFile ( zfname ) as zfile : zfile . extractall ( _DIABETIC_RETINOPATHY_DIAGNOSIS_DATA_DIR ) os . remove ( zfname )
Extracts zip files downloaded from Kaggle.
Extracts zip files downloaded from Kaggle .
"""Extracts zip files downloaded from Kaggle.""" # Extract train and test original images # Extract "<split>.zip.00*"" files to "<split>" # Concatenate "<split>.zip.00*" to "<split>.zip" # Unzip "<split>.zip" to "<split>" # Delete "<split>.zip.00*" files # Extract "sample.zip", "trainLabels.csv.zip"