-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash when calling MacenkoNormalizer.fit with tensorflow backend #37
Comments
Hello, @bertrandchauveau! I had this issue when making this myself, so no worries :] You can take a look at what is done in the tests here. Basically, do this instead:
Could you try this first to see if it resolves you issue? I'm a bit occupied right now, but could take a new look tomorrow, if you are still having issues. This will be better documented in the upcoming release, which includes some new and interested stain normalization techniques and new backends (see here). BTW: What is the status on the release, @carloalbertobarbano? Shall we aim to get it released by next week? I have a master student who would be interested in the new modified reinhard implementation. |
Thank you for your quick response! Sadly the same problem occurs, i.e. crashes when running:
the "T" conversion does the same as my attempt of tf tensor conversion |
Hmm, well, what I described above is what we do in the unit test, so that should work. Could you show me the error log from the terminal? Also, could you try downloading the test data that we used for the unit tests here and here, and try running them through your code. I believe that should work. If that works, then the intensity range of your image after imread is in the wrong range. You can see the intensity range by running Also, I noticed that you were a pathologists. If you just want to get a method working, I would recommend trying the command line tool fast-stain-normalization that is based on torchstain. It enables you to normalize an entire folder without needing to code. Just provide arguments to a CLI and run it from the terminal. You can see how to use it here. |
I had the same issue with the test images that you provided. This is the error message from the terminal:
I tried this kind of things from what I saw from stackoverflow, but the kernel still crashes:
As I understand it, Tensorflow tries to place the tensors on the GPU, but for whatever reason, it does not work (as you said, I'm a pathologist.) For note, I have an RTX 4090 in a Windows setup and I have not encountered similar issues when tranining deep learning models. So by forcing Tensorflow to use the CPU with:
It works as intended. Should it also work with the GPU? |
I was unable to reproduce your issue. See gist. What you are observing I'm guessing is likely related to the First I would try disabling TensorFloats, by adding this to the top of your script (after tf import): If that did not fix the issue, try installing the nightly release of TF to see if this has been fixed recently:
|
Thank you for your response. Agree that it works nicely in colab. On my local machine, I disabled TensorFloat-32 with : But the kernel still crashes when fitting the normalizer. My initial idea (perhaps not a good one) for my project was to use torchstain to normalize images on the fly using a custom data generator, this to avoid the duplication of the dataset (normalized and non-normalized). For now, I will duplicate my dataset, as relying on the CPU for normalization slows down the batch preparation pretty much. I’ll give it a try when I’m ready to upgrade tensorflow or will try with pytorch which seems less windows-phobic. |
Hi @bertrandchauveau, what version of CUDA and cuDNN are you using? |
That's exactly what I do in my training frameworks and that works just fine. As long as you are using I don't really work on windows for training models anymore. Note that multithreading does not work as well on windows, as for UNIX-based systems.
I guess as you seem to be using anaconda, you have installed CUDA through something like this. As I said, I don't have that much experience with conda, as I don't use it myself, but I guess @carloalbertobarbano can help you on that. |
Hi @carloalbertobarbano, |
@bertrandchauveau Are you still experiencing issues? |
Hi,
It works when I force torchstain to work on the CPU. With tf.data.Dataset, it is true that there is not much lag during pure training (about +10% for me as compared to no stain normalization) but the validation step after each training epoch is much longer.
I should have a bit more time this week to see why sometimes it seems to work with the modified Reinhard method. |
AFAIK, there does not yet exist a precompiled binary of tf 2.12 on windows, so I believe that might result in some issues. But if you are using WSL it should work better. You could post the error messages you are getting and I could try to debug it for you. Note that I believe you need a nightly release, as the GPU you have might be too new, as discussed above.
Why it sometimes works and sometimes fails does not make much sense to me. Have you tried not using Anaconda and just regular Python virtual environments? You will need to setup CUDA yourself then. |
Hi,
I am sorry if my question is trivial but I have trouble using this package with the tensorflow backend.
Using torchstain 1.2.0, I have no problem performing a Macenko normalization with numpy. But as I try with tensorflow, it crashes using normalizer.fit
The only thing that I am doing differently from the provided example is the tensor conversion of the numpy array.
That is, I am not doing this
But rather tried this to match the transformation:
Is this why it crashes ? Is there a way to run this without using torchvision.transforms/on a pure TF basis?
I am using Tensorflow_2.10.0 and have installed torchstain using pip install torchstain[tf].
I currently do not use nor have installed torchvision in my TF environment.
Thank you for your advice
The text was updated successfully, but these errors were encountered: