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