summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/detectron2/default.nix
blob: 2a7fb8b7d9aabf7b3166cb4fd605330886d4e0db (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
{
  stdenv,
  lib,
  buildPythonPackage,
  fetchFromGitHub,

  # nativeBuildInputs
  ninja,
  which,

  # buildInputs
  pybind11,

  # dependencies
  black,
  cloudpickle,
  fvcore,
  hydra-core,
  iopath,
  matplotlib,
  omegaconf,
  packaging,
  pillow,
  pycocotools,
  pydot,
  tabulate,
  tensorboard,
  termcolor,
  torch,
  tqdm,
  yacs,

  # optional-dependencies
  fairscale,
  psutil,
  pygments,
  scipy,
  shapely,
  timm,

  # tests
  av,
  opencv4,
  pytest-mock,
  pytestCheckHook,
  torchvision,
}:

let
  pname = "detectron2";
  version = "0.6";
in
buildPythonPackage {
  inherit pname version;
  pyproject = true;

  src = fetchFromGitHub {
    owner = "facebookresearch";
    repo = "detectron2";
    tag = "v${version}";
    hash = "sha256-TosuUZ1hJrXF3VGzsGO2hmQJitGUxe7FyZyKjNh+zPA=";
  };

  postPatch =
    # https://github.com/facebookresearch/detectron2/issues/5010
    ''
      substituteInPlace detectron2/data/transforms/transform.py \
        --replace-fail "interp=Image.LINEAR" "interp=Image.BILINEAR"
    '';

  nativeBuildInputs = [
    ninja
    which
  ];

  buildInputs = [ pybind11 ];

  pythonRelaxDeps = [
    "black"
    "iopath"
  ];

  pythonRemoveDeps = [
    "future"
  ];

  dependencies = [
    black
    cloudpickle
    fvcore
    hydra-core
    iopath
    matplotlib
    omegaconf
    packaging
    pillow
    pycocotools
    pydot # no idea why this is not in their setup.py
    tabulate
    tensorboard
    termcolor
    torch # not explicitly declared in setup.py because they expect you to install it yourself
    tqdm
    yacs
  ];

  optional-dependencies = {
    all = [
      fairscale
      timm
      scipy
      shapely
      pygments
      psutil
    ];
  };

  nativeCheckInputs = [
    av
    opencv4
    pytest-mock
    pytestCheckHook
    torchvision
  ];

  preCheck =
    # prevent import errors for C extension modules
    ''
      rm -r detectron2
    '';

  enabledTestPaths = [
    # prevent include $sourceRoot/projects/*/tests
    "tests"
  ];

  disabledTestPaths = [
    # try import caffe2
    "tests/test_export_torchscript.py"
    "tests/test_model_analysis.py"
    "tests/modeling/test_backbone.py"
    "tests/modeling/test_roi_heads.py"
    "tests/modeling/test_rpn.py"
    "tests/structures/test_instances.py"
    # hangs for some reason
    "tests/modeling/test_model_e2e.py"
    # KeyError: 'precision'
    "tests/data/test_coco_evaluation.py"
  ];

  disabledTests = [
    # fails for some reason
    "test_checkpoint_resume"
    "test_map_style"
    # requires shapely
    "test_resize_and_crop"
    # require caffe2
    "test_predict_boxes_tracing"
    "test_predict_probs_tracing"
    "testMaskRCNN"
    "testRetinaNet"
    # require coco dataset
    "test_default_trainer"
    "test_unknown_category"
    "test_build_dataloader_train"
    "test_build_iterable_dataloader_train"
    # require network access
    "test_opencv_exif_orientation"
    "test_read_exif_orientation"
    # use deprecated api, numpy.bool
    "test_BWmode_nomask"
    "test_draw_binary_mask"
    "test_draw_empty_mask_predictions"
    "test_draw_instance_predictions"
    "test_draw_no_metadata"
    "test_overlay_instances"
    "test_overlay_instances_no_boxes"
    "test_get_bounding_box"
  ]
  ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
    "test_build_batch_dataloader_inference"
    "test_build_dataloader_inference"
    "test_build_iterable_dataloader_inference"
    "test_to_iterable"
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    # RuntimeError: required keyword attribute 'value' has the wrong type
    "test_apply_deltas_tracing"
    "test_imagelist_padding_tracing"
    "test_roi_pooler_tracing"
  ];

  pythonImportsCheck = [ "detectron2" ];

  meta = {
    description = "Facebooks's next-generation platform for object detection, segmentation and other visual recognition tasks";
    homepage = "https://github.com/facebookresearch/detectron2";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ happysalada ];
  };
}