Beispiel #1
0
    def _download_and_extract(self):
        if self._dataset_size == ImagenetteSize.full:
            url = "https://s3.amazonaws.com/fast-ai-imageclas/imagewoof.tgz"
        elif self._dataset_size == ImagenetteSize.s320:
            url = "https://s3.amazonaws.com/fast-ai-imageclas/imagewoof-320.tgz"
        elif self._dataset_size == ImagenetteSize.s160:
            url = "https://s3.amazonaws.com/fast-ai-imageclas/imagewoof-160.tgz"
        else:
            raise ValueError("unknown imagenette size given of {}".format(
                self._dataset_size))

        create_dirs(self._extracted_root)
        file_path = "{}.tar".format(self._extracted_root)

        if os.path.exists(file_path):
            print("already downloaded imagewoof {}".format(self._dataset_size))

            return

        download_file(
            url,
            file_path,
            overwrite=False,
            progress_title="downloading imagewoof {}".format(
                self._dataset_size),
        )

        with tarfile.open(file_path, "r:gz") as tar:
            tar.extractall(path=self.download_root)
Beispiel #2
0
    def _download_and_extract(self):
        """
        Download and extract the dataset into root
        """
        create_dirs(self._download_dir)
        file_path = os.path.join(self._download_dir, "cifar-100-python.tar.gz")
        url = "https://www.cs.toronto.edu/~kriz/cifar-100-python.tar.gz"
        download_file(
            url,
            file_path,
            overwrite=False,
            progress_title="downloading CIFAR-100",
        )

        create_dirs(self._extract_dir)
        with tarfile.open(file_path, "r:gz") as tar:
            tar.extractall(path=self._extract_dir)
Beispiel #3
0
    def download(
        self,
        overwrite: bool = False,
        refresh_token: bool = False,
        show_progress: bool = True,
    ):
        """
        Downloads a sparsezoo file.

        :param overwrite: True to overwrite any previous file, False otherwise
        :param refresh_token: True to refresh the auth token, False otherwise
        :param show_progress: True to print tqdm progress, False otherwise
        """
        if os.path.exists(self.path) and not overwrite:
            _LOGGER.debug(
                f"Model file {self.display_name} already exists, "
                f"skipping download to {self.path}"
            )

            return

        if not self.url:
            _LOGGER.info(
                "Getting signed url for "
                f"{self.model_metadata.model_id}/{self.display_name}"
            )
            self._url = self._signed_url(refresh_token)

        _LOGGER.info(f"Downloading model file {self.display_name} to {self.path}")

        # cleaning up target
        try:
            os.remove(self.path)
        except Exception:
            pass

        # creating target and downloading
        create_parent_dirs(self.path)
        download_file(
            self.url, self.path, overwrite=overwrite, show_progress=show_progress
        )