2023-03-15 16:39:30 +00:00
|
|
|
{ buildPythonPackage
|
2021-01-05 17:05:55 +00:00
|
|
|
, fetchFromGitHub
|
2023-03-15 16:39:30 +00:00
|
|
|
, lib
|
2021-01-05 17:05:55 +00:00
|
|
|
, libjpeg_turbo
|
|
|
|
, libpng
|
2023-03-15 16:39:30 +00:00
|
|
|
, ninja
|
2020-04-24 23:36:52 +00:00
|
|
|
, numpy
|
|
|
|
, pillow
|
2021-01-05 17:05:55 +00:00
|
|
|
, pytest
|
2023-03-15 16:39:30 +00:00
|
|
|
, scipy
|
|
|
|
, torch
|
|
|
|
, which
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
2021-08-08 23:34:03 +00:00
|
|
|
let
|
2023-03-24 00:07:29 +00:00
|
|
|
inherit (torch) cudaCapabilities cudaPackages cudaSupport;
|
2024-01-02 11:29:13 +00:00
|
|
|
inherit (cudaPackages) backendStdenv;
|
2023-03-15 16:39:30 +00:00
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
pname = "torchvision";
|
2024-01-02 11:29:13 +00:00
|
|
|
version = "0.16.2";
|
2023-03-15 16:39:30 +00:00
|
|
|
in
|
|
|
|
buildPythonPackage {
|
|
|
|
inherit pname version;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "pytorch";
|
|
|
|
repo = "vision";
|
2022-08-12 12:06:08 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2024-01-02 11:29:13 +00:00
|
|
|
hash = "sha256-fSFoMZbF0bYqonvgoNAE8ZzwCsjhCdVo2BJ0pOC2zd0=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
libpng
|
|
|
|
ninja
|
|
|
|
which
|
|
|
|
] ++ lib.optionals cudaSupport [
|
|
|
|
cudaPackages.cuda_nvcc
|
|
|
|
];
|
2021-01-05 17:05:55 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
buildInputs = [ libjpeg_turbo libpng torch.cxxdev ];
|
2021-01-05 17:05:55 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
propagatedBuildInputs = [ numpy pillow torch scipy ];
|
2021-01-05 17:05:55 +00:00
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
preConfigure = ''
|
|
|
|
export TORCHVISION_INCLUDE="${libjpeg_turbo.dev}/include/"
|
|
|
|
export TORCHVISION_LIBRARY="${libjpeg_turbo}/lib/"
|
|
|
|
''
|
|
|
|
# NOTE: We essentially override the compilers provided by stdenv because we don't have a hook
|
|
|
|
# for cudaPackages to swap in compilers supported by NVCC.
|
|
|
|
+ lib.optionalString cudaSupport ''
|
2023-03-24 00:07:29 +00:00
|
|
|
export CC=${backendStdenv.cc}/bin/cc
|
|
|
|
export CXX=${backendStdenv.cc}/bin/c++
|
|
|
|
export TORCH_CUDA_ARCH_LIST="${lib.concatStringsSep ";" cudaCapabilities}"
|
2021-08-08 23:34:03 +00:00
|
|
|
export FORCE_CUDA=1
|
|
|
|
'';
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
# tries to download many datasets for tests
|
|
|
|
doCheck = false;
|
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
pythonImportsCheck = [ "torchvision" ];
|
2021-01-05 17:05:55 +00:00
|
|
|
checkPhase = ''
|
|
|
|
HOME=$TMPDIR py.test test --ignore=test/test_datasets_download.py
|
|
|
|
'';
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [ pytest ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "PyTorch vision library";
|
2021-01-05 17:05:55 +00:00
|
|
|
homepage = "https://pytorch.org/";
|
|
|
|
license = licenses.bsd3;
|
2021-08-08 23:34:03 +00:00
|
|
|
platforms = with platforms; linux ++ lib.optionals (!cudaSupport) darwin;
|
2021-02-17 17:02:09 +00:00
|
|
|
maintainers = with maintainers; [ ericsagnes ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|