Unverified Commit 64ccfe34 authored by Edward Z. Yang's avatar Edward Z. Yang Committed by GitHub
Browse files

Rewrite torchvision packaging (#1209)

Following a similar line of inquiry to pytorch/audio#217
parent 5414faa0
version: 2.1
# How to test the Linux jobs:
# - Install CircleCI local CLI: https://circleci.com/docs/2.0/local-cli/
# - circleci config process .circleci/config.yml > gen.yml && circleci local execute -c gen.yml --job binary_linux_wheel
# - Replace binary_linux_wheel with the name of the job you want to test
binary_common: &binary_common
parameters:
# Edit these defaults to do a release`
build_version:
description: "version number of release binary; by default, build a nightly"
type: string
default: ""
pytorch_version:
description: "PyTorch version to build against; by default, use a nightly"
type: string
default: ""
# Don't edit these
python_version:
description: "Python version to build against (e.g., 3.7)"
type: string
cuda_version:
description: "CUDA version to build against (e.g., cpu or 10.0)"
type: string
unicode_abi:
description: "Python 2.7 wheel only: whether or not we are cp27mu (default: no)"
type: string
default: ""
environment:
PYTHON_VERSION: << parameters.python_version >>
BUILD_VERSION: << parameters.build_version >>
PYTORCH_VERSION: << parameters.pytorch_version >>
UNICODE_ABI: << parameters.unicode_abi >>
CUDA_VERSION: << parameters.cuda_version >>
jobs:
build:
circleci_consistency:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run:
command: |
pip install --user --progress-bar off jinja2
python .circleci/regenerate.py
git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1)
binary_linux_wheel:
<<: *binary_common
docker:
- image: "soumith/manylinux-cuda100"
resource_class: 2xlarge+
steps:
- checkout
- run: packaging/build_wheel.sh
- store_artifacts:
path: dist
binary_linux_conda:
<<: *binary_common
docker:
- image: "soumith/conda-cuda"
resource_class: 2xlarge+
steps:
- checkout
- run: packaging/build_conda.sh
- store_artifacts:
path: /opt/conda/conda-bld/linux-64
binary_macos_wheel:
<<: *binary_common
macos:
xcode: "9.0"
steps:
- checkout
- run:
# Cannot easily deduplicate this as source'ing activate
# will set environment variables which we need to propagate
# to build_wheel.sh
command: |
curl -o conda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
sh conda.sh -b
source $HOME/miniconda3/bin/activate
packaging/build_wheel.sh
- store_artifacts:
path: dist
binary_macos_conda:
<<: *binary_common
macos:
xcode: "9.0"
steps:
- checkout
- run:
command: |
curl -o conda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
sh conda.sh -b
source $HOME/miniconda3/bin/activate
conda install -yq conda-build
packaging/build_conda.sh
- store_artifacts:
path: /Users/distiller/miniconda3/conda-bld/osx-64
workflows:
build:
jobs:
- circleci_consistency
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py2.7_cudacpu
python_version: "2.7"
cuda_version: "cpu"
- binary_linux_wheel:
name: binary_linux_wheel_py2.7_cudacpu_unicode
python_version: "2.7"
cuda_version: "cpu"
unicode_abi: "1"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py2.7_cuda10.0
python_version: "2.7"
cuda_version: "10.0"
- binary_linux_wheel:
name: binary_linux_wheel_py2.7_cuda10.0_unicode
python_version: "2.7"
cuda_version: "10.0"
unicode_abi: "1"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py2.7_cuda9.2
python_version: "2.7"
cuda_version: "9.2"
- binary_linux_wheel:
name: binary_linux_wheel_py2.7_cuda9.2_unicode
python_version: "2.7"
cuda_version: "9.2"
unicode_abi: "1"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py3.5_cudacpu
python_version: "3.5"
cuda_version: "cpu"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py3.5_cuda10.0
python_version: "3.5"
cuda_version: "10.0"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py3.5_cuda9.2
python_version: "3.5"
cuda_version: "9.2"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py3.6_cudacpu
python_version: "3.6"
cuda_version: "cpu"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py3.6_cuda10.0
python_version: "3.6"
cuda_version: "10.0"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py3.6_cuda9.2
python_version: "3.6"
cuda_version: "9.2"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py3.7_cudacpu
python_version: "3.7"
cuda_version: "cpu"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py3.7_cuda10.0
python_version: "3.7"
cuda_version: "10.0"
- binary_linux_wheel:
# TODO: cudacpu is ugly
name: binary_linux_wheel_py3.7_cuda9.2
python_version: "3.7"
cuda_version: "9.2"
- binary_macos_wheel:
# TODO: cudacpu is ugly
name: binary_macos_wheel_py2.7_cudacpu
python_version: "2.7"
cuda_version: "cpu"
- binary_macos_wheel:
name: binary_macos_wheel_py2.7_cudacpu_unicode
python_version: "2.7"
cuda_version: "cpu"
unicode_abi: "1"
- binary_macos_wheel:
# TODO: cudacpu is ugly
name: binary_macos_wheel_py3.5_cudacpu
python_version: "3.5"
cuda_version: "cpu"
- binary_macos_wheel:
# TODO: cudacpu is ugly
name: binary_macos_wheel_py3.6_cudacpu
python_version: "3.6"
cuda_version: "cpu"
- binary_macos_wheel:
# TODO: cudacpu is ugly
name: binary_macos_wheel_py3.7_cudacpu
python_version: "3.7"
cuda_version: "cpu"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py2.7_cudacpu
python_version: "2.7"
cuda_version: "cpu"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py2.7_cuda10.0
python_version: "2.7"
cuda_version: "10.0"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py2.7_cuda9.2
python_version: "2.7"
cuda_version: "9.2"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py3.5_cudacpu
python_version: "3.5"
cuda_version: "cpu"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py3.5_cuda10.0
python_version: "3.5"
cuda_version: "10.0"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py3.5_cuda9.2
python_version: "3.5"
cuda_version: "9.2"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py3.6_cudacpu
python_version: "3.6"
cuda_version: "cpu"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py3.6_cuda10.0
python_version: "3.6"
cuda_version: "10.0"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py3.6_cuda9.2
python_version: "3.6"
cuda_version: "9.2"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py3.7_cudacpu
python_version: "3.7"
cuda_version: "cpu"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py3.7_cuda10.0
python_version: "3.7"
cuda_version: "10.0"
- binary_linux_conda:
# TODO: cudacpu is ugly
name: binary_linux_conda_py3.7_cuda9.2
python_version: "3.7"
cuda_version: "9.2"
- binary_macos_conda:
# TODO: cudacpu is ugly
name: binary_macos_conda_py2.7_cudacpu
python_version: "2.7"
cuda_version: "cpu"
- binary_macos_conda:
# TODO: cudacpu is ugly
name: binary_macos_conda_py3.5_cudacpu
python_version: "3.5"
cuda_version: "cpu"
- binary_macos_conda:
# TODO: cudacpu is ugly
name: binary_macos_conda_py3.6_cudacpu
python_version: "3.6"
cuda_version: "cpu"
- binary_macos_conda:
# TODO: cudacpu is ugly
name: binary_macos_conda_py3.7_cudacpu
python_version: "3.7"
cuda_version: "cpu"
\ No newline at end of file
version: 2.1
# How to test the Linux jobs:
# - Install CircleCI local CLI: https://circleci.com/docs/2.0/local-cli/
# - circleci config process .circleci/config.yml > gen.yml && circleci local execute -c gen.yml --job binary_linux_wheel
# - Replace binary_linux_wheel with the name of the job you want to test
binary_common: &binary_common
parameters:
# Edit these defaults to do a release`
build_version:
description: "version number of release binary; by default, build a nightly"
type: string
default: ""
pytorch_version:
description: "PyTorch version to build against; by default, use a nightly"
type: string
default: ""
# Don't edit these
python_version:
description: "Python version to build against (e.g., 3.7)"
type: string
cuda_version:
description: "CUDA version to build against (e.g., cpu or 10.0)"
type: string
unicode_abi:
description: "Python 2.7 wheel only: whether or not we are cp27mu (default: no)"
type: string
default: ""
environment:
PYTHON_VERSION: << parameters.python_version >>
BUILD_VERSION: << parameters.build_version >>
PYTORCH_VERSION: << parameters.pytorch_version >>
UNICODE_ABI: << parameters.unicode_abi >>
CUDA_VERSION: << parameters.cuda_version >>
jobs:
circleci_consistency:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run:
command: |
pip install --user --progress-bar off jinja2
python .circleci/regenerate.py
git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1)
binary_linux_wheel:
<<: *binary_common
docker:
- image: "soumith/manylinux-cuda100"
resource_class: 2xlarge+
steps:
- checkout
- run: packaging/build_wheel.sh
- store_artifacts:
path: dist
binary_linux_conda:
<<: *binary_common
docker:
- image: "soumith/conda-cuda"
resource_class: 2xlarge+
steps:
- checkout
- run: packaging/build_conda.sh
- store_artifacts:
path: /opt/conda/conda-bld/linux-64
binary_macos_wheel:
<<: *binary_common
macos:
xcode: "9.0"
steps:
- checkout
- run:
# Cannot easily deduplicate this as source'ing activate
# will set environment variables which we need to propagate
# to build_wheel.sh
command: |
curl -o conda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
sh conda.sh -b
source $HOME/miniconda3/bin/activate
packaging/build_wheel.sh
- store_artifacts:
path: dist
binary_macos_conda:
<<: *binary_common
macos:
xcode: "9.0"
steps:
- checkout
- run:
command: |
curl -o conda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
sh conda.sh -b
source $HOME/miniconda3/bin/activate
conda install -yq conda-build
packaging/build_conda.sh
- store_artifacts:
path: /Users/distiller/miniconda3/conda-bld/osx-64
workflows:
build:
jobs:
- circleci_consistency
{%- for btype in ["wheel", "conda"] -%}
{%- for os in ["linux", "macos"] -%}
{%- for python_version in ["2.7", "3.5", "3.6", "3.7"] -%}
{%- for cuda_version in ["cpu", "10.0", "9.2"] -%}
{%- if os != "macos" or cuda_version == "cpu" %}
- binary_{{os}}_{{btype}}:
# TODO: cudacpu is ugly
name: binary_{{os}}_{{btype}}_py{{python_version}}_cuda{{cuda_version}}
python_version: "{{python_version}}"
cuda_version: "{{cuda_version}}"
{%- if btype == "wheel" and python_version == "2.7" %}
- binary_{{os}}_{{btype}}:
name: binary_{{os}}_{{btype}}_py{{python_version}}_cuda{{cuda_version}}_unicode
python_version: "{{python_version}}"
cuda_version: "{{cuda_version}}"
unicode_abi: "1"
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{%- endfor -%}
{%- endfor -%}
#!/usr/bin/env python
import jinja2
import os.path
d = os.path.dirname(__file__)
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(d),
lstrip_blocks=True,
autoescape=False,
)
with open(os.path.join(d, 'config.yml'), 'w') as f:
f.write(env.get_template('config.yml.in').render())
......@@ -19,3 +19,4 @@ htmlcov
*/*.dylib*
*.swp
*.swo
gen.yml
#!/bin/bash
set -ex
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
. "$script_dir/pkg_helpers.bash"
setup_build_version 0.4.0
setup_cuda_suffix
setup_macos
export SOURCE_ROOT_DIR="$PWD"
setup_conda_pytorch_constraint
setup_conda_cudatoolkit_constraint
conda build $CONDA_CHANNEL_FLAGS -c defaults -c conda-forge --no-anaconda-upload --python "$PYTHON_VERSION" packaging/torchvision
#!/bin/bash
set -ex
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
. "$script_dir/pkg_helpers.bash"
setup_python
setup_cuda_suffix
setup_build_version 0.4.0
setup_macos
pip_install numpy pyyaml future ninja
setup_pip_pytorch_version
python setup.py clean
IS_WHEEL=1 python setup.py bdist_wheel
# A set of useful bash functions for common functionality we need to do in
# many build scripts
# Respecting PYTHON_VERSION and UNICODE_ABI, add (or install) the correct
# version of Python to perform a build. Relevant to wheel builds.
setup_python() {
if [[ "$(uname)" == Darwin ]]; then
eval "$(conda shell.bash hook)"
conda env remove -n "env$PYTHON_VERSION" || true
conda create -yn "env$PYTHON_VERSION" python="$PYTHON_VERSION"
conda activate "env$PYTHON_VERSION"
else
case "$PYTHON_VERSION" in
2.7)
if [[ -n "$UNICODE_ABI" ]]; then
python_abi=cp27-cp27mu
else
python_abi=cp27-cp27m
fi
;;
3.5) python_abi=cp35-cp35m ;;
3.6) python_abi=cp36-cp36m ;;
3.7) python_abi=cp37-cp37m ;;
*)
echo "Unrecognized PYTHON_VERSION=$PYTHON_VERSION"
exit 1
;;
esac
export PATH="/opt/python/$python_abi/bin:$PATH"
fi
}
# Fill CUDA_SUFFIX and CU_VERSION with CUDA_VERSION. CUDA_SUFFIX is
# left blank for the default CUDA version (that's a blank suffix)
setup_cuda_suffix() {
if [[ "$(uname)" == Darwin ]]; then
if [[ "$CUDA_VERSION" != "cpu" ]]; then
echo "CUDA_VERSION on OS X must be cpu"
exit 1
fi
export CPU_SUFFIX=""
export CU_VERSION="cpu"
else
case "$CUDA_VERSION" in
10.0)
export CUDA_SUFFIX=""
export CU_VERSION="cu100"
;;
9.2)
export CUDA_SUFFIX="+cu92"
export CU_VERSION="cu92"
;;
cpu)
export CUDA_SUFFIX="+cpu"
export CU_VERSION="cpu"
;;
*)
echo "Unrecognized CUDA_VERSION=$CUDA_VERSION"
esac
export CPU_SUFFIX="+cpu"
fi
}
# If a package is cpu-only, we never provide a cuda suffix
setup_cpuonly_cuda_suffix() {
export CUDA_SUFFIX=""
export CPU_SUFFIX=""
}
# Fill BUILD_VERSION and BUILD_NUMBER if it doesn't exist already with a nightly string
# Usage: setup_build_version 0.2
setup_build_version() {
if [[ -z "$BUILD_VERSION" ]]; then
export BUILD_VERSION="$1.dev$(date "+%Y%m%d")"
fi
}
# Set some useful variables for OS X, if applicable
setup_macos() {
if [[ "$(uname)" == Darwin ]]; then
export MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++
fi
}
# Function to retry functions that sometimes timeout or have flaky failures
retry () {
$* || (sleep 1 && $*) || (sleep 2 && $*) || (sleep 4 && $*) || (sleep 8 && $*)
}
# Install with pip a bit more robustly than the default
pip_install() {
retry pip install --progress-bar off "$@"
}
# Install torch with pip, respecting PYTORCH_VERSION, and record the installed
# version into PYTORCH_VERSION, if applicable
setup_pip_pytorch_version() {
if [[ -z "$PYTORCH_VERSION" ]]; then
# Install latest prerelease version of torch, per our nightlies, consistent
# with the requested cuda version
pip_install --pre torch -f "https://download.pytorch.org/whl/nightly/${CU_VERSION}/torch_nightly.html"
if [[ "$CUDA_VERSION" == "cpu" ]]; then
# CUDA and CPU are ABI compatible on the CPU-only parts, so strip
# in this case
export PYTORCH_VERSION="$(pip show torch | grep ^Version: | sed 's/Version: *//' | sed 's/+.\+//')"
else
export PYTORCH_VERSION="$(pip show torch | grep ^Version: | sed 's/Version: *//')"
fi
else
# TODO: Maybe add staging too
pip_install "torch==$PYTORCH_VERSION$CUDA_SUFFIX" \
-f https://download.pytorch.org/whl/torch_stable.html
fi
}
# Fill PYTORCH_VERSION with the latest conda nightly version, and
# CONDA_CHANNEL_FLAGS with appropriate flags to retrieve these versions
#
# You MUST have populated CUDA_SUFFIX before hand.
#
# TODO: This is currently hard-coded for CPU-only case
setup_conda_pytorch_constraint() {
if [[ -z "$PYTORCH_VERSION" ]]; then
export CONDA_CHANNEL_FLAGS="-c pytorch-nightly"
export PYTORCH_VERSION="$(conda search --json 'pytorch[channel=pytorch-nightly]' | python -c "import sys, json, re; print(re.sub(r'\\+.*$', '', json.load(sys.stdin)['pytorch'][-1]['version']))")"
else
export CONDA_CHANNEL_FLAGS="-c pytorch"
fi
if [[ "$CUDA_VERSION" == cpu ]]; then
export CONDA_PYTORCH_BUILD_CONSTRAINT="- pytorch==$PYTORCH_VERSION${CPU_SUFFIX}"
export CONDA_PYTORCH_CONSTRAINT="- pytorch==$PYTORCH_VERSION"
else
export CONDA_PYTORCH_BUILD_CONSTRAINT="- pytorch==${PYTORCH_VERSION}${CUDA_SUFFIX}"
export CONDA_PYTORCH_CONSTRAINT="- pytorch==${PYTORCH_VERSION}${CUDA_SUFFIX}"
fi
}
# Translate CUDA_VERSION into CUDA_CUDATOOLKIT_CONSTRAINT
setup_conda_cudatoolkit_constraint() {
export CONDA_CPUONLY_FEATURE=""
if [[ "$(uname)" == Darwin ]]; then
export CONDA_CUDATOOLKIT_CONSTRAINT=""
else
case "$CUDA_VERSION" in
10.0)
export CONDA_CUDATOOLKIT_CONSTRAINT="- cudatoolkit >=10.0,<10.1 # [not osx]"
;;
9.2)
export CONDA_CUDATOOLKIT_CONSTRAINT="- cudatoolkit >=9.2,<9.3 # [not osx]"
;;
cpu)
export CONDA_CUDATOOLKIT_CONSTRAINT=""
export CONDA_CPUONLY_FEATURE="- cpuonly"
;;
esac
fi
}
package:
name: torchvision{{ environ.get('TORCHVISION_PACKAGE_SUFFIX') }}
version: "{{ environ.get('TORCHVISION_BUILD_VERSION') }}"
name: torchvision
version: "{{ environ.get('BUILD_VERSION') }}"
source:
git_rev: v{{ environ.get('TORCHVISION_BUILD_VERSION') }}
git_url: https://github.com/pytorch/vision.git
path: "{{ environ.get('SOURCE_ROOT_DIR') }}"
requirements:
build:
......@@ -14,23 +12,24 @@ requirements:
host:
- python
- setuptools
- pytorch{{ environ.get('TORCHVISION_PACKAGE_SUFFIX') }} >=1.1.0
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
{{ environ.get('CONDA_PYTORCH_BUILD_CONSTRAINT') }}
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
run:
- python
- pillow >=4.1.1
- numpy >=1.11
- pytorch{{ environ.get('TORCHVISION_PACKAGE_SUFFIX') }} >=1.1.0
- six
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
build:
number: {{ environ.get('TORCHVISION_BUILD_NUMBER') }}
string: py{{py}}_cu{{ environ['CUDA_VERSION'] }}_{{environ.get('TORCHVISION_BUILD_NUMBER')}}
string: py{{py}}_{{ environ['CU_VERSION'] }}
script: python setup.py install --single-version-externally-managed --record=record.txt # [not win]
script_env:
- CUDA_VERSION
- CU_VERSION
features:
{{ CONDA_CPUONLY_FEATURE }}
test:
imports:
......@@ -42,6 +41,9 @@ test:
requires:
- pytest
- scipy
- mock
- av
- ca-certificates
commands:
pytest .
......
......@@ -31,7 +31,7 @@ def get_dist(pkgname):
version = '0.4.0a0'
sha = 'Unknown'
package_name = os.getenv('TORCHVISION_PACKAGE_NAME', 'torchvision')
package_name = 'torchvision'
cwd = os.path.dirname(os.path.abspath(__file__))
......@@ -40,16 +40,8 @@ try:
except Exception:
pass
if os.getenv('TORCHVISION_BUILD_VERSION'):
assert os.getenv('TORCHVISION_BUILD_NUMBER') is not None
build_number = int(os.getenv('TORCHVISION_BUILD_NUMBER'))
base_version = os.getenv('TORCHVISION_BUILD_VERSION')
version = base_version
if build_number > 1:
version += '.post' + str(build_number)
local_label = os.getenv('TORCHVISION_LOCAL_VERSION_LABEL')
if local_label is not None:
version += '+' + local_label
if os.getenv('BUILD_VERSION'):
version = os.getenv('BUILD_VERSION')
elif sha != 'Unknown':
version += '+' + sha[:7]
print("Building wheel {}-{}".format(package_name, version))
......@@ -69,12 +61,9 @@ write_version_file()
readme = open('README.rst').read()
pytorch_dep = os.getenv('TORCHVISION_PYTORCH_DEPENDENCY_NAME', 'torch')
if os.getenv('TORCHVISION_PYTORCH_DEPENDENCY_VERSION'):
pytorch_dep += "==" + os.getenv('TORCHVISION_PYTORCH_DEPENDENCY_VERSION')
# torchvision has CUDA bits, thus, we must specify a local dependency
if local_label is not None:
pytorch_dep += '+' + local_label
pytorch_dep = 'torch'
if os.getenv('PYTORCH_VERSION'):
pytorch_dep += "==" + os.getenv('PYTORCH_VERSION')
requirements = [
'numpy',
......
......@@ -2,6 +2,7 @@ import torch
import os
import unittest
from torchvision import models, transforms, _C_tests
import sys
from PIL import Image
import torchvision.transforms.functional as F
......@@ -35,6 +36,10 @@ def read_image2():
return torch.cat([x, x], 0)
@unittest.skipIf(
sys.platform == "darwin" or True,
"C++ models are broken on OS X at the moment, and there's a BC breakage on master; "
"see https://github.com/pytorch/vision/issues/1191")
class Tester(unittest.TestCase):
pretrained = False
image = read_image1()
......
......@@ -57,6 +57,7 @@ class Tester(unittest.TestCase):
])
self.assertTrue(r.equal(expected))
@unittest.skipIf(not io.video._av_available(), "this test requires av")
def test_video_clips(self):
with get_list_of_videos(num_videos=3) as video_list:
video_clips = VideoClips(video_list, 5, 5)
......@@ -110,6 +111,7 @@ class Tester(unittest.TestCase):
self.assertTrue(v_idxs.equal(torch.tensor([0, 1])))
self.assertTrue(count.equal(torch.tensor([3, 3])))
@unittest.skipIf(not io.video._av_available(), "this test requires av")
def test_video_clips_custom_fps(self):
with get_list_of_videos(num_videos=3, sizes=[12, 12, 12], fps=[3, 4, 6]) as video_list:
num_frames = 4
......
......@@ -17,6 +17,8 @@ else:
try:
import av
# Do a version test too
io.video._check_av_available()
except ImportError:
av = None
......
......@@ -83,7 +83,7 @@ def download_url(url, root, filename=None, md5=None):
url, fpath,
reporthook=gen_bar_updater()
)
except urllib.error.URLError as e:
except (urllib.error.URLError, IOError) as e:
if url[:5] == 'https':
url = url.replace('https:', 'http:')
print('Failed download. Trying https -> http instead.'
......
......@@ -6,19 +6,31 @@ import numpy as np
try:
import av
av.logging.set_level(av.logging.ERROR)
if not hasattr(av.video.frame.VideoFrame, 'pict_type'):
av = ImportError("""\
Your version of PyAV is too old for the necessary video operations in torchvision.
If you are on Python 3.5, you will have to build from source (the conda-forge
packages are not up-to-date). See
https://github.com/mikeboers/PyAV#installation for instructions on how to
install PyAV on your system.
""")
except ImportError:
av = None
def _check_av_available():
if av is None:
raise ImportError("""\
av = ImportError("""\
PyAV is not installed, and is necessary for the video operations in torchvision.
See https://github.com/mikeboers/PyAV#installation for instructions on how to
install PyAV on your system.
""")
def _check_av_available():
if isinstance(av, Exception):
raise av
def _av_available():
return not isinstance(av, Exception)
# PyAV has some reference cycles
_CALLED_TIMES = 0
_GC_COLLECTION_INTERVAL = 10
......
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