ANTsX / ANTsPyNet

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

Hi, I wanna use the ANTsPyNet, but there are always some questions about tensorflow environment #73

Closed FreshmanMa closed 4 months ago

FreshmanMa commented 1 year ago

only requires tensorlfow-version? only uisng under mac or linux? I don't understand, sorry, I'm freshman.

cookpa commented 1 year ago

I don't know about Windows. We recently got ANTsPy to build on Windows, but I don't know if ANTsPyNet will work.

On Mac or Linux, you can try installing with pip:

pip install antspynet

or via setup.py

git clone https://github.com/ANTsX/ANTsPyNet
cd ANTsPyNet
python setup.py install

If you have docker, you can get ANTsPyNet here

https://hub.docker.com/r/cookpa/antspynet/tags

On my Mac, I have

tensorflow==2.3.1 tensorflow-estimator==2.3.0 tensorflow-probability==0.11.1

If you're new to Python, I recommend learning about virtual environments and miniconda, because that will help you create an environment just for ANTsPyNet, where you can control the version of dependencies.

FreshmanMa commented 1 year ago

I don't know about Windows. We recently got ANTsPy to build on Windows, but I don't know if ANTsPyNet will work.

On Mac or Linux, you can try installing with pip:

pip install antspynet

or via setup.py

git clone https://github.com/ANTsX/ANTsPyNet
cd ANTsPyNet
python setup.py install

If you have docker, you can get ANTsPyNet here

https://hub.docker.com/r/cookpa/antspynet/tags

On my Mac, I have

tensorflow==2.3.1 tensorflow-estimator==2.3.0 tensorflow-probability==0.11.1

If you're new to Python, I recommend learning about virtual environments and miniconda, because that will help you create an environment just for ANTsPyNet, where you can control the version of dependencies.

First, thanks to your reply, and the tensorflow need a gpu version ?

cookpa commented 1 year ago

To use the GPU, it needs to be tensorflow-gpu, yes.

FreshmanMa commented 1 year ago

To use the GPU, it needs to be tensorflow-gpu, yes.

Ok, thanks, I'll have a try now.

FreshmanMa commented 1 year ago

Sorry, there is a question I don't know how to deal with. I wanna use antspynet.utilities.deep_atropos() to segment one processed HCP data into Six-tissue segmentation. I rent a server, I use the following codepip install antspynet -i https://pypi.tuna.tsinghua.edu.cn/simple, to install antspynet, and wana use a demo with deep_atropos, but I can't do it . and using python setup.py install ,the error is Reading https://pypi.org/simple/matplotlib/ error: The read operation timed out the code: import ants import antspynet file_path = './dataset/test_GT/531536.nii.gz image = ants.image_read(file_path) segmentation = antspynet.utilities.deep_atropos(image) segmentation_result = segmentation['segmentation'] ants.image_write(segmentation_result, "./dataset/segmentation/531536.nii.gz") but there is error Exception: URL fetch failure on https://figshare.com/ndownloader/files/34821874: 403 -- Forbidden What should I do to resovle it? and if I use the code above, can get the segmentation.nii.gz data ? Thanks!

To use the GPU, it needs to be tensorflow-gpu, yes.

cookpa commented 1 year ago

It seems your server is not allowed to download from Figshare. I don't know how to solve that. If you can download by other means (eg from another machine), here's how you can add it to your ANTsPyNet:

  1. mkdir ~/.keras

  2. Copy this text into ~/.keras/keras.json

{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "tensorflow",
    "image_data_format": "channels_last"
}
  1. mkdir ~/.keras/ANTsXNet

  2. Copy the files (eg, https://figshare.com/ndownloader/files/34821874 downloads as brainExtractionRobustT1.h5) to ~/.keras/ANTsXNet

FreshmanMa commented 1 year ago

It seems your server is not allowed to download from Figshare. I don't know how to solve that. If you can download by other means (eg from another machine), here's how you can add it to your ANTsPyNet:

  1. mkdir ~/.keras
  2. Copy this text into ~/.keras/keras.json
{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "tensorflow",
    "image_data_format": "channels_last"
}
  1. mkdir ~/.keras/ANTsXNet
  2. Copy the files (eg, https://figshare.com/ndownloader/files/34821874 downloads as brainExtractionRobustT1.h5) to ~/.keras/ANTsXNet

Sorry,I don't know why it did not work. So today, I try use docker, and I had dodocker pull cookpa/antspynet:latest and docker run -it cookpa/antspynet, into a python environment, docker How can I run a .py script and upload my mri.nii.gz data?and the docker will use the gpu of my pc? I wanna get this kind of segmentation data in picture.

Six-tissue segmentation

It's hard for me now. Your help will be very useful for me, thanks a lot.

FreshmanMa commented 1 year ago

It seems your server is not allowed to download from Figshare. I don't know how to solve that. If you can download by other means (eg from another machine), here's how you can add it to your ANTsPyNet:

  1. mkdir ~/.keras
  2. Copy this text into ~/.keras/keras.json
{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "tensorflow",
    "image_data_format": "channels_last"
}
  1. mkdir ~/.keras/ANTsXNet
  2. Copy the files (eg, https://figshare.com/ndownloader/files/34821874 downloads as brainExtractionRobustT1.h5) to ~/.keras/ANTsXNet

It seems your server is not allowed to download from Figshare. I don't know how to solve that. If you can download by other means (eg from another machine), here's how you can add it to your ANTsPyNet:

  1. mkdir ~/.keras
  2. Copy this text into ~/.keras/keras.json
{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "tensorflow",
    "image_data_format": "channels_last"
}
  1. mkdir ~/.keras/ANTsXNet
  2. Copy the files (eg, https://figshare.com/ndownloader/files/34821874 downloads as brainExtractionRobustT1.h5) to ~/.keras/ANTsXNet

Sorry,I don't know why it did not work. So today, I try use docker, and I had dodocker pull cookpa/antspynet:latest and docker run -it cookpa/antspynet, into a python environment, docker How can I run a .py script and upload my mri.nii.gz data?and the docker will use the gpu of my pc? I wanna get this kind of segmentation data in picture. Six-tissue segmentation It's hard for me now. Your help will be very useful for me, thanks a lot.

Can you give me some advice? Thanks

FreshmanMa commented 1 year ago

Sorry, I encounter a new promle. using docker provided by, but can't use GPU. What should I do?

dockers_problem
cookpa commented 1 year ago

I didn't build that container with CUDA, because I don't have a machine that supports it. But deep Atropos will run quite quickly without it.

FreshmanMa commented 1 year ago

I didn't build that container with CUDA, because I don't have a machine that supports it. But deep Atropos will run quite quickly without it.

All right, Thanks! Can give me some advice to get the MRI after segmentation, like this picture

Six-tissue segmentation
cookpa commented 1 year ago

I didn't build that container with CUDA, because I don't have a machine that supports it. But deep Atropos will run quite quickly without it.

All right, Thanks! Can give me some advice to get the MRI after segmentation, like this picture

https://antsx.github.io/ANTsPyNet/docs/build/html/utilities.html#antspynet.utilities.deep_atropos