Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
V0XNIHILI authored Oct 28, 2024
2 parents eed378c + e9a3213 commit a69e4ab
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 72 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/update-viablestrict.yml

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_macros_and_flags():
if NVCC_FLAGS is None:
nvcc_flags = []
else:
nvcc_flags = nvcc_flags.split(" ")
nvcc_flags = NVCC_FLAGS.split(" ")
extra_compile_args["nvcc"] = nvcc_flags

if sys.platform == "win32":
Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/_stereo_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ def _download_dataset(self, root: Union[str, Path]) -> None:
for calibration in ["perfect", "imperfect"]:
scene_name = f"{split_scene}-{calibration}"
scene_url = f"{base_url}/{scene_name}.zip"
print(f"Downloading {scene_url}")
# download the scene only if it doesn't exist
if not (split_root / scene_name).exists():
download_and_extract_archive(
Expand Down
2 changes: 0 additions & 2 deletions torchvision/datasets/caltech.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def __len__(self) -> int:

def download(self) -> None:
if self._check_integrity():
print("Files already downloaded and verified")
return

download_and_extract_archive(
Expand Down Expand Up @@ -231,7 +230,6 @@ def __len__(self) -> int:

def download(self) -> None:
if self._check_integrity():
print("Files already downloaded and verified")
return

download_and_extract_archive(
Expand Down
3 changes: 1 addition & 2 deletions torchvision/datasets/celeba.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(
if mask == slice(None): # if split == "all"
self.filename = splits.index
else:
self.filename = [splits.index[i] for i in torch.squeeze(torch.nonzero(mask))]
self.filename = [splits.index[i] for i in torch.squeeze(torch.nonzero(mask))] # type: ignore[arg-type]
self.identity = identity.data[mask]
self.bbox = bbox.data[mask]
self.landmarks_align = landmarks_align.data[mask]
Expand Down Expand Up @@ -148,7 +148,6 @@ def _check_integrity(self) -> bool:

def download(self) -> None:
if self._check_integrity():
print("Files already downloaded and verified")
return

for (file_id, md5, filename) in self.file_list:
Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/cifar.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def _check_integrity(self) -> bool:

def download(self) -> None:
if self._check_integrity():
print("Files already downloaded and verified")
return
download_and_extract_archive(self.url, self.root, filename=self.filename, md5=self.tgz_md5)

Expand Down
2 changes: 1 addition & 1 deletion torchvision/datasets/cityscapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def __getitem__(self, index: int) -> Tuple[Any, Any]:

targets.append(target)

target = tuple(targets) if len(targets) > 1 else targets[0]
target = tuple(targets) if len(targets) > 1 else targets[0] # type: ignore[assignment]

if self.transforms is not None:
image, target = self.transforms(image, target)
Expand Down
5 changes: 1 addition & 4 deletions torchvision/datasets/imagenette.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ def _check_exists(self) -> bool:

def _download(self):
if self._check_exists():
raise RuntimeError(
f"The directory {self._size_root} already exists. "
f"If you want to re-download or re-extract the images, delete the directory."
)
return

download_and_extract_archive(self._url, self.root, md5=self._md5)

Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/inaturalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,3 @@ def download(self) -> None:
if not os.path.exists(orig_dir_name):
raise RuntimeError(f"Unable to find downloaded files at {orig_dir_name}")
os.rename(orig_dir_name, self.root)
print(f"Dataset version '{self.version}' has been downloaded and prepared for use")
8 changes: 0 additions & 8 deletions torchvision/datasets/kinetics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import csv
import os
import time
import urllib
from functools import partial
from multiprocessing import Pool
Expand Down Expand Up @@ -121,7 +120,6 @@ def __init__(
self._legacy = _legacy

if _legacy:
print("Using legacy structure")
self.split_folder = root
self.split = "unknown"
output_format = "THWC"
Expand Down Expand Up @@ -157,14 +155,8 @@ def __init__(

def download_and_process_videos(self) -> None:
"""Downloads all the videos to the _root_ folder in the expected format."""
tic = time.time()
self._download_videos()
toc = time.time()
print("Elapsed time for downloading in mins ", (toc - tic) / 60)
self._make_ds_structure()
toc2 = time.time()
print("Elapsed time for processing in mins ", (toc2 - toc) / 60)
print("Elapsed time overall in mins ", (toc2 - tic) / 60)

def _download_videos(self) -> None:
"""download tarballs containing the video to "tars" folder and extract them into the _split_ folder where
Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/lfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def _check_integrity(self) -> bool:

def download(self) -> None:
if self._check_integrity():
print("Files already downloaded and verified")
return
url = f"{self.download_url_prefix}{self.filename}"
download_and_extract_archive(url, self.root, filename=self.filename, md5=self.md5)
Expand Down
13 changes: 7 additions & 6 deletions torchvision/datasets/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,20 @@ def download(self) -> None:

# download files
for filename, md5 in self.resources:
errors = []
for mirror in self.mirrors:
url = f"{mirror}{filename}"
try:
print(f"Downloading {url}")
download_and_extract_archive(url, download_root=self.raw_folder, filename=filename, md5=md5)
except URLError as error:
print(f"Failed to download (trying next):\n{error}")
except URLError as e:
errors.append(e)
continue
finally:
print()
break
else:
raise RuntimeError(f"Error downloading {filename}")
s = f"Error downloading {filename}:\n"
for mirror, err in zip(self.mirrors, errors):
s += f"Tried {mirror}, got:\n{str(err)}\n"
raise RuntimeError(s)

def extra_repr(self) -> str:
split = "Train" if self.train is True else "Test"
Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/omniglot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def _check_integrity(self) -> bool:

def download(self) -> None:
if self._check_integrity():
print("Files already downloaded and verified")
return

filename = self._get_target_folder()
Expand Down
4 changes: 0 additions & 4 deletions torchvision/datasets/phototour.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def _check_downloaded(self) -> bool:

def download(self) -> None:
if self._check_datafile_exists():
print(f"# Found cached data {self.data_file}")
return

if not self._check_downloaded():
Expand All @@ -157,8 +156,6 @@ def download(self) -> None:

download_url(url, self.root, filename, md5)

print(f"# Extracting data {self.data_down}\n")

import zipfile

with zipfile.ZipFile(fpath, "r") as z:
Expand All @@ -168,7 +165,6 @@ def download(self) -> None:

def cache(self) -> None:
# process and save as torch files
print(f"# Caching data {self.data_file}")

dataset = (
read_image_file(self.data_dir, self.image_ext, self.lens[self.name]),
Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/sbu.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def download(self) -> None:
"""Download and extract the tarball, and download each individual photo."""

if self._check_integrity():
print("Files already downloaded and verified")
return

download_and_extract_archive(self.url, self.root, self.root, self.filename, self.md5_checksum)
Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/semeion.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def _check_integrity(self) -> bool:

def download(self) -> None:
if self._check_integrity():
print("Files already downloaded and verified")
return

root = self.root
Expand Down
9 changes: 7 additions & 2 deletions torchvision/datasets/stanford_cars.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class StanfordCars(VisionDataset):
has been split roughly in a 50-50 split
The original URL is https://ai.stanford.edu/~jkrause/cars/car_dataset.html, but it is broken.
Follow the instructions in ``download`` argument to obtain and use the dataset offline.
.. note::
Expand All @@ -29,8 +30,12 @@ class StanfordCars(VisionDataset):
target and transforms it.
download (bool, optional): This parameter exists for backward compatibility but it does not
download the dataset, since the original URL is not available anymore. The dataset
seems to be available on Kaggle so you can try to manually download it using
`these instructions <https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616>`_.
seems to be available on Kaggle so you can try to manually download and configure it using
`these instructions <https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616>`_,
or use an integrated
`dataset on Kaggle <https://github.com/pytorch/vision/issues/7545#issuecomment-2282674373>`_.
In both cases, first download and configure the dataset locally, and use the dataset with
``"download=False"``.
"""

def __init__(
Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/stl10.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def _check_integrity(self) -> bool:

def download(self) -> None:
if self._check_integrity():
print("Files already downloaded and verified")
return
download_and_extract_archive(self.url, self.root, filename=self.filename, md5=self.tgz_md5)
self._check_integrity()
Expand Down
5 changes: 0 additions & 5 deletions torchvision/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def download_url(

# check if file is already present locally
if check_integrity(fpath, md5):
print("Using downloaded and verified file: " + fpath)
return

if _is_remote_location_available():
Expand All @@ -128,12 +127,10 @@ def download_url(

# download the file
try:
print("Downloading " + url + " to " + fpath)
_urlretrieve(url, fpath)
except (urllib.error.URLError, OSError) as e: # type: ignore[attr-defined]
if url[:5] == "https":
url = url.replace("https:", "http:")
print("Failed download. Trying https -> http instead. Downloading " + url + " to " + fpath)
_urlretrieve(url, fpath)
else:
raise e
Expand Down Expand Up @@ -208,7 +205,6 @@ def download_file_from_google_drive(
os.makedirs(root, exist_ok=True)

if check_integrity(fpath, md5):
print(f"Using downloaded {'and verified ' if md5 else ''}file: {fpath}")
return

gdown.download(id=file_id, output=fpath, quiet=False, user_agent=USER_AGENT)
Expand Down Expand Up @@ -399,7 +395,6 @@ def download_and_extract_archive(
download_url(url, download_root, filename, md5)

archive = os.path.join(download_root, filename)
print(f"Extracting {archive} to {extract_root}")
extract_archive(archive, extract_root, remove_finished)


Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/widerface.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def _check_integrity(self) -> bool:

def download(self) -> None:
if self._check_integrity():
print("Files already downloaded and verified")
return

# download and extract image data
Expand Down
24 changes: 21 additions & 3 deletions torchvision/io/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ def write_video(
audio_options: Optional[Dict[str, Any]] = None,
) -> None:
"""
Writes a 4d tensor in [T, H, W, C] format in a video file
Writes a 4d tensor in [T, H, W, C] format in a video file.
This function relies on PyAV (therefore, ultimately FFmpeg) to encode
videos, you can get more fine-grained control by referring to the other
options at your disposal within `the FFMpeg wiki
<http://trac.ffmpeg.org/wiki#Encoding>`_.
.. warning::
Expand All @@ -78,12 +83,25 @@ def write_video(
as a uint8 tensor in [T, H, W, C] format
fps (Number): video frames per second
video_codec (str): the name of the video codec, i.e. "libx264", "h264", etc.
options (Dict): dictionary containing options to be passed into the PyAV video stream
options (Dict): dictionary containing options to be passed into the PyAV video stream.
The list of options is codec-dependent and can all
be found from `the FFMpeg wiki <http://trac.ffmpeg.org/wiki#Encoding>`_.
audio_array (Tensor[C, N]): tensor containing the audio, where C is the number of channels
and N is the number of samples
audio_fps (Number): audio sample rate, typically 44100 or 48000
audio_codec (str): the name of the audio codec, i.e. "mp3", "aac", etc.
audio_options (Dict): dictionary containing options to be passed into the PyAV audio stream
audio_options (Dict): dictionary containing options to be passed into the PyAV audio stream.
The list of options is codec-dependent and can all
be found from `the FFMpeg wiki <http://trac.ffmpeg.org/wiki#Encoding>`_.
Examples::
>>> # Creating libx264 video with CRF 17, for visually lossless footage:
>>>
>>> from torchvision.io import write_video
>>> # 1000 frames of 100x100, 3-channel image.
>>> vid = torch.randn(1000, 100, 100, 3, dtype = torch.uint8)
>>> write_video("video.mp4", options = {"crf": "17"})
"""
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
_log_api_usage_once(write_video)
Expand Down
2 changes: 1 addition & 1 deletion torchvision/transforms/_functional_pil.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def adjust_hue(img: Image.Image, hue_factor: float) -> Image.Image:

np_h = np.array(h, dtype=np.uint8)
# This will over/underflow, as desired
np_h += np.array(hue_factor * 255).astype(np.uint8)
np_h += np.int32(hue_factor * 255).astype(np.uint8)

h = Image.fromarray(np_h, "L")

Expand Down

0 comments on commit a69e4ab

Please sign in to comment.