ANTsX / ANTsPyNet

Pre-trained models and utilities for deep learning on medical images in Python
https://antspynet.readthedocs.io
Apache License 2.0
200 stars 28 forks source link

Using ANTsPyNet for brain age prediction #71

Closed abanic7 closed 10 months ago

abanic7 commented 1 year ago

Hello, if you could spare some of your time to give me quick guidelines on how I can use ANTsPyNet for brain age prediction on a random database from the internet(specifically I have IXI T1 weighted images). I see that you have implemented kears version of SFCN also which i tried using before without your implementation and it didn't perform so well, so if u could tell me if your model works better. I'm very new to all of this, so any help would be much appreciated. Thank you in advance.

ntustison commented 1 year ago

Have you installed ANTsPy and ANTsPyNet?

abanic7 commented 1 year ago

Yes I have installed both.

ntustison commented 1 year ago

Did you run the code snippet I linked to in my email?

https://gist.github.com/ntustison/12a656a5fc2f6f9c4494c88dc09c5621#brain-age

abanic7 commented 1 year ago

I did, yes.

ntustison commented 1 year ago

Then what is precisely the issue?

abanic7 commented 1 year ago

I'm very new to this field and i don't understand how i would now use IXI database and get age predictions from those images using your model(refer to my original question).

ntustison commented 1 year ago

The IXI images are in nifti format. Use ants.image_read to read in each IXI image and apply the model to each image as shown in the example. The age estimates are in the dictionary returned by the antspynet.brain_age call.

abanic7 commented 1 year ago

Thank u so much. I have images saved as pkl files, because they have already been preprocessed, so i loaded them using pickle library and now i have just a 3d array, can the model just take the image as an array or do i have to modify it?

ntustison commented 1 year ago

The antspynet.brain_age function requires an ANTsImage as input. Ultimately, that image gets converted to a numpy array for prediction. But there's a bit of processing (e.g. ensuring the brain orientation is correct) so you can't simply input your 3-D arrays.

abanic7 commented 1 year ago

Is there any way i can use those objects then or i have to have nifti images?

ntustison commented 1 year ago

Perhaps I wasn't explicit enough. You cannot use numpy arrays as input for the antspynet.brain_age function.

abanic7 commented 1 year ago

Okay, i got it working but the results are still far from what they got. I'm not sure how they got MAE of 2. something, because all the models i tried including ants(deepbrainnet) got much worse results.

ntustison commented 1 year ago

Are you using the arrays as input? If so, your orientation could be wrong.

abanic7 commented 1 year ago

I downloaded original dataset from IXI, im using .nii.gz images(https://brain-development.org/ixi-dataset/)

ntustison commented 1 year ago

Then I don't know.

abanic7 commented 1 year ago

Thank u for your help, much appreciated. I'm going to play around for a bit and see what kind of results I can get.

abanic7 commented 1 year ago

Is there a way to use transfer learning with DeepBrainNet?

ntustison commented 1 year ago

How, specifically, do you want to use transfer learning?

liisipromet commented 11 months ago

Hi, I also have a question about brain age prediction, so I'll just post it here. How exactly is the internal preprocessing done by the antspynet.utilities.brain_age function? (The source code on the Utilities page is not available.) Would this command do it?

antspynet.utilities.preprocess_brain_image(image, truncate_intensity=(0.01, 0.99), brain_extraction_modality='t1', template_transform_type='Affine', template='croppedMni152', do_bias_correction=True, return_bias_field=False, do_denoising=False, intensity_matching_type=None, reference_image=None, intensity_normalization_type=None, antsxnet_cache_directory=None, verbose=True)

I'd like to try out the other models from the original Bashyam et al. paper (available here: https://upenn.app.box.com/v/DeepBrainNet/folder/120404890511) and thought I'd do the preprocessing with antspynet and then get the predictions using the code in DeepBrainNet's github. Or is there a way to use the weights of those other models directly in antspynet? I assume the default version in antspynet is this one: https://upenn.app.box.com/v/DeepBrainNet/file/682464253873?

ntustison commented 11 months ago

https://github.com/ANTsX/ANTsPyNet/blob/master/antspynet/utilities/brain_age.py#L81-L92

liisipromet commented 11 months ago

Got it, thank you so much!

abanic7 commented 6 months ago

@liisipromet Hello, have you been able to use any other models, i downloaded some, but i get this error: ValueError: bad marshal data (unknown type code)

liisipromet commented 6 months ago

Hey, I'm sorry, I don't think I ended up trying out the other models with antspynet, so I never encountered that error.