Skip to content

Commit 47e88d4

Browse files
committed
Merge branch 'please_dont_modify_this_branch_unless_you_are_just_merging_with_main__' of github.com:nicolashug/vision into please_dont_modify_this_branch_unless_you_are_just_merging_with_main__
2 parents 3d454bd + a06ed26 commit 47e88d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1147
-285
lines changed

.github/scripts/setup-env.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ echo '::endgroup::'
100100

101101
echo '::group::Install torchvision-extra-decoders'
102102
# This can be done after torchvision was built
103-
pip install torchvision-extra-decoders
103+
if [[ "$(uname)" == "Linux" && "$(uname -m)" != "aarch64" ]]; then
104+
extra_decoders_channel="--pre --index-url https://download.pytorch.org/whl/nightly/cpu"
105+
else
106+
extra_decoders_channel=""
107+
fi
108+
109+
pip install torchvision-extra-decoders $extra_decoders_channel
104110
echo '::endgroup::'
105111

106112
echo '::group::Collect environment information'

.github/scripts/unittest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ echo '::endgroup::'
1515
python test/smoke_test.py
1616

1717
# We explicitly ignore the video tests until we resolve https://github.com/pytorch/vision/issues/8162
18-
pytest --ignore-glob="*test_video*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25
18+
pytest --ignore-glob="*test_video*" --ignore-glob="*test_onnx*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 -k "not TestFxFeatureExtraction"

.github/workflows/tests.yml

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ jobs:
5252
python-version:
5353
- "3.9"
5454
- "3.10"
55-
- "3.11"
55+
# TODO put back 3.11 (See blame)
56+
# - "3.11"
5657
- "3.12"
5758
runner: ["macos-m1-stable"]
5859
fail-fast: false
@@ -81,11 +82,12 @@ jobs:
8182
- "3.12"
8283
runner: ["windows.4xlarge"]
8384
gpu-arch-type: ["cpu"]
84-
include:
85-
- python-version: "3.9"
86-
runner: windows.g5.4xlarge.nvidia.gpu
87-
gpu-arch-type: cuda
88-
gpu-arch-version: "11.8"
85+
# TODO: put GPU testing back
86+
# include:
87+
# - python-version: "3.9"
88+
# runner: windows.g5.4xlarge.nvidia.gpu
89+
# gpu-arch-type: cuda
90+
# gpu-arch-version: "11.8"
8991
fail-fast: false
9092
uses: pytorch/test-infra/.github/workflows/windows_job.yml@main
9193
permissions:
@@ -109,39 +111,39 @@ jobs:
109111
110112
./.github/scripts/unittest.sh
111113
112-
onnx:
113-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
114-
permissions:
115-
id-token: write
116-
contents: read
117-
with:
118-
repository: pytorch/vision
119-
test-infra-ref: main
120-
script: |
121-
set -euo pipefail
122-
123-
export PYTHON_VERSION=3.10
124-
export GPU_ARCH_TYPE=cpu
125-
export GPU_ARCH_VERSION=''
126-
127-
./.github/scripts/setup-env.sh
128-
129-
# Prepare conda
130-
CONDA_PATH=$(which conda)
131-
eval "$(${CONDA_PATH} shell.bash hook)"
132-
conda activate ci
133-
134-
echo '::group::Install ONNX'
135-
pip install --progress-bar=off onnx onnxruntime
136-
echo '::endgroup::'
137-
138-
echo '::group::Install testing utilities'
139-
pip install --progress-bar=off pytest "numpy<2"
140-
echo '::endgroup::'
141-
142-
echo '::group::Run ONNX tests'
143-
pytest --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 test/test_onnx.py
144-
echo '::endgroup::'
114+
# onnx:
115+
# uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
116+
# permissions:
117+
# id-token: write
118+
# contents: read
119+
# with:
120+
# repository: pytorch/vision
121+
# test-infra-ref: main
122+
# script: |
123+
# set -euo pipefail
124+
125+
# export PYTHON_VERSION=3.10
126+
# export GPU_ARCH_TYPE=cpu
127+
# export GPU_ARCH_VERSION=''
128+
129+
# ./.github/scripts/setup-env.sh
130+
131+
# # Prepare conda
132+
# CONDA_PATH=$(which conda)
133+
# eval "$(${CONDA_PATH} shell.bash hook)"
134+
# conda activate ci
135+
136+
# echo '::group::Install ONNX'
137+
# pip install --progress-bar=off onnx onnxruntime
138+
# echo '::endgroup::'
139+
140+
# echo '::group::Install testing utilities'
141+
# pip install --progress-bar=off pytest "numpy<2"
142+
# echo '::endgroup::'
143+
144+
# echo '::group::Run ONNX tests'
145+
# pytest --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 test/test_onnx.py
146+
# echo '::endgroup::'
145147

146148
unittests-extended:
147149
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main

