summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 38c84d359d5bf558a61590951596dfddba5571d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Maintainer: Butui Hu <hot123tea123@gmail.com>

_CUDA_ARCH_LIST="6.0;6.1;6.2;7.0;7.2;7.5;8.0;8.6;8.6;8.9;9.0;9.0+PTX"
pkgname=(python-detectron2 python-detectron2-cuda)
_pkgname=detectron2
pkgver=0.6
pkgrel=10
pkgdesc="FAIR's next-generation platform for object detection and segmentation"
arch=('x86_64')
url='https://github.com/facebookresearch/detectron2'
license=('Apache-2.0')
depends=(
  gcc-libs
  glibc
  python-cloudpickle
  python-future
  python-fvcore
  python-hydra-core
  python-iopath
  python-matplotlib
  python-omegaconf
  python-opencv
  python-pillow
  python-pycocotools
  python-pydot
  python-shapely
  python-sympy
  python-tabulate
  python-termcolor
  python-tqdm
  python-yacs
  tensorboard
)
makedepends=(
  cuda
  numactl
  python-build
  python-installer
  python-setuptools
  python-wheel
  python-pytorch-cuda
)
source=("${_pkgname}-${pkgver}.tar.gz::https://github.com/facebookresearch/detectron2/archive/v${pkgver}.tar.gz"
        "0001-fix-building-torch-extension-with-glog.patch"
)
sha256sums=('9757fed05fa32acc2116ea038185f08409d5e854573e70f41909a358b70d1004'
            'b658be8e329604a2cdb9529b40c1389719054da61a831b76f7ee203c8bec2537')

prepare() {
  cd ${_pkgname}-${pkgver}
  patch -p1 -i "${srcdir}/0001-fix-building-torch-extension-with-glog.patch"
  cp -a "${srcdir}/${_pkgname}-${pkgver}" "${srcdir}/python-${_pkgname}-${pkgver}"
  cp -a "${srcdir}/${_pkgname}-${pkgver}" "${srcdir}/python-${_pkgname}-cuda-${pkgver}"
}

build() {
  cd "${srcdir}/python-${_pkgname}-${pkgver}"
  python -m build --wheel --no-isolation

  cd "${srcdir}/python-${_pkgname}-cuda-${pkgver}"
  TORCH_CUDA_ARCH_LIST=${_CUDA_ARCH_LIST} \
  FORCE_CUDA=1 \
  python -m build --wheel --no-isolation
}

package_python-detectron2() {
  depends+=(
    python-pytorch
  )
  cd "${srcdir}/python-${_pkgname}-${pkgver}"
  python -m installer --destdir="${pkgdir}" dist/*.whl
  # remove unused files
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  rm -rfv ${pkgdir}${site_packages}/tools
}

package_python-detectron2-cuda() {
  pkgdesc="${pkgdesc} (with CUDA)"
  depends+=(
    cuda
    libcudart.so
    python-pytorch-cuda
  )
  provides=(python-detectron2=${pkgver})
  conflicts=(python-detectron2)
  cd "${srcdir}/python-${_pkgname}-cuda-${pkgver}"
  TORCH_CUDA_ARCH_LIST=${_CUDA_ARCH_LIST} \
  FORCE_CUDA=1 \
  python -m installer --destdir="${pkgdir}" dist/*.whl
  # remove unused files
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  rm -rfv ${pkgdir}${site_packages}/tools
}
# vim:set ts=2 sw=2 et: