ByungKwanLee / Causal-Unsupervised-Segmentation

Official PyTorch Implementation code for realizing the technical part of Causal Unsupervised Semantic sEgmentation (CAUSE) to improve performance of unsupervised semantic segmentation. (Under Review)
13 stars 2 forks source link

The program stuct when it finetunes the segmentation with CRF #4

Open JizeCao opened 1 year ago

JizeCao commented 1 year ago

I runed the test_tr.py file and the program stuct when it finetunes the segmentation with CRF.

https://github.com/ByungKwanLee/Causal-Unsupervised-Segmentation/blob/48e6459d4f9f57ba732084d230a13c0ada70c6df/test_tr.py#L37

How can I facilitate this process?

ByungKwanLee commented 1 year ago

I had an equal issue, then I tried to remove the conda environment and this issue was addressed by re-creating conda environment

I have had no idea why it is sparsely happening.

It seems the library collision between pydensecrf library and torch library I guess or .. any probable server envrionment things..

I hope updating pytorch library for the latest version is one of the plausible ways to address it.

JizeCao commented 1 year ago

I had an equal issue, then I tried to remove the conda environment and this issue was addressed by re-creating conda environment

I have had no idea why it is sparsely happening.

It seems the library collision between pydensecrf library and torch library I guess or .. any probable server envrionment things..

I hope updating pytorch library for the latest version is one of the plausible ways to address it.

I tried to resolve this issue through conda (uninstall pydensecry and reinstall it through conda), and the conda will install a cpu-only version torch for pydensecry (overwrite the original torch package). I think there might be a version of torch that can work for both pydensecry and gpu-version torch. Would you like to tell me which version of torch using for this work?

ByungKwanLee commented 1 year ago

torch==2.0.1 torchvision==0.15.2 torchmetrics==1.1.0 pydensecrf==1.0rc3

JizeCao commented 1 year ago

torch==2.0.1 torchvision==0.15.2 torchmetrics==1.1.0 pydensecrf==1.0rc3

Thanks! I finally make it work by installing pydensecrf with a downgraded version of cython, (https://github.com/lucasb-eyer/pydensecrf/pull/124), and rewrite the do_crf function without multiprocessing.

def do_crf(img_tensor, prob_tensor, max_iter=10): 
    outputs = []
    for img, prob in zip(img_tensor.detach().cpu(), prob_tensor.detach().cpu()):
        outputs.append(_apply_crf((img, prob), max_iter=max_iter))
    return torch.cat([torch.from_numpy(arr).unsqueeze(0) for arr in outputs], dim=0)

I believe that someone can make it work even when do_crf function is multiprocessing, but I am good to go :).