packaging/post_build_script.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash
22
LD_LIBRARY_PATH="/usr/local/lib:$CUDA_HOME/lib64:$LD_LIBRARY_PATH" python packaging/wheel/relocate.py
33

4-
pip install torchvision-extra-decoders
4+
if [[ "$(uname)" == "Linux" && "$(uname -m)" != "aarch64" ]]; then
5+
extra_decoders_channel="--pre --index-url https://download.pytorch.org/whl/nightly/cpu"
6+
else
7+
extra_decoders_channel=""
8+
fi
9+
10+
pip install torchvision-extra-decoders $extra_decoders_channel

packaging/pre_build_script.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ if [[ "$(uname)" == Darwin ]]; then
99
brew uninstall --ignore-dependencies --force $pkg || true
1010
done
1111

12-
conda install -yq wget
12+
conda install -y wget
1313
fi
1414

1515
if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
16-
conda install libpng libwebp -yq
16+
conda install libpng libwebp -y
1717
# Installing webp also installs a non-turbo jpeg, so we uninstall jpeg stuff
1818
# before re-installing them
1919
conda uninstall libjpeg-turbo libjpeg -y
20-
conda install -yq ffmpeg=4.2 libjpeg-turbo -c pytorch
20+
conda install -y ffmpeg=4.2 -c pytorch
21+
conda install -y libjpeg-turbo -c pytorch
2122

2223
# Copy binaries to be included in the wheel distribution
2324
if [[ "$OSTYPE" == "msys" ]]; then
@@ -28,11 +29,11 @@ if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
2829
else
2930

3031
if [[ "$ARCH" == "aarch64" ]]; then
31-
conda install libpng -yq
32-
conda install -yq ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly
32+
conda install libpng -y
33+
conda install -y ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly
3334
fi
3435

35-
conda install libwebp -yq
36+
conda install libwebp -y
3637
conda install libjpeg-turbo -c pytorch
3738
yum install -y freetype gnutls
3839
pip install auditwheel

release/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Vision Release Scripts
2+
3+
This folder contains script(s) used for releasing new versions of the Vision package

release/apply-release-changes.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python3
2+
"""
3+
apply-release-changes.py - Cross-platform script to replace main with a specified release version in YML files
4+
5+
This script performs two replacements in YML files in .github/workflows/:
6+
1. Replaces @main with @release/VERSION
7+
2. Replaces 'test-infra-ref: main' with 'test-infra-ref: release/VERSION'
8+
9+
Usage:
10+
python apply-release-changes.py VERSION
11+
12+
Example:
13+
python apply-release-changes.py 2.7
14+
"""
15+
16+
import os
17+
import pathlib
18+
import sys
19+
from typing import Optional
20+
21+
22+
def replace_in_file(file_path: pathlib.Path, old_text: str, new_text: str) -> None:
23+
"""Replace all occurrences of old_text with new_text in the specified file."""
24+
try:
25+
# Try reading the file without specifying encoding to use the default
26+
encoding = None
27+
try:
28+
content = file_path.read_text()
29+
except UnicodeDecodeError:
30+
# If that fails, try with UTF-8
31+
encoding = "utf-8"
32+
content = file_path.read_text(encoding=encoding)
33+
34+
# Perform the replacement
35+
new_content = content.replace(old_text, new_text)
36+
37+
# Only write if changes were made
38+
if new_content != content:
39+
# Write with the same encoding we used to read
40+
if encoding:
41+
file_path.write_text(new_content, encoding=encoding)
42+
else:
43+
file_path.write_text(new_content)
44+
print(f"Updated: {file_path}")
45+
46+
except Exception as e:
47+
print(f"Error processing {file_path}: {e}")
48+
49+
50+
def find_repo_root() -> Optional[pathlib.Path]:
51+
"""Find the git repository root by searching for .git directory."""
52+
# Start from the current directory and traverse upwards
53+
current_path = pathlib.Path.cwd().absolute()
54+
55+
while current_path != current_path.parent:
56+
# Check if .git directory exists
57+
git_dir = current_path / ".git"
58+
if git_dir.exists() and git_dir.is_dir():
59+
return current_path
60+
61+
# Move up one directory
62+
current_path = current_path.parent
63+
64+
# If we get here, we didn't find a repository root
65+
return None
66+
67+
68+
def main() -> None:
69+
# Check if version is provided as command line argument
70+
if len(sys.argv) != 2:
71+
print("Error: Exactly one version parameter is required")
72+
print(f"Usage: python {os.path.basename(__file__)} VERSION")
73+
print("Example: python apply-release-changes.py 2.7")
74+
sys.exit(1)
75+
76+
# Get version from command line argument
77+
version = sys.argv[1]
78+
print(f"Using release version: {version}")
79+
80+
# Find the repository root by searching for .git directory
81+
repo_root = find_repo_root()
82+
if not repo_root:
83+
print("Error: Not inside a git repository. Please run from within a git repository.")
84+
sys.exit(1)
85+
86+
print(f"Repository root found at: {repo_root}")
87+
88+
# Get path to workflow directory
89+
workflow_dir = repo_root / ".github" / "workflows"
90+
91+
# Process all workflow files and perform both replacements on each file
92+
for yml_file in workflow_dir.glob("*.yml"):
93+
replace_in_file(yml_file, "@main", f"@release/{version}")
94+
replace_in_file(yml_file, "test-infra-ref: main", f"test-infra-ref: release/{version}")
95+
96+
97+
if __name__ == "__main__":
98+
print("Starting YML updates...")
99+
main()
100+
print("YML updates completed.")

