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 pytestFlagsArray = [ 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 [ 153 # fails for some reason 154 "test_checkpoint_resume" 155 "test_map_style" 156 # requires shapely 157 "test_resize_and_crop" 158 # require caffe2 159 "test_predict_boxes_tracing" 160 "test_predict_probs_tracing" 161 "testMaskRCNN" 162 "testRetinaNet" 163 # require coco dataset 164 "test_default_trainer" 165 "test_unknown_category" 166 "test_build_dataloader_train" 167 "test_build_iterable_dataloader_train" 168 # require network access 169 "test_opencv_exif_orientation" 170 "test_read_exif_orientation" 171 # use deprecated api, numpy.bool 172 "test_BWmode_nomask" 173 "test_draw_binary_mask" 174 "test_draw_empty_mask_predictions" 175 "test_draw_instance_predictions" 176 "test_draw_no_metadata" 177 "test_overlay_instances" 178 "test_overlay_instances_no_boxes" 179 "test_get_bounding_box" 180 ] 181 ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [ 182 "test_build_batch_dataloader_inference" 183 "test_build_dataloader_inference" 184 "test_build_iterable_dataloader_inference" 185 "test_to_iterable" 186 ] 187 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 188 # RuntimeError: required keyword attribute 'value' has the wrong type 189 "test_apply_deltas_tracing" 190 "test_imagelist_padding_tracing" 191 "test_roi_pooler_tracing" 192 ]; 193 194 pythonImportsCheck = [ "detectron2" ]; 195 196 meta = { 197 description = "Facebooks's next-generation platform for object detection, segmentation and other visual recognition tasks"; 198 homepage = "https://github.com/facebookresearch/detectron2"; 199 license = lib.licenses.asl20; 200 maintainers = with lib.maintainers; [ happysalada ]; 201 }; 202}