voxelmorph / voxelmorph

Unsupervised Learning for Image Registration
Apache License 2.0
2.3k stars 582 forks source link

Request to Update TensorFlow Import for Compatibility in train.py and test.py Scripts #569

Open VishalBalajiSivaraman opened 11 months ago

VishalBalajiSivaraman commented 11 months ago

Kindly update the import line in your train.py and test.py scripts to use import tensorflow.compat.v1 as tf to mitigate compatibility errors during code execution in TensorFlow 2.x versions.

adalca commented 11 months ago

Could you describe what this would do? We haven't worked with tf v1 for a while and I'm not sure what this is trying to fix.

VishalBalajiSivaraman commented 11 months ago

Hello,

I was working on a study using your GitHub code and encountered an issue with compatibility when running your example Colab notebook with your suggested method. I initially thought the problem was related to model saving, but I managed to resolve that by using a different model-saving approach. However, I continued to encounter unusual errors with your code, which, in my opinion, appeared to be well-structured. After investigating further, I realized that the code was originally implemented using Tensorflow 1.x, which is no longer current. To restore the functionality of the code and fix all errors, including the model saving issue, I found a simple solution: replacing the Tensorflow import commands with import tensorflow.compat.v1 as tf, especially in your train and test TensorFlow scripts. In short, this command allows us to use code originally designed for TensorFlow 1.x while benefiting from the newer TensorFlow versions, which currently is TensorFlow 2.x. I have attached screenshots for your reference.

Thanks

model.save Issue

model_save_issue

Adam Optimizer Issue

adam_opt_issue

Overall Fix

issue_fix

arnaud-nt2i commented 3 months ago

Same problem here, lots of errors with tf 2.16. What is the recommended version?

adalca commented 3 months ago

tf changes so quickly,. but it seems that 2.14 is stable with vxm code. Could you tell us if you still get these errors? I'll tag @mu40 on the thread as well as he has experience with a myriad of tf versions

arnaud-nt2i commented 3 months ago

ok thanks, tried bunch of them but got multiples errors (besides obvious ones like naming changes of keras mse loss) related to tensor.numpy() or type mismatches when calling model.fit function, different errors for each version I tried...

Switched to PyTorch, worked instant !