yhygao / CBIM-Medical-Image-Segmentation

A PyTorch framework for medical image segmentation
Apache License 2.0
272 stars 48 forks source link

update inference code #11

Closed ruida closed 1 year ago

ruida commented 2 years ago

Could you update the full code fragment for inference? Save the predicted maps, etc. Thanks.

yhygao commented 2 years ago

Thanks for your interest in our work. I'll update the full inference code later, e.g. including preprocessing, model prediction, post-processing, and storing the prediction. The thing is for different datasets, their pre-processing operations are different. I need to find a way to integrate them together.

ruida commented 2 years ago

Hi, Gao, Could you update the code for

Thanks,

--Ruida

On Thu, Sep 15, 2022 at 3:05 PM yhygao @.***> wrote:

Thanks for your interest in our work. I'll update the full inference code later, e.g. including preprocessing, model prediction, post-processing, and storing the prediction. The thing is for different datasets, their pre-processing operations are different. I need to find a way to integrate them together.

— Reply to this email directly, view it on GitHub https://github.com/yhygao/CBIM-Medical-Image-Segmentation/issues/11#issuecomment-1248492655, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOP5YH5UH6IVHDAXCE6E6DV6NXOHANCNFSM56XKZDLQ . You are receiving this because you authored the thread.Message ID: @.***>

yhygao commented 1 year ago

See this issue #16

ruida commented 1 year ago

Hi, Gao,

I just saw this email. Thanks very much for updating me. Could you help me to update the code for 2D image prediction? 3D works, 2D seems not working.

Thanks,

--Ruida

On Wed, Mar 1, 2023 at 8:28 PM yhygao @.***> wrote:

Closed #11 https://github.com/yhygao/CBIM-Medical-Image-Segmentation/issues/11 as completed.

— Reply to this email directly, view it on GitHub https://github.com/yhygao/CBIM-Medical-Image-Segmentation/issues/11#event-8644424191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOP5YGOC56NT4FJEQIVA6DWZ7ZUNANCNFSM56XKZDLQ . You are receiving this because you authored the thread.Message ID: <yhygao/CBIM-Medical-Image-Segmentation/issue/11/issue_event/8644424191@ github.com>

yhygao commented 1 year ago

Yeah, I haven't test the 2D inference yet. If you have an urgent case and need the inference code, you can fix it with the modifications I mentioned in #19. If it's not urgent. I'll fix it later this week.

ruida commented 1 year ago

Hi, Gao,

I modify the sliding window scenario, and change the tensor shape. The predicted maps do not look right. Something went wrong. Could you look into the issue ASAP?

Thanks,

--Ruida

On Mon, Apr 3, 2023 at 11:03 AM yhygao @.***> wrote:

Yeah, I haven't test the 2D inference yet. If you have an urgent case and need the inference code, you can fix it with the modifications I mentioned in #19 https://github.com/yhygao/CBIM-Medical-Image-Segmentation/issues/19. If it's not urgent. I'll fix it later this week.

— Reply to this email directly, view it on GitHub https://github.com/yhygao/CBIM-Medical-Image-Segmentation/issues/11#issuecomment-1494494801, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOP5YEGDG5JRU237BNQPQLW7LRFJANCNFSM56XKZDLQ . You are receiving this because you authored the thread.Message ID: @.***>

yhygao commented 1 year ago

I got it. Will update it this week.

yhygao commented 1 year ago

I've pushed a new update. The new prediction.py supports both 2D and 3D inference. The previous version has a bug that calls Softmax twice. That's might be why your modification still has the wrong prediction. I've fixed it and tested it on ACDC. It works well in both 2D and 3D settings. You can try it to see if it fixes your problem.

ruida commented 1 year ago

Hi, Gao,

Thanks for the update. I encountered a few issues with the update. I use your new prediction code, the generated feature map is empty. Then, I use your new updated training code ( rebuild the conda environment) to train the model, I got bus errors (on console window, can't debug into it) on both A100x and V100x cards. Not sure, what is happening. I will continue working on those issues.

Thanks,

--Ruida

On Mon, Apr 10, 2023 at 2:49 AM yhygao @.***> wrote:

I've pushed a new update. The new prediction.py supports both 2D and 3D inference. The previous version has a bug that calls Softmax twice. That's might be why your modification still has the wrong prediction. I've fixed it and tested it on ACDC. It works well in both 2D and 3D settings. You can try it to see if it fixes your problem.

— Reply to this email directly, view it on GitHub https://github.com/yhygao/CBIM-Medical-Image-Segmentation/issues/11#issuecomment-1501465929, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOP5YCQ3VRJ6Q77BKEL4C3XAOUOZANCNFSM56XKZDLQ . You are receiving this because you authored the thread.Message ID: @.***>

yhygao commented 1 year ago

I also got bus error one or two times when using PyTorch2.0. I don't exactly know what happens, but starting a new terminal and reactivating the conda environment can solve that problem.

If it still can't solve the problem, you can use PyTorch1.13 to train the model without any problem, as 2.0 and the previous versions are totally compatible. The only difference is you can't use torch.compile for acceleration. In my experience, in ACDC 2d setting, using torch.compile offers around 20% less time per iteration. Combining torch.compile and amp is over 30% faster.

If you still have issues and want me to help. Please provide more context such that I can reproduce the problem.

ruida commented 1 year ago

Hi, Gao,

I use the old conda environment with your new update. Retrain and test, the prediction code (2D) works now for my projects. Thanks much!!! For the newly build conda environment. I was able to work around the bus error. I figure it is caused by the deep copying. However, during the training phase, I got loss function errors from pytorch. Still need to work on it.

Thanks much for updating me with the 2D prediction code!

Best,

--Ruida

On Tue, Apr 11, 2023 at 12:29 PM yhygao @.***> wrote:

I also got bus error one or two times when using PyTorch2.0. I don't exactly know what happens, but starting a new terminal and reactivating the conda environment can solve that problem.

If it still can't solve the problem, you can use PyTorch1.13 to train the model without any problem, as 2.0 and the previous versions are totally compatible. The only difference is you can't use torch.compile for acceleration. In my experience, in ACDC 2d setting, using torch.compile offers around 20% less time per iteration. Combining torch.compile and amp is over 30% faster.

If you still have issues and want me to help. Please provide more context such that I can reproduce the problem.

— Reply to this email directly, view it on GitHub https://github.com/yhygao/CBIM-Medical-Image-Segmentation/issues/11#issuecomment-1503727295, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOP5YA23SAPSR2K3O43HZDXAWBGXANCNFSM56XKZDLQ . You are receiving this because you authored the thread.Message ID: @.***>

yhygao commented 1 year ago

I'm happy that it works :)