Skip to content

Commit 4246abc

Browse files
andfoyr-zenine
andauthored
PR: Read JPEG images directly (#2388)
* Add libpng requirement into conda recipe * Try to install libjpeg-turbo * Add PNG reading capabilities * Remove newline * Add image extension to compilation instructions * Include png functions as part of the main library * Update CMakeLists * Detect if building on conda-build * Debug * More debug messages * Print globbed libreries * Print globbed libreries * Point to correct PNG path * Remove libJPEG preventively * Debug extension loading * Link libpng explicitly * Link with PNG * Add PNG reading capabilities * Add libpng requirement into conda recipe * Try to install libjpeg-turbo * Remove newline * Add image extension to compilation instructions * Include png functions as part of the main library * Update CMakeLists * Detect if building on conda-build * Debug * More debug messages * Print globbed libreries * Print globbed libreries * Point to correct PNG path * Remove libJPEG preventively * Debug extension loading * Link libpng explicitly * Link with PNG * Install libpng on conda-based wheel distributions * Add -y flag * Add -y flag to yum * Locate LibPNG on windows conda * Remove empty else * Copy libpng16.so * Copy dylib on Mac * Improve check on Windows * Try to install ninja using conda on windows * Use libpng on Windows * Package lib on windows wheel * Point library to the correct place * Include binaries as part of wheel * Copy libpng.so on linux * Look for png.h on Windows when using conda-build * Do not skip png tests on Mac/Win * Restore libjpeg-turbo * Install jpeg-turbo on wheel distributions * Install libjpeg-turbo from conda-forge on wheel distributions * Do not pull av on conda-build * Add pillow disclaimer * Vendors libjpeg-turbo 2.0.4 * Merge JPEG work * Remove submodules * Regenerate circle config * Fix style issues * Fix C++ style issues * More style corrections * Add JPEG-turbo to linking libraries * More style corrections * More style corrections * More style corrections * Install libjpeg-turbo-devel * Install libturbo-jpeg on typing pipeline * Update Circle template * Windows and Unix turbojpeg have the same linking name * Install turbojpeg-devel instead of libjpeg-turbo * Copy TurboJPEG binaries to wheel * Move test image * Move back test image * Update JPEG test path * Remove dot from extension * Move image functions to extension * Use stdout arg in subprocess * Disable image extension if libpng or turbojpeg are not found * Append libpng stdout * Prevent list appending on lists * Minor path correction * Minor error correction * Add linking flags * Style issues correction * Address minor review corrections * Refactor library search * Restore access index * Fix JPEG tests * Update libpng version in Travis * Add -y flag * Remove dot * Update libpng using apt * Check libpng version * Change libturbojpeg binary * Update import * Change call * Restore av in conda recipe * Minor error correction * Remove unused comment in travis.yml * Update README * Fix missing links * Remove fixes for 16.04 * Enable JPEG support using libjpeg directly * Install libjpeg-turbo8 on Travis * Fix styling issues * Do not append to paths if library found in standard library locations * Add macro flag * Use custom error handler * Use 3? * Use short-lived buffer * Return TRUE instead of true * Assert RuntimeError * Use .jpg extension * Remove conda-forge * Use data_ptr instead of accessor * Use assertTrue for jpeg verification * Remove unnecessary memcpy * Debug test on Windows * Remove PIL from jpeg verification Co-authored-by: Ryad ZENINE <[email protected]>
1 parent 4433a5b commit 4246abc

File tree

19 files changed

+252
-11
lines changed

19 files changed

+252
-11
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ jobs:
107107
- checkout
108108
- run:
109109
command: |
110+
sudo apt-get update -y
111+
sudo apt install -y libturbojpeg-dev
110112
pip install --user --progress-bar off numpy mypy
111113
pip install --user --progress-bar off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
112114
pip install --user --progress-bar off --editable .

.circleci/config.yml.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ jobs:
107107
- checkout
108108
- run:
109109
command: |
110+
sudo apt-get update -y
111+
sudo apt install -y libturbojpeg-dev
110112
pip install --user --progress-bar off numpy mypy
111113
pip install --user --progress-bar off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
112114
pip install --user --progress-bar off --editable .

.circleci/unittest/linux/scripts/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dependencies:
77
- codecov
88
- pip
99
- libpng
10+
- jpeg
1011
- ca-certificates
1112
- pip:
1213
- future

.circleci/unittest/windows/scripts/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dependencies:
77
- codecov
88
- pip
99
- libpng
10+
- jpeg
1011
- ca-certificates
1112
- pip:
1213
- future

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
before_install:
1515
- sudo apt-get update
16-
- sudo apt-get install -y libpng-dev
16+
- sudo apt-get install -y libpng-dev libjpeg-turbo8-dev
1717
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
1818
- bash miniconda.sh -b -p $HOME/miniconda
1919
- export PATH="$HOME/miniconda/bin:$PATH"

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ find_package(Python3 COMPONENTS Development)
1414

1515
find_package(Torch REQUIRED)
1616
find_package(PNG REQUIRED)
17+
find_package(JPEG REQUIRED)
1718

1819

1920
file(GLOB HEADERS torchvision/csrc/*.h)
@@ -28,12 +29,12 @@ file(GLOB MODELS_HEADERS torchvision/csrc/models/*.h)
2829
file(GLOB MODELS_SOURCES torchvision/csrc/models/*.h torchvision/csrc/models/*.cpp)
2930

3031
add_library(${PROJECT_NAME} SHARED ${MODELS_SOURCES} ${OPERATOR_SOURCES} ${IMAGE_SOURCES})
31-
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} ${PNG_LIBRARY} Python3::Python)
32+
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} ${PNG_LIBRARY} ${JPEG_LIBRARIES} Python3::Python)
3233
# target_link_libraries(${PROJECT_NAME} PRIVATE ${PNG_LIBRARY} Python3::Python)
3334
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchVision)
3435

3536
target_include_directories(${PROJECT_NAME} INTERFACE
36-
$<BUILD_INTERFACE:${HEADERS}:${PNG_INCLUDE_DIR}>
37+
$<BUILD_INTERFACE:${HEADERS}:${PNG_INCLUDE_DIR}:${JPEG_INCLUDE_DIRS}>
3738
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
3839

3940
include(GNUInstallDirs)

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,17 @@ Torchvision currently supports the following image backends:
8080

8181
* `libpng`_ - can be installed via conda :code:`conda install libpng` or any of the package managers for debian-based and RHEL-based Linux distributions.
8282

83-
**Notes:** ``libpng`` must be available at compilation time in order to be available. Make sure that it is available on the standard library locations,
83+
* `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.
84+
85+
**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,
8486
otherwise, add the include and library paths in the environment variables ``TORCHVISION_INCLUDE`` and ``TORCHVISION_LIBRARY``, respectively.
8587

8688
.. _libpng : http://www.libpng.org/pub/png/libpng.html
8789
.. _Pillow : https://python-pillow.org/
8890
.. _Pillow-SIMD : https://github.com/uploadcare/pillow-simd
8991
.. _accimage: https://github.com/pytorch/accimage
92+
.. _libjpeg: http://ijg.org/
93+
.. _libjpeg-turbo: https://libjpeg-turbo.org/
9094

9195
C++ API
9296
=======

packaging/build_wheel.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
1919
if [[ "$(uname)" == Darwin ]]; then
2020
# Include LibPNG
2121
cp "$env_path/lib/libpng16.dylib" torchvision
22+
# Include LibJPEG
23+
cp "$env_path/lib/libjpeg.dylib" torchvision
2224
else
2325
cp "$bin_path/Library/bin/libpng16.dll" torchvision
26+
cp "$bin_path/Library/bin/libjpeg.dll" torchvision
2427
fi
2528
else
2629
# Include LibPNG
2730
cp "/usr/lib64/libpng.so" torchvision
31+
# Include LibJPEG
32+
cp "/usr/lib64/libjpeg.so" torchvision
2833
fi
2934

3035
if [[ "$OSTYPE" == "msys" ]]; then

packaging/pkg_helpers.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ setup_wheel_python() {
171171
conda create -yn "env$PYTHON_VERSION" python="$PYTHON_VERSION"
172172
conda activate "env$PYTHON_VERSION"
173173
# Install libpng from Anaconda (defaults)
174-
conda install libpng -y
174+
conda install libpng jpeg -y
175175
else
176176
# Install native CentOS libPNG
177-
yum install -y libpng-devel
177+
yum install -y libpng-devel libjpeg-turbo-devel
178178
case "$PYTHON_VERSION" in
179179
2.7)
180180
if [[ -n "$UNICODE_ABI" ]]; then

packaging/torchvision/meta.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ requirements:
99
build:
1010
- {{ compiler('c') }} # [win]
1111
- libpng
12+
- jpeg
1213

1314
host:
1415
- python
@@ -20,6 +21,7 @@ requirements:
2021
run:
2122
- python
2223
- libpng
24+
- jpeg
2325
- pillow >=4.1.1
2426
- numpy >=1.11
2527
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}

0 commit comments

Comments
 (0)