1{ stdenv
2, lib
3, buildPythonPackage
4, fetchFromGitHub
5, pythonRelaxDepsHook
6, ninja
7, which
8# build inputs
9, pillow
10, matplotlib
11, pycocotools
12, termcolor
13, yacs
14, tabulate
15, cloudpickle
16, tqdm
17, tensorboard
18, fvcore
19, iopath
20, omegaconf
21, hydra-core
22, packaging
23, torch
24, pydot
25, black
26# optional dependencies
27, fairscale
28, timm
29, scipy
30, shapely
31, pygments
32, psutil
33# check inputs
34, pytestCheckHook
35, torchvision
36, av
37, opencv4
38, pytest-mock
39, pybind11
40}:
41
42let
43 pname = "detectron2";
44 version = "0.6";
45 optional-dependencies = {
46 all = [
47 fairscale
48 timm
49 scipy
50 shapely
51 pygments
52 psutil
53 ];
54 };
55in
56buildPythonPackage {
57 inherit pname version;
58 format = "setuptools";
59
60 src = fetchFromGitHub {
61 owner = "facebookresearch";
62 repo = "detectron2";
63 rev = "refs/tags/v${version}";
64 sha256 = "1w6cgvc8r2lwr72yxicls650jr46nriv1csivp2va9k1km8jx2sf";
65 };
66
67 postPatch = ''
68 # https://github.com/facebookresearch/detectron2/issues/5010
69 substituteInPlace detectron2/data/transforms/transform.py \
70 --replace "interp=Image.LINEAR" "interp=Image.BILINEAR"
71 '';
72
73 nativeBuildInputs = [
74 pythonRelaxDepsHook
75 ninja
76 which
77 ];
78
79 buildInputs = [ pybind11 ];
80
81 pythonRelaxDeps = [
82 "black"
83 ];
84
85 propagatedBuildInputs = [
86 pillow
87 matplotlib
88 pycocotools
89 termcolor
90 yacs
91 tabulate
92 cloudpickle
93 tqdm
94 tensorboard
95 fvcore
96 iopath
97 omegaconf
98 hydra-core
99 packaging
100 black
101 torch # not explicitly declared in setup.py because they expect you to install it yourself
102 pydot # no idea why this is not in their setup.py
103 ];
104
105 passthru.optional-dependencies = optional-dependencies;
106
107 nativeCheckInputs = [
108 av
109 opencv4
110 pytest-mock
111 pytestCheckHook
112 torchvision
113 ];
114
115 preCheck = ''
116 # prevent import errors for C extension modules
117 rm -r detectron2
118 '';
119
120 pytestFlagsArray = [
121 # prevent include $sourceRoot/projects/*/tests
122 "tests"
123 ];
124
125 disabledTestPaths = [
126 # try import caffe2
127 "tests/test_export_torchscript.py"
128 "tests/test_model_analysis.py"
129 "tests/modeling/test_backbone.py"
130 "tests/modeling/test_roi_heads.py"
131 "tests/modeling/test_rpn.py"
132 "tests/structures/test_instances.py"
133 # hangs for some reason
134 "tests/modeling/test_model_e2e.py"
135 # KeyError: 'precision'
136 "tests/data/test_coco_evaluation.py"
137 ];
138
139 disabledTests = [
140 # fails for some reason
141 "test_checkpoint_resume"
142 "test_map_style"
143 # requires shapely
144 "test_resize_and_crop"
145 # require caffe2
146 "test_predict_boxes_tracing"
147 "test_predict_probs_tracing"
148 "testMaskRCNN"
149 "testRetinaNet"
150 # require coco dataset
151 "test_default_trainer"
152 "test_unknown_category"
153 "test_build_dataloader_train"
154 "test_build_iterable_dataloader_train"
155 # require network access
156 "test_opencv_exif_orientation"
157 "test_read_exif_orientation"
158 # use deprecated api, numpy.bool
159 "test_BWmode_nomask"
160 "test_draw_binary_mask"
161 "test_draw_empty_mask_predictions"
162 "test_draw_instance_predictions"
163 "test_draw_no_metadata"
164 "test_overlay_instances"
165 "test_overlay_instances_no_boxes"
166 "test_get_bounding_box"
167 ] ++ lib.optionals (stdenv.isLinux && stdenv.isAarch64) [
168 "test_build_batch_dataloader_inference"
169 "test_build_dataloader_inference"
170 "test_build_iterable_dataloader_inference"
171 "test_to_iterable"
172 ];
173
174 pythonImportsCheck = [ "detectron2" ];
175
176 meta = with lib; {
177 description = "Facebooks's next-generation platform for object detection, segmentation and other visual recognition tasks";
178 homepage = "https://github.com/facebookresearch/detectron2";
179 license = licenses.asl20;
180 maintainers = with maintainers; [ happysalada ];
181 };
182}