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