setup.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import distutils.spawn
33
import glob
44
import os
5+
import shlex
56
import shutil
67
import subprocess
78
import sys
@@ -79,7 +80,7 @@ def get_version():
7980

8081
def write_version_file(version, sha):
8182
# Exists for BC, probably completely useless.
82-
with open(ROOT_DIR / "torchvision/version.py", "w") as f:
83+
with open(ROOT_DIR / "torchvision" / "version.py", "w") as f:
8384
f.write(f"__version__ = '{version}'\n")
8485
f.write(f"git_version = {repr(sha)}\n")
8586
f.write("from torchvision.extension import _check_cuda_version\n")
@@ -95,8 +96,14 @@ def get_dist(pkgname):
9596
return None
9697

9798
pytorch_dep = os.getenv("TORCH_PACKAGE_NAME", "torch")
98-
if os.getenv("PYTORCH_VERSION"):
99-
pytorch_dep += "==" + os.getenv("PYTORCH_VERSION")
99+
if version_pin := os.getenv("PYTORCH_VERSION"):
100+
pytorch_dep += "==" + version_pin
101+
elif (version_pin_ge := os.getenv("PYTORCH_VERSION_GE")) and (version_pin_lt := os.getenv("PYTORCH_VERSION_LT")):
102+
# This branch and the associated env vars exist to help third-party
103+
# builds like in https://github.com/pytorch/vision/pull/8936. This is
104+
# supported on a best-effort basis, we don't guarantee that this won't
105+
# eventually break (and we don't test it.)
106+
pytorch_dep += f">={version_pin_ge},<{version_pin_lt}"
100107

101108
requirements = [
102109
"numpy",
@@ -123,7 +130,7 @@ def get_macros_and_flags():
123130
if NVCC_FLAGS is None:
124131
nvcc_flags = []
125132
else:
126-
nvcc_flags = NVCC_FLAGS.split(" ")
133+
nvcc_flags = shlex.split(NVCC_FLAGS)
127134
extra_compile_args["nvcc"] = nvcc_flags
128135

129136
if sys.platform == "win32":
@@ -194,7 +201,7 @@ def make_C_extension():
194201

195202
def find_libpng():
196203
# Returns (found, include dir, library dir, library name)
197-
if sys.platform in ("linux", "darwin"):
204+
if sys.platform in ("linux", "darwin", "aix"):
198205
libpng_config = shutil.which("libpng-config")
199206
if libpng_config is None:
200207
warnings.warn("libpng-config not found")

test/common_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ def sample_position(values, max_value):
423423
h, w = [torch.randint(1, s, (num_boxes,)) for s in canvas_size]
424424
y = sample_position(h, canvas_size[0])
425425
x = sample_position(w, canvas_size[1])
426+
r = -360 * torch.rand((num_boxes,)) + 180
426427

427428
if format is tv_tensors.BoundingBoxFormat.XYWH:
428429
parts = (x, y, w, h)
@@ -435,6 +436,23 @@ def sample_position(values, max_value):
435436
cx = x + w / 2
436437
cy = y + h / 2
437438
parts = (cx, cy, w, h)
439+
elif format is tv_tensors.BoundingBoxFormat.XYWHR:
440+
parts = (x, y, w, h, r)
441+
elif format is tv_tensors.BoundingBoxFormat.CXCYWHR:
442+
cx = x + w / 2
443+
cy = y + h / 2
444+
parts = (cx, cy, w, h, r)
445+
elif format is tv_tensors.BoundingBoxFormat.XYXYXYXY:
446+
r_rad = r * torch.pi / 180.0
447+
cos, sin = torch.cos(r_rad), torch.sin(r_rad)
448+
x1, y1 = x, y
449+
x3 = x1 + w * cos
450+
y3 = y1 - w * sin
451+
x2 = x3 + h * sin
452+
y2 = y3 + h * cos
453+
x4 = x1 + h * sin
454+
y4 = y1 + h * cos
455+
parts = (x1, y1, x3, y3, x2, y2, x4, y4)
438456
else:
439457
raise ValueError(f"Format {format} is not supported")
440458

0 commit comments

Comments
 (0)