nerf icon indicating copy to clipboard operation
nerf copied to clipboard

Upgrade to TensorFlow 2

Open mulliganaceous opened this issue 2 years ago • 5 comments

Hi. I am building a Nerf project, but currently I have TensorFlow 2, and I am not willing to downgrade to TensorFlow 1. I am trying to run tf_upgrade_v2 but so far it says "command not found". I checked over the internet and I couldn't get it working.

Is it possible if you can provide a TensorFlow 2 branch please?

mulliganaceous avatar Apr 16 '23 06:04 mulliganaceous

I also notice that manual conversion is required.

(base) mulliganaceous@mulliganaceous-ASUS-TUF-Gaming-F15-FX506HCB:~/Documents/s/Nerf$ ~/.local/bin/tf_upgrade_v2 --intree ./implementation --outtree ./implementation2
2023-04-16 02:43:40.324987: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2023-04-16 02:43:40.354036: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-04-16 02:43:40.805143: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
INFO line 82:15: Changed tf.image.resize_area call to tf.image.resize(..., method=tf.image.ResizeMethod.AREA).
INFO line 709:16: Renamed 'tf.keras.optimizers.Adam' to 'tf.keras.optimizers.legacy.Adam'
INFO line 753:13: Added keywords to args of function 'tf.contrib.summary.create_file_writer'
WARNING line 753:13: tf.contrib.summary.create_file_writer requires manual check. tf.contrib.summary.create_file_writer() has been ported to the new tf.compat.v2.summary.create_file_writer(), which no longer re-uses existing event files for the same logdir; instead it always opens a new writer/file. The python writer objects must be re-used explicitly if the reusing behavior is desired.
INFO line 753:13: Renamed 'tf.contrib.summary.create_file_writer' to 'tf.compat.v2.summary.create_file_writer'
WARNING line 838:12: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
ERROR line 878:17: tf.contrib.summary.record_summaries_every_n_global_steps requires manual check. (Manual edit required) tf.contrib.summary.record_summaries_every_n_global_steps(n, step) should be replaced by a call to tf.compat.v2.summary.record_if() with the argument `lambda: tf.math.equal(0, global_step % n)` (or in graph mode, the lambda body can be used directly). If no global step was passed, instead use tf.compat.v1.train.get_or_create_global_step().
ERROR line 878:17: Using member tf.contrib.summary.record_summaries_every_n_global_steps in deprecated module tf.contrib. tf.contrib.summary.record_summaries_every_n_global_steps cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
INFO line 879:16: Added keywords to args of function 'tf.contrib.summary.scalar'
INFO line 879:16: Renamed keyword argument for tf.contrib.summary.scalar from tensor to data
WARNING line 879:16: Summary API writing function tf.contrib.summary.scalar now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 879:16: tf.contrib.summary.scalar requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 879:16: Renamed 'tf.contrib.summary.scalar' to 'tf.compat.v2.summary.scalar'
INFO line 880:16: Added keywords to args of function 'tf.contrib.summary.scalar'
INFO line 880:16: Renamed keyword argument for tf.contrib.summary.scalar from tensor to data
WARNING line 880:16: Summary API writing function tf.contrib.summary.scalar now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 880:16: tf.contrib.summary.scalar requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 880:16: Renamed 'tf.contrib.summary.scalar' to 'tf.compat.v2.summary.scalar'
INFO line 881:16: Added keywords to args of function 'tf.contrib.summary.histogram'
INFO line 881:16: Renamed keyword argument for tf.contrib.summary.histogram from tensor to data
WARNING line 881:16: Summary API writing function tf.contrib.summary.histogram now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 881:16: tf.contrib.summary.histogram requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 881:16: Renamed 'tf.contrib.summary.histogram' to 'tf.compat.v2.summary.histogram'
INFO line 883:20: Added keywords to args of function 'tf.contrib.summary.scalar'
INFO line 883:20: Renamed keyword argument for tf.contrib.summary.scalar from tensor to data
WARNING line 883:20: Summary API writing function tf.contrib.summary.scalar now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 883:20: tf.contrib.summary.scalar requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 883:20: Renamed 'tf.contrib.summary.scalar' to 'tf.compat.v2.summary.scalar'
ERROR line 903:21: tf.contrib.summary.record_summaries_every_n_global_steps requires manual check. (Manual edit required) tf.contrib.summary.record_summaries_every_n_global_steps(n, step) should be replaced by a call to tf.compat.v2.summary.record_if() with the argument `lambda: tf.math.equal(0, global_step % n)` (or in graph mode, the lambda body can be used directly). If no global step was passed, instead use tf.compat.v1.train.get_or_create_global_step().
ERROR line 903:21: Using member tf.contrib.summary.record_summaries_every_n_global_steps in deprecated module tf.contrib. tf.contrib.summary.record_summaries_every_n_global_steps cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
INFO line 905:20: Added keywords to args of function 'tf.contrib.summary.image'
INFO line 905:20: Renamed keyword argument for tf.contrib.summary.image from tensor to data
WARNING line 905:20: Summary API writing function tf.contrib.summary.image now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 905:20: tf.contrib.summary.image requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 905:20: Renamed 'tf.contrib.summary.image' to 'tf.compat.v2.summary.image'
INFO line 906:20: Added keywords to args of function 'tf.contrib.summary.image'
INFO line 906:20: Renamed keyword argument for tf.contrib.summary.image from tensor to data
WARNING line 906:20: Summary API writing function tf.contrib.summary.image now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 906:20: tf.contrib.summary.image requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 906:20: Renamed 'tf.contrib.summary.image' to 'tf.compat.v2.summary.image'
INFO line 908:20: Added keywords to args of function 'tf.contrib.summary.image'
INFO line 908:20: Renamed keyword argument for tf.contrib.summary.image from tensor to data
WARNING line 908:20: Summary API writing function tf.contrib.summary.image now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 908:20: tf.contrib.summary.image requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 908:20: Renamed 'tf.contrib.summary.image' to 'tf.compat.v2.summary.image'
INFO line 911:20: Added keywords to args of function 'tf.contrib.summary.scalar'
INFO line 911:20: Renamed keyword argument for tf.contrib.summary.scalar from tensor to data
WARNING line 911:20: Summary API writing function tf.contrib.summary.scalar now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 911:20: tf.contrib.summary.scalar requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 911:20: Renamed 'tf.contrib.summary.scalar' to 'tf.compat.v2.summary.scalar'
INFO line 912:20: Added keywords to args of function 'tf.contrib.summary.image'
INFO line 912:20: Renamed keyword argument for tf.contrib.summary.image from tensor to data
WARNING line 912:20: Summary API writing function tf.contrib.summary.image now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 912:20: tf.contrib.summary.image requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 912:20: Renamed 'tf.contrib.summary.image' to 'tf.compat.v2.summary.image'
ERROR line 916:25: tf.contrib.summary.record_summaries_every_n_global_steps requires manual check. (Manual edit required) tf.contrib.summary.record_summaries_every_n_global_steps(n, step) should be replaced by a call to tf.compat.v2.summary.record_if() with the argument `lambda: tf.math.equal(0, global_step % n)` (or in graph mode, the lambda body can be used directly). If no global step was passed, instead use tf.compat.v1.train.get_or_create_global_step().
ERROR line 916:25: Using member tf.contrib.summary.record_summaries_every_n_global_steps in deprecated module tf.contrib. tf.contrib.summary.record_summaries_every_n_global_steps cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
INFO line 917:24: Added keywords to args of function 'tf.contrib.summary.image'
INFO line 917:24: Renamed keyword argument for tf.contrib.summary.image from tensor to data
WARNING line 917:24: Summary API writing function tf.contrib.summary.image now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 917:24: tf.contrib.summary.image requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 917:24: Renamed 'tf.contrib.summary.image' to 'tf.compat.v2.summary.image'
INFO line 919:24: Added keywords to args of function 'tf.contrib.summary.image'
INFO line 919:24: Renamed keyword argument for tf.contrib.summary.image from tensor to data
WARNING line 919:24: Summary API writing function tf.contrib.summary.image now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 919:24: tf.contrib.summary.image requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 919:24: Renamed 'tf.contrib.summary.image' to 'tf.compat.v2.summary.image'
INFO line 921:24: Added keywords to args of function 'tf.contrib.summary.image'
INFO line 921:24: Renamed keyword argument for tf.contrib.summary.image from tensor to data
WARNING line 921:24: Summary API writing function tf.contrib.summary.image now requires a 'step' argument; inserting default of tf.compat.v1.train.get_or_create_global_step().
WARNING line 921:24: tf.contrib.summary.image requires manual check. tf.contrib.summary.* functions have been migrated best-effort to tf.compat.v2.summary.* equivalents where possible, but the resulting code is not guaranteed to work, so please check carefully. For more information about the new summary API, see the Effective TF 2.0 migration document or check the updated TensorBoard tutorials.
INFO line 921:24: Renamed 'tf.contrib.summary.image' to 'tf.compat.v2.summary.image'
INFO line 14:29: Renamed 'tf.log' to 'tf.math.log'
INFO line 14:39: Renamed 'tf.log' to 'tf.math.log'
INFO line 207:12: Renamed 'tf.where' to 'tf.compat.v1.where'
WARNING line 267:12: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
WARNING line 402:8: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
WARNING line 589:8: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
WARNING line 600:8: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
WARNING line 119:19: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
Traceback (most recent call last):
  File "/home/mulliganaceous/.local/bin/tf_upgrade_v2", line 8, in <module>
    sys.exit(main())
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/tensorflow/tools/compatibility/tf_upgrade_v2_main.py", line 168, in main
    files_processed, report_text, errors = upgrade.process_tree(
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/tensorflow/tools/compatibility/ast_edits.py", line 1065, in process_tree
    _, l_report, l_errors = self.process_file(input_path, output_path)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/tensorflow/tools/compatibility/ast_edits.py", line 911, in process_file
    ret = self.process_opened_file(in_filename, in_file, out_filename,
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/tensorflow/tools/compatibility/ast_edits.py", line 975, in process_opened_file
    self.update_string_pasta("".join(lines), in_filename))
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/tensorflow/tools/compatibility/ast_edits.py", line 931, in update_string_pasta
    t = pasta.parse(text)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/__init__.py", line 25, in parse
    annotator.visit(t)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 1254, in visit
    super(AstAnnotator, self).visit(node)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 133, in visit
    super(BaseVisitor, self).visit(node)
  File "/usr/lib/python3.10/ast.py", line 410, in visit
    return visitor(node)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 47, in wrapped
    f(self, node, *args, **kwargs)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 225, in visit_Module
    self.generic_visit(node)
  File "/usr/lib/python3.10/ast.py", line 418, in generic_visit
    self.visit(item)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 1254, in visit
    super(AstAnnotator, self).visit(node)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 133, in visit
    super(BaseVisitor, self).visit(node)
  File "/usr/lib/python3.10/ast.py", line 410, in visit
    return visitor(node)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 47, in wrapped
    f(self, node, *args, **kwargs)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 565, in visit_Assign
    self.visit(target)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 1254, in visit
    super(AstAnnotator, self).visit(node)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 133, in visit
    super(BaseVisitor, self).visit(node)
  File "/usr/lib/python3.10/ast.py", line 410, in visit
    return visitor(node)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 47, in wrapped
    f(self, node, *args, **kwargs)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 739, in visit_Attribute
    self.token(node.attr)
  File "/home/mulliganaceous/.local/lib/python3.10/site-packages/pasta/base/annotate.py", line 1392, in token
    raise AnnotationError("Expected %r but found %r\nline %d: %s" % (
pasta.base.annotate.AnnotationError: Expected 'עִברִית' but found 'ע'
line 345: pyparsing_unicode.עִברִית = pyparsing_unicode.Hebrew

mulliganaceous avatar Apr 16 '23 06:04 mulliganaceous

I made a version for TF 2.11.*. You can try it here

Khoa-NT avatar May 06 '23 03:05 Khoa-NT

I made a version for TF 2.11.*. You can try it here

Thank you very much for your work. May I ask what are the differences between you and the previous https://github.com/cjw531/nerf_tf2?

dfldylan avatar Sep 13 '23 03:09 dfldylan

You can see in the link that it's using TF 2.8, mine is TF 2.11. I'm already aware of that link, but I wanted the latest version of TF, at that moment, so I created my own version.

Khoa-NT avatar Sep 14 '23 06:09 Khoa-NT