ANTsPyNet icon indicating copy to clipboard operation
ANTsPyNet copied to clipboard

TensorFlow Version Error in ANTsPy/ANTsPyNet | ImportError: This version of TensorFlow Probability requires TensorFlow version >= 2.15; Detected an installation of version 2.11.0. Please upgrade TensorFlow to proceed.

Open GayanSamuditha opened this issue 1 year ago • 7 comments

GitHub Issue: TensorFlow Version Error in ANTsPy/ANTsPyNet Sample Code


Description:

I am currently experimenting with the sample code provided in the PaperANTsX repository for ANTsPy/ANTsPyNet. However, when running the library imports code block, I encounter an error related to TensorFlow version compatibility.


Code:

import ants 
import antspynet

# ANTsPy/ANTsPyNet processing for subject IXI002-Guys-0828-T1

t1_file = "IXI002-Guys-0828-T1.nii.gz" 
t1 = ants.image_read(t1_file)

# Atropos six-tissue segmentation

atropos = antspynet.deep_atropos(t1, do_preprocessing=True, verbose=True)

# Kelly Kapowski cortical thickness

kk_segmentation = atropos['segmentation_image']
kk_segmentation[kk_segmentation == 4] = 3
gray_matter = atropos['probability_images'][2] 
white_matter = (atropos['probability_images'][3] + atropos['probability_images'][4]) 
kk = ants.kelly_kapowski(s=kk_segmentation, g=gray_matter, w=white_matter, 
                         its=45, r=0.025, m=1.5, x=0, verbose=1)

# Desikan-Killiany-Tourville labeling

dkt = antspynet.desikan_killiany_tourville_labeling(t1, do_preprocessing=True, verbose=True)

# DKT label propagation throughout the cortex

dkt_cortical_mask = ants.threshold_image(dkt, 1000, 3000, 1, 0) 
dkt = dkt_cortical_mask * dkt 
kk_mask = ants.threshold_image(kk, 0, 0, 0, 1) 
dkt_propagated = ants.iMath(kk_mask, "PropagateLabelsThroughMask", kk_mask * dkt)

# Get average regional thickness values

kk_regional_stats = ants.label_stats(kk, dkt_propagated)

Error:

ImportError: This version of TensorFlow Probability requires TensorFlow version >= 2.15; Detected an installation of version 2.11.0. Please upgrade TensorFlow to proceed.

Additional Information:

  • TensorFlow Environment:
    • TensorFlow version detected: 2.11.0
    • TensorFlow Probability version requirement: >= 2.15

Steps Taken:

I have already ensured that the required libraries are installed. However, despite updating TensorFlow to the latest version, the issue persists.


Traceback:

2024-02-20 15:46:17.675655: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
...

Note:

The traceback information provides additional context regarding the error encountered during execution.


Expected Behavior:

The code should execute without errors after ensuring TensorFlow version compatibility or making necessary adjustments to the codebase.


Suggestions for Resolution:

  1. Confirm TensorFlow and TensorFlow Probability versions and ensure they meet the minimum requirements.
  2. If necessary, upgrade TensorFlow to a version >= 2.15.
  3. Check for any specific version requirements or compatibility issues with other libraries being used.
  4. If applicable, consult the documentation or community resources for further assistance.

Environment:

  • Operating System: [Provide OS information if relevant]
  • Python Version: [Provide Python version if relevant]
  • ANTsPy/ANTsPyNet Version: [Specify version of ANTsPy/ANTsPyNet if known]
  • TensorFlow Version: 2.11.0 [Detected version]
  • TensorFlow Probability Version: [Provide version if relevant]
  • Other Dependencies: [List any other relevant dependencies]

This issue is reported for tracking and resolution purposes. Any assistance or guidance to resolve this issue would be greatly appreciated. Thank you.

GayanSamuditha avatar Feb 21 '24 17:02 GayanSamuditha

@cookpa @ntustison TensorFlow 2.15.0 version not available to download the latest is 2.13.1 Can you give some advice on how to install

GayanSamuditha avatar Feb 21 '24 18:02 GayanSamuditha

Tensorflow 2.15.0 is available to me (Intel Mac, OS 12.7). I don't know if it's available on your platform. It's possible that it is and your package manager is out of date. If you can't get tensorflow 2.15.0, you would need to downgrade your version of tensorflow-probability to one that is compatible with tensorflow 2.13.1. I believe ANTsPyNet will work with tensorflow 2.13.1.

I can install antspynet in conda with

conda create -n antspynet python=3.9
conda activate antspynet
pip install antspynet

Then

>>> import ants
>>> import antspynet
```

works for me.

cookpa avatar Feb 21 '24 18:02 cookpa

On my linux and mac systems, I have

tf.__version__ = '2.13.0'
tfp.__version__ = '0.21.0'

ntustison avatar Feb 21 '24 18:02 ntustison

Hi @ntustison @cookpa thank you very much for the response. The above steps worked in the Mac system. We are running smoothly. after running the ANTsPyNet Cortical Thickness Python code for a single image we got the output like this (Attached Image)

image

My follow-up question is how to transform this output to get region-wise feature names like left.caudal.anterior.cingulate.

Thanks for your help.

GayanSamuditha avatar Feb 27 '24 18:02 GayanSamuditha

Here are the label names.

ntustison avatar Feb 27 '24 18:02 ntustison

@ntustison Got it, Thank you!

I attached the screenshot of left.caudal.anterior.cingulate value in ADNI image ID - 118675 in the antsxnetThickness.csv data file. image

But when we ran the same image with the Cortical Thickness Python code, our output shows a different value:
image

We are getting different value in Mean column. Should we consider another column?

GayanSamuditha avatar Feb 27 '24 18:02 GayanSamuditha

Multiple possible sources e.g., change in brain extraction weights, change in deep atropos weights, randomness due to the registration steps.

ntustison avatar Feb 27 '24 18:02 ntustison

I think version problems should be reduced by #104, but please let us know if there's further problems

cookpa avatar Apr 26 '24 20:04 cookpa

Fantastic! This will help me a ton. Need help getting a pypi release up? Here is the GHA workflow I use personally to automatically push to pypi every time you make a new release on github. Just requires setting the pypi token as a repo secret.

ncullen93 avatar Apr 27 '24 06:04 ncullen93