Commit cc26cd81 authored by panning's avatar panning
Browse files

merge v0.16.0

parents f78f29f5 fbb4cc54
name: Build Linux Wheels
on:
pull_request:
push:
branches:
- nightly
- main
- release/*
tags:
# NOTE: Binary build pipelines should only get triggered on release candidate builds
# Release candidate tags look like: v1.11.0-rc1
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
workflow_dispatch:
jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@release/2.1
with:
package-type: wheel
os: linux
test-infra-repository: pytorch/test-infra
test-infra-ref: release/2.1
build:
needs: generate-matrix
strategy:
fail-fast: false
matrix:
include:
- repository: pytorch/vision
pre-script: packaging/pre_build_script.sh
post-script: packaging/post_build_script.sh
smoke-test-script: test/smoke_test.py
package-name: torchvision
name: ${{ matrix.repository }}
uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@release/2.1
with:
repository: ${{ matrix.repository }}
ref: ""
test-infra-repository: pytorch/test-infra
test-infra-ref: release/2.1
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
pre-script: ${{ matrix.pre-script }}
post-script: ${{ matrix.post-script }}
package-name: ${{ matrix.package-name }}
smoke-test-script: ${{ matrix.smoke-test-script }}
trigger-event: ${{ github.event_name }}
secrets:
AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID: ${{ secrets.AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID }}
AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY: ${{ secrets.AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY }}
name: Build M1 Wheels
on:
pull_request:
push:
branches:
- nightly
- main
- release/*
tags:
# NOTE: Binary build pipelines should only get triggered on release candidate builds
# Release candidate tags look like: v1.11.0-rc1
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
workflow_dispatch:
jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@release/2.1
with:
package-type: wheel
os: macos-arm64
test-infra-repository: pytorch/test-infra
test-infra-ref: release/2.1
build:
needs: generate-matrix
strategy:
fail-fast: false
matrix:
include:
- repository: pytorch/vision
pre-script: packaging/pre_build_script.sh
post-script: packaging/post_build_script.sh
smoke-test-script: test/smoke_test.py
package-name: torchvision
name: ${{ matrix.repository }}
uses: pytorch/test-infra/.github/workflows/build_wheels_macos.yml@release/2.1
with:
repository: ${{ matrix.repository }}
ref: ""
test-infra-repository: pytorch/test-infra
test-infra-ref: release/2.1
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
pre-script: ${{ matrix.pre-script }}
post-script: ${{ matrix.post-script }}
package-name: ${{ matrix.package-name }}
runner-type: macos-m1-12
smoke-test-script: ${{ matrix.smoke-test-script }}
trigger-event: ${{ github.event_name }}
secrets:
AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID: ${{ secrets.AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID }}
AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY: ${{ secrets.AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY }}
name: Build Macos Wheels
on:
pull_request:
push:
branches:
- nightly
- main
- release/*
tags:
# NOTE: Binary build pipelines should only get triggered on release candidate builds
# Release candidate tags look like: v1.11.0-rc1
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
workflow_dispatch:
jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@release/2.1
with:
package-type: wheel
os: macos
test-infra-repository: pytorch/test-infra
test-infra-ref: release/2.1
build:
needs: generate-matrix
strategy:
fail-fast: false
matrix:
include:
- repository: pytorch/vision
pre-script: packaging/pre_build_script.sh
post-script: packaging/post_build_script.sh
smoke-test-script: test/smoke_test.py
package-name: torchvision
name: ${{ matrix.repository }}
uses: pytorch/test-infra/.github/workflows/build_wheels_macos.yml@release/2.1
with:
repository: ${{ matrix.repository }}
ref: ""
test-infra-repository: pytorch/test-infra
test-infra-ref: release/2.1
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
pre-script: ${{ matrix.pre-script }}
post-script: ${{ matrix.post-script }}
package-name: ${{ matrix.package-name }}
runner-type: macos-12
smoke-test-script: ${{ matrix.smoke-test-script }}
trigger-event: ${{ github.event_name }}
secrets:
AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID: ${{ secrets.AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID }}
AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY: ${{ secrets.AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY }}
name: Build Windows Wheels
on:
pull_request:
push:
branches:
- nightly
- main
- release/*
tags:
# NOTE: Binary build pipelines should only get triggered on release candidate builds
# Release candidate tags look like: v1.11.0-rc1
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
workflow_dispatch:
jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@release/2.1
with:
package-type: wheel
os: windows
test-infra-repository: pytorch/test-infra
test-infra-ref: release/2.1
build:
needs: generate-matrix
strategy:
fail-fast: false
matrix:
include:
- repository: pytorch/vision
pre-script: packaging/pre_build_script.sh
env-script: packaging/windows/internal/vc_env_helper.bat
post-script: "python packaging/wheel/relocate.py"
smoke-test-script: test/smoke_test.py
package-name: torchvision
name: ${{ matrix.repository }}
uses: pytorch/test-infra/.github/workflows/build_wheels_windows.yml@release/2.1
with:
repository: ${{ matrix.repository }}
ref: ""
test-infra-repository: pytorch/test-infra
test-infra-ref: release/2.1
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
pre-script: ${{ matrix.pre-script }}
env-script: ${{ matrix.env-script }}
post-script: ${{ matrix.post-script }}
package-name: ${{ matrix.package-name }}
smoke-test-script: ${{ matrix.smoke-test-script }}
trigger-event: ${{ github.event_name }}
secrets:
AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID: ${{ secrets.AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID }}
AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY: ${{ secrets.AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY }}
name: Docs
on:
pull_request:
push:
branches:
- nightly
- main
- release/*
tags:
- v[0-9]+.[0-9]+.[0-9]
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
workflow_dispatch:
jobs:
build:
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
with:
repository: pytorch/vision
upload-artifact: docs
script: |
set -euo pipefail
export PYTHON_VERSION=3.8
export GPU_ARCH_TYPE=cpu
export GPU_ARCH_VERSION=''
./.github/scripts/setup-env.sh
# Prepare conda
CONDA_PATH=$(which conda)
eval "$(${CONDA_PATH} shell.bash hook)"
conda activate ci
# FIXME: not sure why we need this. `ldd torchvision/video_reader.so` shows that it
# already links against the one pulled from conda. However, at runtime it pulls from
# /lib64
# Should we maybe always do this in `./.github/scripts/setup-env.sh` so that we don't
# have to pay attention in all other workflows?
export LD_LIBRARY_PATH="${CONDA_PREFIX}/lib:${LD_LIBRARY_PATH}"
cd docs
echo '::group::Install doc requirements'
pip install --progress-bar=off -r requirements.txt
echo '::endgroup::'
if [[ ${{ github.event_name }} == push && (${{ github.ref_type }} == tag || (${{ github.ref_type }} == branch && ${{ github.ref_name }} == release/*)) ]]; then
echo '::group::Enable version string sanitization'
# This environment variable just has to exist and must not be empty. The actual value is arbitrary.
# See docs/source/conf.py for details
export TORCHVISION_SANITIZE_VERSION_STR_IN_DOCS=1
echo '::endgroup::'
fi
# The runner does not have sufficient memory to run with as many processes as there are
# cores (`-j auto`). Thus, we limit to a single process (`-j 1`) here.
sed -i -e 's/-j auto/-j 1/' Makefile
make html
# Below is an imperfect way for us to add "try on collab" links to all of our gallery examples.
# sphinx-gallery will convert all gallery examples to .ipynb notebooks and stores them in
# build/html/_downloads/<some_hash>/<example_name>.ipynb
# We copy all those ipynb files in a more convenient folder so that we can more easily link to them.
mkdir build/html/_generated_ipynb_notebooks
for file in `find build/html/_downloads`; do
if [[ $file == *.ipynb ]]; then
cp $file build/html/_generated_ipynb_notebooks/
fi
done
cp -r build/html "${RUNNER_ARTIFACT_DIR}"
# On PRs we also want to upload the docs into our S3 bucket for preview.
if [[ ${{ github.event_name == 'pull_request' }} ]]; then
cp -r build/html/* "${RUNNER_DOCS_DIR}"
fi
upload:
needs: build
if: github.repository == 'pytorch/vision' && github.event_name == 'push' &&
((github.ref_type == 'branch' && github.ref_name == 'main') || github.ref_type == 'tag')
permissions:
contents: write
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
with:
repository: pytorch/vision
download-artifact: docs
ref: gh-pages
script: |
set -euo pipefail
REF_TYPE=${{ github.ref_type }}
REF_NAME=${{ github.ref_name }}
if [[ "${REF_TYPE}" == branch ]]; then
TARGET_FOLDER="${REF_NAME}"
elif [[ "${REF_TYPE}" == tag ]]; then
case "${REF_NAME}" in
*-rc*)
echo "Aborting upload since this is an RC tag: ${REF_NAME}"
exit 0
;;
*)
# Strip the leading "v" as well as the trailing patch version. For example:
# 'v0.15.2' -> '0.15'
TARGET_FOLDER=$(echo "${REF_NAME}" | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.[0-9]\+/\1.\2/')
;;
esac
fi
echo "Target Folder: ${TARGET_FOLDER}"
mkdir -p "${TARGET_FOLDER}"
rm -rf "${TARGET_FOLDER}"/*
mv "${RUNNER_ARTIFACT_DIR}"/html/* "${TARGET_FOLDER}"
git add "${TARGET_FOLDER}" || true
if [[ "${TARGET_FOLDER}" == main ]]; then
mkdir -p _static
rm -rf _static/*
cp -r "${TARGET_FOLDER}"/_static/* _static
git add _static || true
fi
git config user.name 'pytorchbot'
git config user.email 'soumith+bot@pytorch.org'
git config http.postBuffer 524288000
git commit -m "auto-generating sphinx docs" || true
git push
name: Lint
on:
pull_request:
push:
branches:
- nightly
- main
- release/*
workflow_dispatch:
jobs:
python-source-and-configs:
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
with:
repository: pytorch/vision
script: |
set -euo pipefail
echo '::group::Setup environment'
CONDA_PATH=$(which conda)
eval "$(${CONDA_PATH} shell.bash hook)"
conda create --name ci --quiet --yes python=3.8 pip
conda activate ci
echo '::endgroup::'
echo '::group::Install lint tools'
pip install --progress-bar=off pre-commit
echo '::endgroup::'
set +e
pre-commit run --all-files
if [ $? -ne 0 ]; then
git --no-pager diff
exit 1
fi
c-source:
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
with:
repository: pytorch/vision
script: |
set -euo pipefail
echo '::group::Setup environment'
CONDA_PATH=$(which conda)
eval "$(${CONDA_PATH} shell.bash hook)"
# clang-format needs some shared libraries that conflict with the system ones. Thus, we install them from conda
# and prepend the libraries to linker path to prioritize them. `ncurses=5` is only available on the conda-forge
# channel. Since we are not building or testing here, this is fine.
conda create --name ci --quiet --yes -c conda-forge python=3.8 ncurses=5 libgcc
conda activate ci
export LD_LIBRARY_PATH="${CONDA_PREFIX}/lib:${LD_LIBRARY_PATH}"
echo '::endgroup::'
echo '::group::Install lint tools'
curl https://oss-clang-format.s3.us-east-2.amazonaws.com/linux64/clang-format-linux64 -o ./clang-format
chmod +x ./clang-format
echo '::endgroup::'
echo '::group::Lint C source'
set +e
./.github/scripts/run-clang-format.py -r torchvision/csrc --clang-format-executable ./clang-format
if [ $? -ne 0 ]; then
git --no-pager diff
exit 1
fi
echo '::endgroup::'
python-types:
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
with:
repository: pytorch/vision
script: |
set -euo pipefail
export PYTHON_VERSION=3.8
export GPU_ARCH_TYPE=cpu
export GPU_ARCH_VERSION=''
./.github/scripts/setup-env.sh
CONDA_PATH=$(which conda)
eval "$(${CONDA_PATH} shell.bash hook)"
conda activate ci
echo '::group::Install lint tools'
pip install --progress-bar=off mypy
echo '::endgroup::'
echo '::group::Lint Python types'
mypy --install-types --non-interactive --config-file mypy.ini
echo '::endgroup::'
bc:
if: github.event.pull_request
runs-on: ubuntu-latest
steps:
- name: Run BC Lint Action
uses: pytorch/test-infra/.github/actions/bc-lint@release/2.1
with:
repo: ${{ github.event.pull_request.head.repo.full_name }}
base_sha: ${{ github.event.pull_request.base.sha }}
head_sha: ${{ github.event.pull_request.head.sha }}
name: Unit-tests on M1
on:
pull_request:
push:
branches:
- nightly
- main
- release/*
workflow_dispatch:
env:
CHANNEL: "nightly"
jobs:
tests:
name: "Unit-tests on M1"
runs-on: macos-m1-12
strategy:
matrix:
py_vers: [ "3.8"]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set Release CHANNEL (for release)
if: ${{ (github.event_name == 'pull_request' && startsWith(github.base_ref, 'release')) || startsWith(github.ref, 'refs/heads/release') }}
run: |
echo "CHANNEL=test" >> "$GITHUB_ENV"
- name: Install TorchVision
shell: arch -arch arm64 bash {0}
env:
ENV_NAME: conda-env-${{ github.run_id }}
PY_VERS: ${{ matrix.py_vers }}
run: |
. ~/miniconda3/etc/profile.d/conda.sh
# Needed for JPEG library detection as setup.py detects conda presence by running `shutil.which('conda')`
export PATH=~/miniconda3/bin:$PATH
set -ex
conda create -yp ${ENV_NAME} python=${PY_VERS} numpy libpng jpeg scipy
conda run -p ${ENV_NAME} python3 -mpip install --pre torch --extra-index-url=https://download.pytorch.org/whl/${CHANNEL}
conda run -p ${ENV_NAME} python3 setup.py develop
conda run -p ${ENV_NAME} python3 -mpip install pytest pytest-mock av
- name: Run tests
shell: arch -arch arm64 bash {0}
env:
ENV_NAME: conda-env-${{ github.run_id }}
PY_VERS: ${{ matrix.py_vers }}
run: |
. ~/miniconda3/etc/profile.d/conda.sh
set -ex
conda run -p ${ENV_NAME} --no-capture-output python3 -u -mpytest -v --tb=long --durations 20
conda env remove -p ${ENV_NAME}
...@@ -18,11 +18,14 @@ jobs: ...@@ -18,11 +18,14 @@ jobs:
- name: Set up python - name: Set up python
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:
python-version: 3.7 python-version: 3.8
- name: Upgrade system packages - name: Upgrade system packages
run: python -m pip install --upgrade pip setuptools wheel run: python -m pip install --upgrade pip setuptools wheel
- name: SSL
run: python -c 'import ssl; print(ssl.OPENSSL_VERSION)'
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
......
name: Tests
on:
pull_request:
push:
branches:
- nightly
- main
- release/*
workflow_dispatch:
jobs:
unittests-linux:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
runner: ["linux.12xlarge"]
gpu-arch-type: ["cpu"]
include:
- python-version: 3.8
runner: linux.g5.4xlarge.nvidia.gpu
gpu-arch-type: cuda
gpu-arch-version: "11.8"
fail-fast: false
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
with:
repository: pytorch/vision
runner: ${{ matrix.runner }}
gpu-arch-type: ${{ matrix.gpu-arch-type }}
gpu-arch-version: ${{ matrix.gpu-arch-version }}
timeout: 120
script: |
set -euo pipefail
export PYTHON_VERSION=${{ matrix.python-version }}
export GPU_ARCH_TYPE=${{ matrix.gpu-arch-type }}
export GPU_ARCH_VERSION=${{ matrix.gpu-arch-version }}
./.github/scripts/unittest.sh
unittests-macos:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
runner: ["macos-12"]
include:
- python-version: "3.8"
runner: macos-m1-12
fail-fast: false
uses: pytorch/test-infra/.github/workflows/macos_job.yml@release/2.1
with:
repository: pytorch/vision
# We need an increased timeout here, since the macos-12 runner is the free one from GH
# and needs roughly 2 hours to just run the test suite
timeout: 240
runner: ${{ matrix.runner }}
script: |
set -euo pipefail
export PYTHON_VERSION=${{ matrix.python-version }}
export GPU_ARCH_TYPE=cpu
export GPU_ARCH_VERSION=''
./.github/scripts/unittest.sh
unittests-windows:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
runner: ["windows.4xlarge"]
gpu-arch-type: ["cpu"]
include:
- python-version: "3.8"
runner: windows.g5.4xlarge.nvidia.gpu
gpu-arch-type: cuda
gpu-arch-version: "11.8"
fail-fast: false
uses: pytorch/test-infra/.github/workflows/windows_job.yml@release/2.1
with:
repository: pytorch/vision
runner: ${{ matrix.runner }}
gpu-arch-type: ${{ matrix.gpu-arch-type }}
gpu-arch-version: ${{ matrix.gpu-arch-version }}
timeout: 120
script: |
set -euxo pipefail
export PYTHON_VERSION=${{ matrix.python-version }}
export VC_YEAR=2019
export VSDEVCMD_ARGS=""
export GPU_ARCH_TYPE=${{ matrix.gpu-arch-type }}
export GPU_ARCH_VERSION=${{ matrix.gpu-arch-version }}
./.github/scripts/unittest.sh
onnx:
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
with:
repository: pytorch/vision
script: |
set -euo pipefail
export PYTHON_VERSION=3.8
export GPU_ARCH_TYPE=cpu
export GPU_ARCH_VERSION=''
./.github/scripts/setup-env.sh
# Prepare conda
CONDA_PATH=$(which conda)
eval "$(${CONDA_PATH} shell.bash hook)"
conda activate ci
echo '::group::Install ONNX'
pip install --progress-bar=off onnx onnxruntime
echo '::endgroup::'
echo '::group::Install testing utilities'
pip install --progress-bar=off pytest
echo '::endgroup::'
echo '::group::Run ONNX tests'
pytest --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 test/test_onnx.py
echo '::endgroup::'
unittests-extended:
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
with:
repository: pytorch/vision
script: |
set -euo pipefail
export PYTHON_VERSION=3.8
export GPU_ARCH_TYPE=cpu
export GPU_ARCH_VERSION=''
./.github/scripts/setup-env.sh
# Prepare conda
CONDA_PATH=$(which conda)
eval "$(${CONDA_PATH} shell.bash hook)"
conda activate ci
echo '::group::Pre-download model weights'
pip install --progress-bar=off aiohttp aiofiles tqdm
python scripts/download_model_urls.py
echo '::endgroup::'
echo '::group::Install testing utilities'
pip install --progress-bar=off pytest
echo '::endgroup::'
echo '::group::Run extended unittests'
export PYTORCH_TEST_WITH_EXTENDED=1
pytest --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 test/test_extended_*.py
echo '::endgroup::'
name: Update viable/strict
on:
pull_request:
paths:
- .github/workflows/update-viablestrict.yml
schedule:
- cron: 10,40 * * * *
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
do_update_viablestrict:
uses: pytorch/test-infra/.github/workflows/update-viablestrict.yml@release/2.1
with:
repository: pytorch/vision
required_checks: "Build Linux,Build M1,Build Macos,Build Windows,Tests,CMake,Lint,Docs"
secrets:
ROCKSET_API_KEY: ${{ secrets.ROCKSET_API_KEY }}
GITHUB_DEPLOY_KEY : ${{ secrets.VISION_GITHUB_DEPLOY_KEY }}
...@@ -6,19 +6,21 @@ repos: ...@@ -6,19 +6,21 @@ repos:
- id: check-toml - id: check-toml
- id: check-yaml - id: check-yaml
exclude: packaging/.* exclude: packaging/.*
args:
- --allow-multiple-documents
- id: mixed-line-ending - id: mixed-line-ending
args: [--fix=lf] args: [--fix=lf]
- id: end-of-file-fixer - id: end-of-file-fixer
- repo: https://github.com/omnilib/ufmt - repo: https://github.com/omnilib/ufmt
rev: v1.3.2 rev: v1.3.3
hooks: hooks:
- id: ufmt - id: ufmt
additional_dependencies: additional_dependencies:
- black == 22.3.0 - black == 22.3.0
- usort == 1.0.2 - usort == 1.0.2
- repo: https://gitlab.com/pycqa/flake8 - repo: https://github.com/PyCQA/flake8
rev: 5.0.4 rev: 5.0.4
hooks: hooks:
- id: flake8 - id: flake8
......
cff-version: 1.2.0
title: "TorchVision: PyTorch's Computer Vision library"
message: >-
If you find TorchVision useful in your work, please
consider citing the following BibTeX entry.
type: software
authors:
- given-names: TorchVision maintainers and contributors
url: "https://github.com/pytorch/vision"
license: "BSD-3-Clause"
date-released: "2016-11-06"
journal: "GitHub repository"
publisher: "GitHub"
key: "torchvision2016"
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.18)
project(torchvision) project(torchvision)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 17)
file(STRINGS version.txt TORCHVISION_VERSION) file(STRINGS version.txt TORCHVISION_VERSION)
option(WITH_CUDA "Enable CUDA support" OFF) option(WITH_CUDA "Enable CUDA support" OFF)
option(WITH_MPS "Enable MPS support" OFF)
option(WITH_PNG "Enable features requiring LibPNG." ON) option(WITH_PNG "Enable features requiring LibPNG." ON)
option(WITH_JPEG "Enable features requiring LibJPEG." ON) option(WITH_JPEG "Enable features requiring LibJPEG." ON)
option(USE_PYTHON "Link to Python when building" OFF) option(USE_PYTHON "Link to Python when building" OFF)
...@@ -13,11 +14,11 @@ if(WITH_CUDA) ...@@ -13,11 +14,11 @@ if(WITH_CUDA)
add_definitions(-D__CUDA_NO_HALF_OPERATORS__) add_definitions(-D__CUDA_NO_HALF_OPERATORS__)
add_definitions(-DWITH_CUDA) add_definitions(-DWITH_CUDA)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr") set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
# CUDA-11.x can not be compiled using C++14 standard on Windows endif()
string(REGEX MATCH "^[0-9]+" CUDA_MAJOR ${CMAKE_CUDA_COMPILER_VERSION})
if(${CUDA_MAJOR} GREATER 10 AND MSVC) if(WITH_MPS)
set(CMAKE_CXX_STANDARD 17) enable_language(OBJC OBJCXX)
endif() add_definitions(-DWITH_MPS)
endif() endif()
find_package(Torch REQUIRED) find_package(Torch REQUIRED)
...@@ -84,6 +85,9 @@ list(APPEND ALLOW_LISTED ${TVCPP} ${TVCPP}/io/image ${TVCPP}/io/image/cpu ${TVCP ...@@ -84,6 +85,9 @@ list(APPEND ALLOW_LISTED ${TVCPP} ${TVCPP}/io/image ${TVCPP}/io/image/cpu ${TVCP
if(WITH_CUDA) if(WITH_CUDA)
list(APPEND ALLOW_LISTED ${TVCPP}/ops/cuda ${TVCPP}/ops/autocast) list(APPEND ALLOW_LISTED ${TVCPP}/ops/cuda ${TVCPP}/ops/autocast)
endif() endif()
if(WITH_MPS)
list(APPEND ALLOW_LISTED ${TVCPP}/ops/mps)
endif()
FOREACH(DIR ${ALLOW_LISTED}) FOREACH(DIR ${ALLOW_LISTED})
file(GLOB ALL_SOURCES ${ALL_SOURCES} ${DIR}/*.*) file(GLOB ALL_SOURCES ${ALL_SOURCES} ${DIR}/*.*)
......
...@@ -4,22 +4,22 @@ We want to make contributing to this project as easy and transparent as possible ...@@ -4,22 +4,22 @@ We want to make contributing to this project as easy and transparent as possible
## TL;DR ## TL;DR
We appreciate all contributions. If you are interested in contributing to Torchvision, there are many ways to help out. We appreciate all contributions. If you are interested in contributing to Torchvision, there are many ways to help out.
Your contributions may fall into the following categories: Your contributions may fall into the following categories:
- It helps the project if you could - It helps the project if you could
- Report issues you're facing - Report issues you're facing
- Give a :+1: on issues that others reported and that are relevant to you - Give a :+1: on issues that others reported and that are relevant to you
- Answering queries on the issue tracker, investigating bugs are very valuable contributions to the project. - Answering queries on the issue tracker, investigating bugs are very valuable contributions to the project.
- You would like to improve the documentation. This is no less important than improving the library itself! - You would like to improve the documentation. This is no less important than improving the library itself!
If you find a typo in the documentation, do not hesitate to submit a GitHub pull request. If you find a typo in the documentation, do not hesitate to submit a GitHub pull request.
- If you would like to fix a bug - If you would like to fix a bug
- please pick one from the [list of open issues labelled as "help wanted"](https://github.com/pytorch/vision/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) - please pick one from the [list of open issues labelled as "help wanted"](https://github.com/pytorch/vision/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)
- comment on the issue that you want to work on this issue - comment on the issue that you want to work on this issue
- send a PR with your fix, see below. - send a PR with your fix, see below.
- If you plan to contribute new features, utility functions or extensions, please first open an issue and discuss the feature with us. - If you plan to contribute new features, utility functions or extensions, please first open an issue and discuss the feature with us.
...@@ -30,30 +30,49 @@ clear and has sufficient instructions to be able to reproduce the issue. ...@@ -30,30 +30,49 @@ clear and has sufficient instructions to be able to reproduce the issue.
## Development installation ## Development installation
### Install PyTorch Nightly
### Dependencies
Start by installing the **nightly** build of PyTorch following the [official
instructions](https://pytorch.org/get-started/locally/).
**Optionally**, install `libpng` and `libjpeg-turbo` if you want to enable
support for
native encoding / decoding of PNG and JPEG formats in
[torchvision.io](https://pytorch.org/vision/stable/io.html#image):
```bash ```bash
conda install pytorch -c pytorch-nightly conda install libpng libjpeg-turbo -c pytorch
# or with pip (see https://pytorch.org/get-started/locally/)
# pip install numpy
# pip install --pre torch -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html
``` ```
### Install Torchvision Note: you can use the `TORCHVISION_INCLUDE` and `TORCHVISION_LIBRARY`
environment variables to tell the build system where to find those libraries if
they are in specific locations. Take a look at
[setup.py](https://github.com/pytorch/vision/blob/main/setup.py) for more
details.
### Clone and install torchvision
```bash ```bash
git clone https://github.com/pytorch/vision.git git clone https://github.com/pytorch/vision.git
cd vision cd vision
python setup.py develop python setup.py develop # use install instead of develop if you don't care about development.
# or, for OSX # or, for OSX
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py develop # MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py develop
# for C++ debugging, please use DEBUG=1 # for C++ debugging, use DEBUG=1
# DEBUG=1 python setup.py develop # DEBUG=1 python setup.py develop
pip install flake8 typing mypy pytest pytest-mock scipy
``` ```
You may also have to install `libpng-dev` and `libjpeg-turbo8-dev` libraries:
```bash By default, GPU support is built if CUDA is found and `torch.cuda.is_available()` is true. It's possible to force
conda install libpng jpeg building GPU support by setting `FORCE_CUDA=1` environment variable, which is useful when building a docker image.
We don't officially support building from source using `pip`, but _if_ you do, you'll need to use the
`--no-build-isolation` flag.
Other development dependencies include:
```
pip install flake8 typing mypy pytest pytest-mock scipy
``` ```
## Development Process ## Development Process
...@@ -66,12 +85,12 @@ If you plan to modify the code or documentation, please follow the steps below: ...@@ -66,12 +85,12 @@ If you plan to modify the code or documentation, please follow the steps below:
4. Ensure the test suite passes. 4. Ensure the test suite passes.
5. Make sure your code passes the formatting checks (see below). 5. Make sure your code passes the formatting checks (see below).
For more details about pull requests, For more details about pull requests,
please read [GitHub's guides](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request). please read [GitHub's guides](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request).
If you would like to contribute a new model, please see [here](#New-model). If you would like to contribute a new model, please see [here](#New-architecture-or-improved-model-weights).
If you would like to contribute a new dataset, please see [here](#New-dataset). If you would like to contribute a new dataset, please see [here](#New-dataset).
### Code formatting and typing ### Code formatting and typing
...@@ -83,7 +102,7 @@ Instead of relying directly on `black` however, we rely on ...@@ -83,7 +102,7 @@ Instead of relying directly on `black` however, we rely on
[ufmt](https://github.com/omnilib/ufmt), for compatibility reasons with Facebook [ufmt](https://github.com/omnilib/ufmt), for compatibility reasons with Facebook
internal infrastructure. internal infrastructure.
To format your code, install `ufmt` with `pip install ufmt==1.3.2 black==22.3.0 usort==1.0.2` and use e.g.: To format your code, install `ufmt` with `pip install ufmt==1.3.3 black==22.3.0 usort==1.0.2` and use e.g.:
```bash ```bash
ufmt format torchvision ufmt format torchvision
...@@ -126,8 +145,8 @@ mypy --config-file mypy.ini ...@@ -126,8 +145,8 @@ mypy --config-file mypy.ini
### Unit tests ### Unit tests
If you have modified the code by adding a new feature or a bug-fix, please add unit tests for that. To run a specific If you have modified the code by adding a new feature or a bug-fix, please add unit tests for that. To run a specific
test: test:
```bash ```bash
pytest test/<test-module.py> -vvv -k <test_myfunc> pytest test/<test-module.py> -vvv -k <test_myfunc>
# e.g. pytest test/test_transforms.py -vvv -k test_center_crop # e.g. pytest test/test_transforms.py -vvv -k test_center_crop
...@@ -136,7 +155,7 @@ pytest test/<test-module.py> -vvv -k <test_myfunc> ...@@ -136,7 +155,7 @@ pytest test/<test-module.py> -vvv -k <test_myfunc>
If you would like to run all tests: If you would like to run all tests:
```bash ```bash
pytest test -vvv pytest test -vvv
``` ```
Tests that require internet access should be in Tests that require internet access should be in
`test/test_internet.py`. `test/test_internet.py`.
...@@ -189,18 +208,18 @@ with "transforms" in their name. ...@@ -189,18 +208,18 @@ with "transforms" in their name.
### New architecture or improved model weights ### New architecture or improved model weights
Please refer to the guidelines in [Contributing to Torchvision - Models](https://github.com/pytorch/vision/blob/main/CONTRIBUTING_MODELS.md). Please refer to the guidelines in [Contributing to Torchvision - Models](https://github.com/pytorch/vision/blob/main/CONTRIBUTING_MODELS.md).
### New dataset ### New dataset
More details on how to add a new dataset will be provided later. Please, do not send any PR with a new dataset without discussing Please, do not send any PR with a new dataset without discussing
it in an issue as, most likely, it will not be accepted. it in an issue as, most likely, it will not be accepted.
### Pull Request ### Pull Request
If all previous checks (flake8, mypy, unit tests) are passing, please send a PR. Submitted PR will pass other tests on If all previous checks (flake8, mypy, unit tests) are passing, please send a PR. Submitted PR will pass other tests on
different operation systems, python versions and hardwares. different operating systems, python versions and hardware.
For more details about pull requests workflow, For more details about pull requests workflow,
please read [GitHub's guides](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request). please read [GitHub's guides](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request).
## License ## License
......
...@@ -20,13 +20,13 @@ So, before starting any work and submitting a PR there are a few critical things ...@@ -20,13 +20,13 @@ So, before starting any work and submitting a PR there are a few critical things
### 1. Preparation work ### 1. Preparation work
- Start by looking into this [issue](https://github.com/pytorch/vision/issues/2707) in order to have an idea of the models that are being considered, express your willingness to add a new model and discuss with the community whether or not this model should be included in TorchVision. It is very important at this stage to make sure that there is an agreement on the value of having this model in TorchVision and there is no one else already working on it. - Start by looking into this [issue](https://github.com/pytorch/vision/issues/2707) in order to have an idea of the models that are being considered, express your willingness to add a new model and discuss with the community whether this model should be included in TorchVision. It is very important at this stage to make sure that there is an agreement on the value of having this model in TorchVision and there is no one else already working on it.
- If the decision is to include the new model, then please create a new ticket which will be used for all design and implementation discussions prior to the PR. One of the TorchVision maintainers will reach out at this stage and this will be your POC from this point onwards in order to provide support, guidance and regular feedback. - If the decision is to include the new model, then please create a new ticket which will be used for all design and implementation discussions prior to the PR. One of the TorchVision maintainers will reach out at this stage and this will be your POC from this point onwards in order to provide support, guidance and regular feedback.
### 2. Implement the model ### 2. Implement the model
Please take a look at existing models in TorchVision to get familiar with the idioms. Also please look at recent contributions for new models. If in doubt about any design decisions you can ask for feedback on the issue created in step 1. Example of things to take into account: Please take a look at existing models in TorchVision to get familiar with the idioms. Also, please look at recent contributions for new models. If in doubt about any design decisions you can ask for feedback on the issue created in step 1. Example of things to take into account:
- The implementation should be as close as possible to the canonical implementation/paper - The implementation should be as close as possible to the canonical implementation/paper
- The PR must include the code implementation, documentation and tests - The PR must include the code implementation, documentation and tests
...@@ -34,7 +34,7 @@ Please take a look at existing models in TorchVision to get familiar with the id ...@@ -34,7 +34,7 @@ Please take a look at existing models in TorchVision to get familiar with the id
- The weights need to reproduce closely the results of the paper in terms of accuracy, even though the final weights to be deployed will be those trained by the TorchVision maintainers - The weights need to reproduce closely the results of the paper in terms of accuracy, even though the final weights to be deployed will be those trained by the TorchVision maintainers
- The PR description should include commands/configuration used to train the model, so that the TorchVision maintainers can easily run them to verify the implementation and generate the final model to be released - The PR description should include commands/configuration used to train the model, so that the TorchVision maintainers can easily run them to verify the implementation and generate the final model to be released
- Make sure we re-use existing components as much as possible (inheritance) - Make sure we re-use existing components as much as possible (inheritance)
- New primitives (transforms, losses, etc) can be added if necessary, but the final location will be determined after discussion with the dedicated maintainer - New primitives (transforms, losses, etc.) can be added if necessary, but the final location will be determined after discussion with the dedicated maintainer
- Please take a look at the detailed [implementation and documentation guidelines](https://github.com/pytorch/vision/issues/5319) for a fine grain list of things not to be missed - Please take a look at the detailed [implementation and documentation guidelines](https://github.com/pytorch/vision/issues/5319) for a fine grain list of things not to be missed
### 3. Train the model with reference scripts ### 3. Train the model with reference scripts
......
include README.rst include README.md
include LICENSE include LICENSE
recursive-exclude * __pycache__ recursive-exclude * __pycache__
......
...@@ -47,7 +47,7 @@ pip3 install torchvision* ...@@ -47,7 +47,7 @@ pip3 install torchvision*
##### 编译安装 ##### 编译安装
```bash ```bash
git clone -b dtk-23.10-v0.14.1 http://developer.hpccube.com/codes/aicomponent/vision.git git clone -b dtk-23.10-v0.16.0 http://developer.hpccube.com/codes/aicomponent/vision.git
cd vision cd vision
PYTORCH_ROCM_ARCH="gfx906;gfx926" python3 setup.py bdist_wheel PYTORCH_ROCM_ARCH="gfx906;gfx926" python3 setup.py bdist_wheel
pip3 install dist/vision* pip3 install dist/vision*
......
# torchvision
[![total torchvision downloads](https://pepy.tech/badge/torchvision)](https://pepy.tech/project/torchvision)
[![documentation](https://img.shields.io/badge/dynamic/json.svg?label=docs&url=https%3A%2F%2Fpypi.org%2Fpypi%2Ftorchvision%2Fjson&query=%24.info.version&colorB=brightgreen&prefix=v)](https://pytorch.org/vision/stable/index.html)
The torchvision package consists of popular datasets, model architectures, and common image transformations for computer
vision.
## Installation
Please refer to the [official
instructions](https://pytorch.org/get-started/locally/) to install the stable
versions of `torch` and `torchvision` on your system.
To build source, refer to our [contributing
page](https://github.com/pytorch/vision/blob/main/CONTRIBUTING.md#development-installation).
The following is the corresponding `torchvision` versions and supported Python
versions.
| `torch` | `torchvision` | Python |
| ------------------ | ------------------ | ------------------- |
| `main` / `nightly` | `main` / `nightly` | `>=3.8`, `<=3.11` |
| `2.1` | `0.16` | `>=3.8`, `<=3.11` |
| `2.0` | `0.15` | `>=3.8`, `<=3.11` |
| `1.13` | `0.14` | `>=3.7.2`, `<=3.10` |
<details>
<summary>older versions</summary>
| `torch` | `torchvision` | Python |
|---------|-------------------|---------------------------|
| `1.12` | `0.13` | `>=3.7`, `<=3.10` |
| `1.11` | `0.12` | `>=3.7`, `<=3.10` |
| `1.10` | `0.11` | `>=3.6`, `<=3.9` |
| `1.9` | `0.10` | `>=3.6`, `<=3.9` |
| `1.8` | `0.9` | `>=3.6`, `<=3.9` |
| `1.7` | `0.8` | `>=3.6`, `<=3.9` |
| `1.6` | `0.7` | `>=3.6`, `<=3.8` |
| `1.5` | `0.6` | `>=3.5`, `<=3.8` |
| `1.4` | `0.5` | `==2.7`, `>=3.5`, `<=3.8` |
| `1.3` | `0.4.2` / `0.4.3` | `==2.7`, `>=3.5`, `<=3.7` |
| `1.2` | `0.4.1` | `==2.7`, `>=3.5`, `<=3.7` |
| `1.1` | `0.3` | `==2.7`, `>=3.5`, `<=3.7` |
| `<=1.0` | `0.2` | `==2.7`, `>=3.5`, `<=3.7` |
</details>
## Image Backends
Torchvision currently supports the following image backends:
- torch tensors
- PIL images:
- [Pillow](https://python-pillow.org/)
- [Pillow-SIMD](https://github.com/uploadcare/pillow-simd) - a **much faster** drop-in replacement for Pillow with SIMD.
Read more in in our [docs](https://pytorch.org/vision/stable/transforms.html).
## [UNSTABLE] Video Backend
Torchvision currently supports the following video backends:
- [pyav](https://github.com/PyAV-Org/PyAV) (default) - Pythonic binding for ffmpeg libraries.
- video_reader - This needs ffmpeg to be installed and torchvision to be built from source. There shouldn't be any
conflicting version of ffmpeg installed. Currently, this is only supported on Linux.
```
conda install -c conda-forge ffmpeg
python setup.py install
```
# Using the models on C++
TorchVision provides an example project for how to use the models on C++ using JIT Script.
Installation From source:
```
mkdir build
cd build
# Add -DWITH_CUDA=on support for the CUDA if needed
cmake ..
make
make install
```
Once installed, the library can be accessed in cmake (after properly configuring `CMAKE_PREFIX_PATH`) via the
`TorchVision::TorchVision` target:
```
find_package(TorchVision REQUIRED)
target_link_libraries(my-target PUBLIC TorchVision::TorchVision)
```
The `TorchVision` package will also automatically look for the `Torch` package and add it as a dependency to
`my-target`, so make sure that it is also available to cmake via the `CMAKE_PREFIX_PATH`.
For an example setup, take a look at `examples/cpp/hello_world`.
Python linking is disabled by default when compiling TorchVision with CMake, this allows you to run models without any
Python dependency. In some special cases where TorchVision's operators are used from Python code, you may need to link
to Python. This can be done by passing `-DUSE_PYTHON=on` to CMake.
### TorchVision Operators
In order to get the torchvision operators registered with torch (eg. for the JIT), all you need to do is to ensure that
you `#include <torchvision/vision.h>` in your project.
## Documentation
You can find the API documentation on the pytorch website: <https://pytorch.org/vision/stable/index.html>
## Contributing
See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out.
## Disclaimer on Datasets
This is a utility library that downloads and prepares public datasets. We do not host or distribute these datasets,
vouch for their quality or fairness, or claim that you have license to use the dataset. It is your responsibility to
determine whether you have permission to use the dataset under the dataset's license.
If you're a dataset owner and wish to update any part of it (description, citation, etc.), or do not want your dataset
to be included in this library, please get in touch through a GitHub issue. Thanks for your contribution to the ML
community!
## Pre-trained Model License
The pre-trained models provided in this library may have their own licenses or terms and conditions derived from the
dataset used for training. It is your responsibility to determine whether you have permission to use the models for your
use case.
More specifically, SWAG models are released under the CC-BY-NC 4.0 license. See
[SWAG LICENSE](https://github.com/facebookresearch/SWAG/blob/main/LICENSE) for additional details.
## Citing TorchVision
If you find TorchVision useful in your work, please consider citing the following BibTeX entry:
```bibtex
@software{torchvision2016,
title = {TorchVision: PyTorch's Computer Vision library},
author = {TorchVision maintainers and contributors},
year = 2016,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{https://github.com/pytorch/vision}}
}
```
torchvision
===========
.. image:: https://pepy.tech/badge/torchvision
:target: https://pepy.tech/project/torchvision
.. image:: https://img.shields.io/badge/dynamic/json.svg?label=docs&url=https%3A%2F%2Fpypi.org%2Fpypi%2Ftorchvision%2Fjson&query=%24.info.version&colorB=brightgreen&prefix=v
:target: https://pytorch.org/vision/stable/index.html
The torchvision package consists of popular datasets, model architectures, and common image transformations for computer vision.
Installation
============
We recommend Anaconda as Python package management system. Please refer to `pytorch.org <https://pytorch.org/>`_
for the detail of PyTorch (``torch``) installation. The following is the corresponding ``torchvision`` versions and
supported Python versions.
+--------------------------+--------------------------+---------------------------------+
| ``torch`` | ``torchvision`` | ``python`` |
+==========================+==========================+=================================+
| ``main`` / ``nightly`` | ``main`` / ``nightly`` | ``>=3.7``, ``<=3.10`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.12.0`` | ``0.13.0`` | ``>=3.7``, ``<=3.10`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.11.0`` | ``0.12.0`` | ``>=3.7``, ``<=3.10`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.10.2`` | ``0.11.3`` | ``>=3.6``, ``<=3.9`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.10.1`` | ``0.11.2`` | ``>=3.6``, ``<=3.9`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.10.0`` | ``0.11.1`` | ``>=3.6``, ``<=3.9`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.9.1`` | ``0.10.1`` | ``>=3.6``, ``<=3.9`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.9.0`` | ``0.10.0`` | ``>=3.6``, ``<=3.9`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.8.2`` | ``0.9.2`` | ``>=3.6``, ``<=3.9`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.8.1`` | ``0.9.1`` | ``>=3.6``, ``<=3.9`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.8.0`` | ``0.9.0`` | ``>=3.6``, ``<=3.9`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.7.1`` | ``0.8.2`` | ``>=3.6``, ``<=3.9`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.7.0`` | ``0.8.1`` | ``>=3.6``, ``<=3.8`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.7.0`` | ``0.8.0`` | ``>=3.6``, ``<=3.8`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.6.0`` | ``0.7.0`` | ``>=3.6``, ``<=3.8`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.5.1`` | ``0.6.1`` | ``>=3.5``, ``<=3.8`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.5.0`` | ``0.6.0`` | ``>=3.5``, ``<=3.8`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.4.0`` | ``0.5.0`` | ``==2.7``, ``>=3.5``, ``<=3.8`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.3.1`` | ``0.4.2`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.3.0`` | ``0.4.1`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.2.0`` | ``0.4.0`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
+--------------------------+--------------------------+---------------------------------+
| ``1.1.0`` | ``0.3.0`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
+--------------------------+--------------------------+---------------------------------+
| ``<=1.0.1`` | ``0.2.2`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
+--------------------------+--------------------------+---------------------------------+
Anaconda:
.. code:: bash
conda install torchvision -c pytorch
pip:
.. code:: bash
pip install torchvision
From source:
.. code:: bash
python setup.py install
# or, for OSX
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install
We don't officially support building from source using ``pip``, but *if* you do,
you'll need to use the ``--no-build-isolation`` flag.
In case building TorchVision from source fails, install the nightly version of PyTorch following
the linked guide on the `contributing page <https://github.com/pytorch/vision/blob/main/CONTRIBUTING.md#development-installation>`_ and retry the install.
By default, GPU support is built if CUDA is found and ``torch.cuda.is_available()`` is true.
It's possible to force building GPU support by setting ``FORCE_CUDA=1`` environment variable,
which is useful when building a docker image.
Image Backend
=============
Torchvision currently supports the following image backends:
* `Pillow`_ (default)
* `Pillow-SIMD`_ - a **much faster** drop-in replacement for Pillow with SIMD. If installed will be used as the default.
* `accimage`_ - if installed can be activated by calling :code:`torchvision.set_image_backend('accimage')`
* `libpng`_ - can be installed via conda :code:`conda install libpng` or any of the package managers for debian-based and RHEL-based Linux distributions.
* `libjpeg`_ - can be installed via conda :code:`conda install jpeg` or any of the package managers for debian-based and RHEL-based Linux distributions. `libjpeg-turbo`_ can be used as well.
**Notes:** ``libpng`` and ``libjpeg`` must be available at compilation time in order to be available. Make sure that it is available on the standard library locations,
otherwise, add the include and library paths in the environment variables ``TORCHVISION_INCLUDE`` and ``TORCHVISION_LIBRARY``, respectively.
.. _libpng : http://www.libpng.org/pub/png/libpng.html
.. _Pillow : https://python-pillow.org/
.. _Pillow-SIMD : https://github.com/uploadcare/pillow-simd
.. _accimage: https://github.com/pytorch/accimage
.. _libjpeg: http://ijg.org/
.. _libjpeg-turbo: https://libjpeg-turbo.org/
Video Backend
=============
Torchvision currently supports the following video backends:
* `pyav`_ (default) - Pythonic binding for ffmpeg libraries.
.. _pyav : https://github.com/PyAV-Org/PyAV
* video_reader - This needs ffmpeg to be installed and torchvision to be built from source. There shouldn't be any conflicting version of ffmpeg installed. Currently, this is only supported on Linux.
.. code:: bash
conda install -c conda-forge ffmpeg
python setup.py install
Using the models on C++
=======================
TorchVision provides an example project for how to use the models on C++ using JIT Script.
Installation From source:
.. code:: bash
mkdir build
cd build
# Add -DWITH_CUDA=on support for the CUDA if needed
cmake ..
make
make install
Once installed, the library can be accessed in cmake (after properly configuring ``CMAKE_PREFIX_PATH``) via the :code:`TorchVision::TorchVision` target:
.. code:: rest
find_package(TorchVision REQUIRED)
target_link_libraries(my-target PUBLIC TorchVision::TorchVision)
The ``TorchVision`` package will also automatically look for the ``Torch`` package and add it as a dependency to ``my-target``,
so make sure that it is also available to cmake via the ``CMAKE_PREFIX_PATH``.
For an example setup, take a look at ``examples/cpp/hello_world``.
Python linking is disabled by default when compiling TorchVision with CMake, this allows you to run models without any Python
dependency. In some special cases where TorchVision's operators are used from Python code, you may need to link to Python. This
can be done by passing ``-DUSE_PYTHON=on`` to CMake.
TorchVision Operators
---------------------
In order to get the torchvision operators registered with torch (eg. for the JIT), all you need to do is to ensure that you
:code:`#include <torchvision/vision.h>` in your project.
Documentation
=============
You can find the API documentation on the pytorch website: https://pytorch.org/vision/stable/index.html
Contributing
============
See the `CONTRIBUTING <CONTRIBUTING.md>`_ file for how to help out.
Disclaimer on Datasets
======================
This is a utility library that downloads and prepares public datasets. We do not host or distribute these datasets, vouch for their quality or fairness, or claim that you have license to use the dataset. It is your responsibility to determine whether you have permission to use the dataset under the dataset's license.
If you're a dataset owner and wish to update any part of it (description, citation, etc.), or do not want your dataset to be included in this library, please get in touch through a GitHub issue. Thanks for your contribution to the ML community!
Pre-trained Model License
=========================
The pre-trained models provided in this library may have their own licenses or terms and conditions derived from the dataset used for training. It is your responsibility to determine whether you have permission to use the models for your use case.
More specifically, SWAG models are released under the CC-BY-NC 4.0 license. See `SWAG LICENSE <https://github.com/facebookresearch/SWAG/blob/main/LICENSE>`_ for additional details.
## Status
The Android demo of TorchVision is currently unmaintained, untested and likely out-of-date.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment