python-torchvision: enable and bump to 0.15.1

This commit is contained in:
Chongyun Lee 2023-03-25 22:27:09 +08:00 committed by xtkoba
parent e00fbe5514
commit f4f9a14522
3 changed files with 70 additions and 85 deletions

View File

@ -1,41 +0,0 @@
TERMUX_PKG_HOMEPAGE=https://github.com/pytorch/vision
TERMUX_PKG_DESCRIPTION="Datasets, Transforms and Models specific to Computer Vision"
TERMUX_PKG_LICENSE="BSD 3-Clause"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=0.13.1
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=git+https://github.com/pytorch/vision
TERMUX_PKG_DEPENDS="python, python-numpy, python-pillow, python-torch, libjpeg-turbo, libpng, ffmpeg, zlib"
termux_step_pre_configure() {
_PYTHON_VERSION=$(. $TERMUX_SCRIPTDIR/packages/python/build.sh; echo $_MAJOR_VERSION)
termux_setup_python_crossenv
pushd $TERMUX_PYTHON_CROSSENV_SRCDIR
_CROSSENV_PREFIX=$TERMUX_PKG_BUILDDIR/python-crossenv-prefix
python${_PYTHON_VERSION} -m crossenv \
$TERMUX_PREFIX/bin/python${_PYTHON_VERSION} \
${_CROSSENV_PREFIX}
popd
. ${_CROSSENV_PREFIX}/bin/activate
build-pip install -U wheel setuptools
CFLAGS+=" -I${TERMUX_PREFIX}/lib/python${_PYTHON_VERSION}/site-packages/torch/include"
CFLAGS+=" -I${TERMUX_PREFIX}/lib/python${_PYTHON_VERSION}/site-packages/torch/include/torch/csrc/api/include"
CXXFLAGS+=" -DUSE_PYTHON"
LDFLAGS+=" -ltorch_cpu -ltorch_python -lc10"
}
termux_step_configure() {
:
}
termux_step_make_install() {
pip -v install --prefix "$TERMUX_PREFIX" "$TERMUX_PKG_SRCDIR"
}
termux_step_create_debscripts() {
echo "#!$TERMUX_PREFIX/bin/sh" > postinst
echo "pip3 install typing_extensions requests" >> postinst
}

View File

@ -0,0 +1,33 @@
TERMUX_PKG_HOMEPAGE=https://github.com/pytorch/vision
TERMUX_PKG_DESCRIPTION="Datasets, Transforms and Models specific to Computer Vision"
TERMUX_PKG_LICENSE="BSD 3-Clause"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=0.15.1
TERMUX_PKG_SRCURL=git+https://github.com/pytorch/vision
# ffmpeg
TERMUX_PKG_DEPENDS="libc++, python, python-numpy, python-pillow, python-pip, python-torch, libjpeg-turbo, libpng, zlib"
TERMUX_PKG_PYTHON_COMMON_DEPS="wheel, setuptools"
termux_step_pre_configure() {
CFLAGS+=" -I${TERMUX_PYTHON_HOME}/site-packages/torch/include"
CFLAGS+=" -I${TERMUX_PYTHON_HOME}/site-packages/torch/include/torch/csrc/api/include"
CXXFLAGS+=" -DUSE_PYTHON"
LDFLAGS+=" -ltorch_cpu -ltorch_python -lc10"
# FIXME: Disable ffmpeg temporarily because torchvision doesn't support ffmpeg 6.
export TORCHVISION_USE_FFMPEG=0
export BUILD_VERSION=$TERMUX_PKG_VERSION
}
termux_step_configure() {
:
}
termux_step_make_install() {
pip -v install --no-build-isolation --no-deps --prefix "$TERMUX_PREFIX" "$TERMUX_PKG_SRCDIR"
}
termux_step_create_debscripts() {
echo "#!$TERMUX_PREFIX/bin/sh" > postinst
echo "pip3 install typing_extensions requests" >> postinst
}

View File

@ -1,19 +1,18 @@
diff -uNr vision/setup.py vision.mod/setup.py
--- vision/setup.py 2022-10-07 23:30:59.696293602 +0900
+++ vision.mod/setup.py 2022-10-08 01:16:59.594996000 +0900
--- ./setup.py.orig
+++ ./setup.py
@@ -6,10 +6,9 @@
import subprocess
import sys
-import torch
from pkg_resources import parse_version, get_distribution, DistributionNotFound
from setuptools import setup, find_packages
-from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension, CUDA_HOME
from pkg_resources import DistributionNotFound, get_distribution, parse_version
from setuptools import find_packages, setup
-from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDA_HOME, CUDAExtension
+from setuptools import Extension as CppExtension
def read(*names, **kwargs):
@@ -141,11 +140,6 @@
@@ -159,11 +158,6 @@
is_rocm_pytorch = False
@ -25,20 +24,26 @@ diff -uNr vision/setup.py vision.mod/setup.py
if is_rocm_pytorch:
from torch.utils.hipify import hipify_python
@@ -182,10 +176,8 @@
@@ -189,7 +183,7 @@
define_macros = []
- extra_compile_args = {"cxx": []}
- if (torch.cuda.is_available() and ((CUDA_HOME is not None) or is_rocm_pytorch)) or os.getenv(
- "FORCE_CUDA", "0"
- ) == "1":
+ extra_compile_args = []
- if (torch.cuda.is_available() and ((CUDA_HOME is not None) or is_rocm_pytorch)) or force_cuda:
+ extra_compile_args = {}
+ if False:
extension = CUDAExtension
sources += source_cuda
if not is_rocm_pytorch:
@@ -308,11 +300,7 @@
@@ -245,7 +245,7 @@
image_macros += [("USE_PYTHON", None)]
# Locating libPNG
- libpng = shutil.which("libpng-config")
+ libpng = "@TERMUX_PREFIX@/bin/libpng-config"
pngfix = shutil.which("pngfix")
png_found = libpng is not None or pngfix is not None
@@ -308,11 +302,7 @@
# Locating nvjpeg
# Should be included in CUDA_HOME for CUDA >= 10.1, which is the minimum version we have in the CI
@ -49,32 +54,27 @@ diff -uNr vision/setup.py vision.mod/setup.py
- )
+ nvjpeg_found = False
print(f"NVJPEG found: {nvjpeg_found}")
image_macros += [("NVJPEG_FOUND", str(int(nvjpeg_found)))]
@@ -340,7 +328,7 @@
)
use_nvjpeg = use_nvjpeg and nvjpeg_found
if use_nvjpeg:
@@ -343,7 +333,7 @@
)
# Locating ffmpeg
- ffmpeg_exe = shutil.which("ffmpeg")
+ ffmpeg_exe = "@TERMUX_PREFIX@/bin/ffmpeg"
has_ffmpeg = ffmpeg_exe is not None
ffmpeg_version = None
# FIXME: Building torchvision with ffmpeg on MacOS or with Python 3.9
# FIXME: causes crash. See the following GitHub issues for more details.
@@ -348,13 +336,6 @@
@@ -352,7 +342,7 @@
# FIXME: https://github.com/pytorch/vision/issues/3367
if sys.platform != "linux" or (sys.version_info.major == 3 and sys.version_info.minor == 9):
has_ffmpeg = False
- if has_ffmpeg:
- try:
- # This is to check if ffmpeg is installed properly.
- subprocess.check_output(["ffmpeg", "-version"])
- except subprocess.CalledProcessError:
- print("Error fetching ffmpeg version, ignoring ffmpeg.")
- has_ffmpeg = False
print(f"FFmpeg found: {has_ffmpeg}")
@@ -435,13 +416,7 @@
+ if False:
try:
# This is to check if ffmpeg is installed properly.
ffmpeg_version = subprocess.check_output(["ffmpeg", "-version"])
@@ -444,13 +434,7 @@
# CUDA_HOME should be set to the cuda root directory.
# TORCHVISION_INCLUDE and TORCHVISION_LIBRARY should include the location to
# video codec header files and libraries respectively.
@ -87,20 +87,13 @@ diff -uNr vision/setup.py vision.mod/setup.py
- )
+ video_codec_found = False
print(f"video codec found: {video_codec_found}")
@@ -525,14 +500,9 @@
packages=find_packages(exclude=("test",)),
package_data={package_name: ["*.dll", "*.dylib", "*.so"]},
zip_safe=False,
- install_requires=requirements,
extras_require={
"scipy": ["scipy"],
},
use_video_codec = use_video_codec and video_codec_found
if (
@@ -547,7 +531,6 @@
ext_modules=get_extensions(),
python_requires=">=3.7",
- cmdclass={
python_requires=">=3.8",
cmdclass={
- "build_ext": BuildExtension.with_options(no_python_abi_suffix=True),
- "clean": clean,
- },
"clean": clean,
},
)