lindawangg / COVID-Net

COVID-Net Open Source Initiative
Other
1.15k stars 480 forks source link

Migrate to tensorflow 2 #46

Open berndverst opened 4 years ago

berndverst commented 4 years ago

Can you please make your code compatible with Tensorflow 2.0+ by default.

Pretty easy to do with no code changes, see: https://www.tensorflow.org/guide/migrate

Just add this wherever you previously imported tensorflow:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

And update your requirements.txt per #45

Parag0506 commented 4 years ago

+1 for this

iSean97 commented 4 years ago

Hi there, I got stuck running at train_tf.py. I've added "import tensorflow.compat.v1 as tf tf.disable_v2_behavior()" into Juypter Notebook but it doesn't run :/

WARNING:tensorflow:From C:\Users\user.conda\envs\tensorflow_env\lib\site-packages\tensorflow_core\python\compat\v2_compat.py:88: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term usage: ipykernel_launcher.py [-h] [--epochs EPOCHS] [--lr LR] [--bs BS] [--weightspath WEIGHTSPATH] [--metaname METANAME] [--ckptname CKPTNAME] [--trainfile TRAINFILE] [--testfile TESTFILE] [--name NAME] [--datadir DATADIR] [--covid_weight COVID_WEIGHT] [--covid_percent COVID_PERCENT] [--input_size INPUT_SIZE] [--top_percent TOP_PERCENT] [--in_tensorname IN_TENSORNAME] [--out_tensorname OUT_TENSORNAME] [--logit_tensorname LOGIT_TENSORNAME] [--label_tensorname LABEL_TENSORNAME] [--weights_tensorname WEIGHTS_TENSORNAME] ipykernel_launcher.py: error: unrecognized arguments: -f C:\Users\user\AppData\Roaming\jupyter\runtime\kernel-d40f5aa3-b4a4-4d37-8ad4-dd87ed3aeddd.json An exception has occurred, use %tb to see the full traceback.

SystemExit: 2

C:\Users\user.conda\envs\tensorflow_env\lib\site-packages\IPython\core\interactiveshell.py:3339: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D. warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

berndverst commented 4 years ago

@iSean97 you have to add that at the very beginning of the notebook file and make sure you don't have other tensorflow imports.

Also, your error is actually mentioning an argument -f. Not sure how you are actually doing your training and what your environment is.

I recommend troubleshooting this general tensorflow problem elsewhere as it is not related the project here.

yoyongbo commented 3 years ago

Hi there I am very interested in this model architecture, is there something like model.summary() in TensorFlow1? I am curious what kind of pooling and activation functions the model uses. I can see that the last layer uses a sigmoid. Thanks!!

haydengunraj commented 3 years ago

Hi @yoyongbo ,

I don't believe there's a simple print like model.summary() provides, but there are a couple of things you can do to visualize the model. The best way to do it would be using tensorboard, which lets you interactively explore the model graph. You can prepare the model for viewing on tensorboard like this:

import tensorflow as tf

out_dir = './tensorboard_graph'
meta_file = 'models/COVID-Net_CXR-2/model.meta'

graph = tf.Graph()
with graph.as_default():
    tf.train.import_meta_graph(meta_file)
    writer = tf.summary.FileWriter(out_dir, graph)
    writer.close()

You can then run tensorboard and view the graph in a browser at localhost:6006 (or whichever port you're using) via this command

tensorboard --logdir=./tensorboard_graph --port=6006

If you don't care about the structure and you just want a list of all the operations (in no particular order), you can try

import tensorflow as tf

meta_file = 'models/COVID-Net_CXR-2/model.meta'

graph = tf.Graph()
with graph.as_default():
    tf.train.import_meta_graph(meta_file)

    for n in graph.as_graph_def().node:
        print(n.name)
yoyongbo commented 3 years ago

Thanks!!

On Thu, Apr 8, 2021 at 5:56 PM Hayden Gunraj @.***> wrote:

CAUTION: This email originated from outside of UPEI. Do not click links or open attachments unless you recognize the sender and know the content is safe. If you are uncertain, please forward to @.*** and delete this email.

Hi @yoyongbo https://github.com/yoyongbo ,

I don't believe there's a simple print like model.summary() provides, but there are a couple of things you can do to visualize the model. The best way to do it would be using tensorboard https://www.tensorflow.org/tensorboard, which lets you interactively explore the model graph. You can prepare the model for viewing on tensorboard like this:

import tensorflow as tf

out_dir = './tensorboard_graph' meta_file = 'models/COVID-Net_CXR-2/model.meta'

graph = tf.Graph() with graph.as_default(): tf.train.import_meta_graph(meta_file) writer = tf.summary.FileWriter(out_dir, graph) writer.close()

You can then run tensorboard and view the graph in a browser at localhost:6006 (or whichever port you're using) via this command

tensorboard --logdir=./tensorboard_graph --port=6006

If you don't care about the structure and you just want a list of all the operations (in no particular order), you can try

import tensorflow as tf

meta_file = 'models/COVID-Net_CXR-2/model.meta'

graph = tf.Graph() with graph.as_default(): tf.train.import_meta_graph(meta_file)

for n in graph.as_graph_def().node:
    print(n.name)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lindawangg/COVID-Net/issues/46#issuecomment-816188792, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHSFVRRYPHNY646A54NN5ELTHYJ6BANCNFSM4MLEMFHA .