lorifranke / SlicerTMS

Extension in 3DSlicer for visualization of TMS
GNU General Public License v3.0
15 stars 7 forks source link

Files fibers.vtk and model.pth.tar from Example 1 & 2 data can not be opened. #9

Closed lopezchau closed 4 months ago

lopezchau commented 1 year ago

First of all congratulations and thank you very much to the team for the fantastic work in this open-source project. I am a physician working on clinical TMS for depression. Please excuse my limited knowledge of coding.

I found the pre-print paper that get me to this is site. I followed all the installation steps with no problem (Though I haven't used Slicer before).

I get this error after trying to add fibers.vtk

An this after trying to add model.pth.tar Error: Loading /Users/lopezchau/SlicerTMS/data/Example1/model.pth.tar - load failed.

Attached is a backup of my active Conda environment. (For the record in am using vtk 9.0.3) Also the installed extensions.

I am using a M1 Pro processor.

Thank you very much in advance. Any help would appreciated.

Backup_env.pdf

Captura de Pantalla 2023-09-03 a la(s) 10 41 47
lopezchau commented 1 year ago

Upgrade to vtk 9.2.6 and I experience the same problem. Also create a new conda environment with no luck.

When I test SlicerTMS I get this on the error log.

Traceback (most recent call last): File "/Applications/Slicer.app/Contents/bin/Python/slicer/ScriptedLoadableModule.py", line 250, in onReload slicer.util.reloadScriptedModule(self.moduleName) File "/Applications/Slicer.app/Contents/bin/Python/slicer/util.py", line 1377, in reloadScriptedModule widget.setup() File "/Users/lopezchau/SlicerTMS/client/SlicerTMS/SlicerTMS.py", line 33, in setup self.IGTLNode = slicer.vtkMRMLIGTLConnectorNode() AttributeError: module 'slicer' has no attribute 'vtkMRMLIGTLConnectorNode'

Backup.pdf

lopezchau commented 1 year ago

@windyjunfeng Dear windyjunfeng Yes. It seems that version 5.4 of 3D Slicer is not working with SlicerTMS yet. Try version 5.0.3 of 3D Slicer. (It is available for download too). The path need for both versions to recognize the module is "....yourpath/SlicerTMS/client/SlicerTMS" (include this under Application Support / Modules). Remember to have your server running first. For some reason server is stopped on v.5.4 . It seems that is something to do with NVIDIA CUDA architecture. Please let me know if it helps. Are you a programmer/technician or just a simple MD like me trying to figure out technical issues?

windyjunfeng commented 1 year ago

@lopezchau Thanks for your reply. Finally, I succeeded in installing the SlicerTMS module in version 5.4 of 3D Slicer. But I find that there is still something wrong. When are run the server.py, there is no coil on the screen. It's so strange but it doesn't report any error. Maybe it's the problem of the version? image I don't find a direct installation package of version 5.0.3 like version 5.4. Could you please share the link? I'm a PhD and majoring in the application of AI in neuromodulation. I want to utilize this tool to facilitate the research. Thanks a lot!

lopezchau commented 1 year ago

@windyjunfeng here you can find the previous version (5.0.3) https://slicer-packages.kitware.com/#collection/5f4474d0e1d8c75dfc70547e/folder/5f4474d0e1d8c75dfc705482 It seems that my problem is because I am using a M1 Macbook Pro and server seem to be setup NVIDIA (CUDA).

To run the server you need to setup an environment using Conda that includes vtk, nibabel, pytorch and pyigtl as per instructions says. Once the environment is active you need to use your terminal like this.

Captura de Pantalla 2023-09-13 a la(s) 09 10 31
lopezchau commented 1 year ago

@windyjunfeng I am also a PhD candidate. I majored in rTMS for depression. Trying to setup a post-doc research lab using this software. InVesalius is another alternative but this SlicerTMS is much more advanced. Do you have any programming skills with Python? Maybe we can help each other.

windyjunfeng commented 1 year ago

@lopezchau Thank you very much! I made it. The version 5.0.3 is normal. I also know another software SimNIBS which can calculate the eletric field distribution in TMS and tDCS. But its calculation isn't real-time. Yes, I often code with Python. It's OK, welcome to contact. My email is windyjunfeng@163.com, or some means of communication that you often use.

lorifranke commented 1 year ago

@windyjunfeng @lopezchau Yes, please use version 5.0.3 for now. I did not update it for slicer 5.4 yet. @lopezchau SlicerTMS should also run on a Macbook, the server.py will detect that there is no GPU available. However, running the pytorch model on a GPU is way faster for real-time visualization.

lorifranke commented 1 year ago

Upgrade to vtk 9.2.6 and I experience the same problem. Also create a new conda environment with no luck.

When I test SlicerTMS I get this on the error log.

Traceback (most recent call last): File "/Applications/Slicer.app/Contents/bin/Python/slicer/ScriptedLoadableModule.py", line 250, in onReload slicer.util.reloadScriptedModule(self.moduleName) File "/Applications/Slicer.app/Contents/bin/Python/slicer/util.py", line 1377, in reloadScriptedModule widget.setup() File "/Users/lopezchau/SlicerTMS/client/SlicerTMS/SlicerTMS.py", line 33, in setup self.IGTLNode = slicer.vtkMRMLIGTLConnectorNode() AttributeError: module 'slicer' has no attribute 'vtkMRMLIGTLConnectorNode'

Backup.pdf

There is an environment.yml file in this repo. I would recommend using this to set up the conda environment.

lopezchau commented 1 year ago

@windyjunfeng @lopezchau Yes, please use version 5.0.3 for now. I did not update it for slicer 5.4 yet. @lopezchau SlicerTMS should also run on a Macbook, the server.py will detect that there is no GPU available. However, running the pytorch model on a GPU is way faster for real-time visualization.

@lorifranke Thank you for taking the time to answer. I managed to make it work with Slicer 5.2.2 with the server running normally. How do we run the pytorch model on a GPU? Is there a way to use different coil shapes? How can we enter a new coil shape into the learning model so it can predict the e-field with different coil shapes? We use double-coil and angled figure of eight coils. Attached are the mesh of the coils that we use. coil.zip

lopezchau commented 1 year ago

@lorifranke just to clarify that I replaced the coil.stl file and new coil do load but far aside from the mesh and from the vectors.

lorifranke commented 1 year ago

@windyjunfeng @lopezchau Yes, please use version 5.0.3 for now. I did not update it for slicer 5.4 yet. @lopezchau SlicerTMS should also run on a Macbook, the server.py will detect that there is no GPU available. However, running the pytorch model on a GPU is way faster for real-time visualization.

@lorifranke Thank you for taking the time to answer. I managed to make it work with Slicer 5.2.2 with the server running normally. How do we run the pytorch model on a GPU? Is there a way to use different coil shapes? How can we enter a new coil shape into the learning model so it can predict the e-field with different coil shapes? We use double-coil and angled figure of eight coils. Attached are the mesh of the coils that we use. coil.zip

  1. If you have the GPU correctly configured with CUDA and the right packages for your specific GPU, it will automatically detect the GPU. Inside the server.py there is the line 59 that will print out if pytorch can detect your GPU.

  2. yes, you can just put your custom coils in the data folder and rename your coil to coil.stl. For the coils being far away, the issue is that stl files can have different origins depending on how they were created and with which software. In the Loader.py file, you can adjust the origins manually somewhere around the lines 284-290 (https://github.com/lorifranke/SlicerTMS/blob/3d2e7ef74bf896ad31da3e76eb105a7755479ea0/client/SlicerTMS/Loader.py#L284C13-L290C52). If this is too much work, you could do the following steps: a) Load your STL files into 3D Slicer (as you already did). b) Go to the “Transforms” module inside 3DSlicer. c) Create a new transform. d) Apply this transform to your STL files. e) Adjust the sliders or enter values to translate (move) your STL files to the desired position. f) Save/Export the modified STL files if necessary.

lopezchau commented 1 year ago

Thank you so much for the time you are taking to this. I am trying to figure out by myself without knowing that much about programming. As far as I as can find, CUDA is not supporting MacOS anymore. The Table 1 . Performance evaluation in your paper is with Apple M1 using GPU or using CPU? I can't find a way to install CUDA toolkit for M1 Pro chip with MacOS 12.6

We tried but weren't able to get CUDA activated. Not even find CUDA toolkit previous versions for Mac.

As for the coil I managed to load up the coil and it is generating e-fields on the cortex despite is far away. Will try to do fix with both of your suggestions.

Sorry for all the novice questions from a physician. But we are really trying to use your tool in clinical practice. We are considering hiring a programmer for this.

lorifranke commented 1 year ago

@lopezchau Of course, I am happy to help and glad if you can somehow use the tool for the clinic! 👍🏼

No, if you are running it solely on a MacBook with an M1 chip, you can not use CUDA, it will always use the built-in CPU by default. If you have some GPU available, for example in another machine or a computing cluster, you can connect to this graphics card remotely with SlicerTMS. This would work via ssh. If you need this, please let me know, I can definitely give some more information on the setup.

In the performance table in the paper, Apple M1 is meant for the local CPU in an Apple MacBook with M1 chip. That's the 'slowest' performance and it will take around 3 seconds to generate a new electric field with the Neural network.

However, Apple has the Metal Plate Shader that could do the job, but this is not supported yet for 3D deep learning models in pytorch (like the one we use here to predict the efield). But I believe, and hope, this will be available at some point later.

Please let me know, if there are still issues with the coil when you tried the approaches I have suggested.

lopezchau commented 1 year ago

@lorifranke , thank you. I really appreciated. All our team is very excited with this new tool. 3s is absolutely fantastic to generate a new e-field.

So far, we are using 3D Slicer 5.2.2. with success. We are still facing a couple of challenges. a) We were not able to resize and properly place our coils. We are will edit them in SketchUp (were they originally modeled) and then export new .stl files to see if that do the trick. b) Yesterday we tried to use WebXR with no luck. I am afraid that I am going to bother you again asking for instructions on how to setup the WebXR. We are currently using InVesalius and a Polhemus FastTrack movement tracker for neuronavigation. The option with Slicer and WebXR is very exciting.

Thank you very much again.

lopezchau commented 4 months ago

Issue solved here:

https://github.com/lorifranke/SlicerTMS/issues/15