1{
2 lib,
3 buildPythonPackage,
4 pythonOlder,
5 fetchPypi,
6 setuptools,
7 matplotlib,
8 numpy,
9 opencv4,
10 pillow,
11 scikit-learn,
12 torch,
13 torchvision,
14 ttach,
15 tqdm,
16}:
17
18buildPythonPackage rec {
19 pname = "grad-cam";
20 version = "1.5.2";
21 pyproject = true;
22
23 disabled = pythonOlder "3.8";
24
25 src = fetchPypi {
26 inherit pname version;
27 hash = "sha256-WhC3QjMDh4E8NnO8SyCtg9rFgDJkYP6/xdWNcTvlKFU=";
28 };
29
30 postPatch = ''
31 substituteInPlace requirements.txt\
32 --replace "opencv-python" "opencv"
33 '';
34
35 nativeBuildInputs = [
36 ];
37
38 pythonRelaxDeps = [
39 "torchvision"
40 ];
41
42 build-system = [
43 setuptools
44 ];
45
46 dependencies = [
47 matplotlib
48 numpy
49 opencv4
50 pillow
51 scikit-learn
52 torchvision
53 ttach
54 tqdm
55 ];
56
57 # Let the user bring their own instance (as with torchmetrics)
58 buildInputs = [ torch ];
59
60 doCheck = false; # every nontrivial test tries to download a pretrained model
61
62 pythonImportsCheck = [
63 "pytorch_grad_cam"
64 "pytorch_grad_cam.metrics"
65 "pytorch_grad_cam.metrics.cam_mult_image"
66 "pytorch_grad_cam.metrics.road"
67 "pytorch_grad_cam.utils"
68 "pytorch_grad_cam.utils.image"
69 "pytorch_grad_cam.utils.model_targets"
70 ];
71
72 meta = {
73 description = "Advanced AI explainability for computer vision";
74 homepage = "https://jacobgil.github.io/pytorch-gradcam-book";
75 license = lib.licenses.mit;
76 maintainers = with lib.maintainers; [ bcdarwin ];
77 };
78}