|
18 | 18 |
|
19 | 19 | Implemented using the pydense library available at https://github.com/lucasb-eyer/pydensecrf. |
20 | 20 | """ |
| 21 | + |
21 | 22 | import importlib |
22 | 23 |
|
23 | 24 | import numpy as np |
|
28 | 29 |
|
29 | 30 | spec = importlib.util.find_spec("pydensecrf") |
30 | 31 | CRF_INSTALLED = spec is not None |
31 | | -if not CRF_INSTALLED: |
32 | | - logger.info( |
33 | | - "pydensecrf not installed, CRF post-processing will not be available. " |
34 | | - "Please install by running : pip install pydensecrf " |
35 | | - "This is not a hard requirement, you do not need it to install it unless you want to use the CRF post-processing step. " |
36 | | - ) |
37 | | -else: |
| 32 | +if CRF_INSTALLED: |
38 | 33 | import pydensecrf.densecrf as dcrf |
39 | 34 | from pydensecrf.utils import ( |
40 | 35 | create_pairwise_bilateral, |
@@ -124,6 +119,11 @@ def crf(image, prob, sa, sb, sg, w1, w2, n_iter=5): |
124 | 119 | np.ndarray: Array of shape (K, H, W, D) containing the refined class probabilities for each pixel. |
125 | 120 | """ |
126 | 121 | if not CRF_INSTALLED: |
| 122 | + logger.info( |
| 123 | + "pydensecrf not installed, CRF post-processing will not be available. " |
| 124 | + "Please install by running : pip install pydensecrf@git+https://github.com/lucasb-eyer/pydensecrf.git#egg=master" |
| 125 | + "This is not a hard requirement, you do not need it to install it unless you want to use the CRF post-processing step." |
| 126 | + ) |
127 | 127 | return None |
128 | 128 |
|
129 | 129 | d = dcrf.DenseCRF( |
@@ -232,7 +232,12 @@ def __init__( |
232 | 232 | def _run_crf_job(self): |
233 | 233 | """Runs the CRF post-processing step for the W-Net.""" |
234 | 234 | if not CRF_INSTALLED: |
235 | | - raise ImportError("pydensecrf is not installed.") |
| 235 | + logger.info( |
| 236 | + "pydensecrf not installed, CRF post-processing will not be available. " |
| 237 | + "Please install by running : pip install pydensecrf@git+https://github.com/lucasb-eyer/pydensecrf.git#egg=master" |
| 238 | + "This is not a hard requirement, you do not need it to install it unless you want to use the CRF post-processing step." |
| 239 | + ) |
| 240 | + # raise ImportError("pydensecrf is not installed.") |
236 | 241 |
|
237 | 242 | if len(self.images) != len(self.labels): |
238 | 243 | raise ValueError("Number of images and labels must be the same.") |
|
0 commit comments