teamtomo / membrain-seg

membrane segmentation in 3D for cryo-ET
Other
47 stars 12 forks source link

Error during normalization while running membrain on WSL2 #27

Closed BhattaArjun2p closed 11 months ago

BhattaArjun2p commented 11 months ago

Hi all,

I am not sure if this is to be expected, I am having trouble running "membrain segment" on my WSL2 setup. When I run the segment command, membrain segment --tomogram-path test.mrc --ckpt-path membrain_v9_528_merged_DA_DS_run2.ckpt --out-folder predictions/ the programme crashes with ValueError: output array is read-only. From the traceback log, it looks like the programme crashes while trying to normalize the input tomogram.

Capture

Weirdly enough, this only happens to me on WSL2 — segmentation on the same tomogram works just fine on native linux.

Am I perhaps doing something wrong here? Or is WSL2 just not supported yet?

Best, Arjun

BhattaArjun2p commented 11 months ago

Update: managed to get it to run by changing the file-mode from "r" to "r+" in data_utils.py > load_tomogram module.

whanyv commented 11 months ago

Hi Arjun,

I had the same problem and changed the module according to what you said. However I am still getting this error message: "UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling". Did you get this error message as well? Would you mind telling me how you fixed this? I am using a Macbook with a intel core. Thank you so much for your help on this matter.

Best, Wendy

LorenzLamm commented 11 months ago

Hi Arjun and Wendy,

many thanks for raising these issues. Regarding the tomogram loading: I changed some things in the data loading recently and must have messed up something there. I'll convert it back to a functioning workflow. Meanwhile, you found a good fix for the issue, @BhattaArjun2p .

@whanyv Unfortunately, MemBrain-seg is optimized to be run on the GPU. As most common deep learning frameworks, it relies on the availability of CUDA, which is only really compatible with NVIDIA GPUs, which are normally not built into Macbooks. You can still run the model on CPU, but this will take quite some time. I recommend you turn off the 8-fold test time augmentation. You can currently do so by changing the script src/membrain_seg/segmentation/segment.py: for m in range(8): --> for m in range(1):

I will also add this as a functionality in an upcoming update, but currently you need to manually change the script. Sorry for that.

BhattaArjun2p commented 11 months ago

Hi Lorenz, kind of relatedly to the tomogram loading issue, I also noticed while saving the output segmentation volume, there seems to be a mismatch in the datatype in the header and in the actual data array, and trying to open the volume in imod or in python with the mrcfile module gives an error saying the expected size doesn't match the actual size of the data. I couldn't read the the header, so i don't know what the datatype in the header was originally, but at least changing the line tomogram = tomogram.astype("ubyte") to tomogram = tomogram.astype("float32") in the store_tomograms function in data_utils.py worked for now (might be overkill to save the segmentations as 32-bit floats, though).

Segmentations look very nice though! Thank you very much for the tool! :D

LorenzLamm commented 11 months ago

Ah, that's interesting. I had not expected that setting the tomogram to data type float32 would solve this problem.

I think the issue comes from a mismatch between the header of the original file, which also stores the data mode of the original file (which is probably not the data mode of the output array). I tried to address this in a current PR (https://github.com/teamtomo/membrain-seg/pull/25) and hope that it will solve the problem.

Sorry for the trouble, and great that you like the segmentations! :)

LorenzLamm commented 11 months ago

Hey @BhattaArjun2p , PR has been merged, and both your initial storing issue, and the problems with the header should be resolved now. If you find time, could you please confirm that it works, so we can close this issue?

BhattaArjun2p commented 11 months ago

Works like a charm! Thanks for the fix, Lorenz. Will close the issue :)