Updated attention_ocr model to be compatible with TensorFlow 2.x. #10952
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Updated references to removed
tf.contrib
packages:tf.contrib.slim
is now distributed as a separate PIP packagetf-slim
.tf.contrib.legacy_seq2seq
is no longer available. The classes need by this model have been copied here.tf.contrib.lookup.index_to_string_table_from_tensor
has been replaced withtf.lookup.StaticHashTable
.tf.contrib.layers.one_hot_encoding
has been replaced withtf.one_hot
.Added the FSNS list of URLs which used to be under
research/street
(that model was removed by PR #8934).This update makes the
research/attention_ocr
model compatible with TensorFlow 2, but it is not TF2 native, since it uses compat.v1 layers. Checkpoints trained with TF1 can still be loaded with the latest version, but results my be slightly different due to implementation changes with respect to old contrib layers.BUG: The
test_moving_variables_properly_loaded_from_a_checkpoint
indemo_inference.py
no longer passes (probably to internal changes in SLIM). We need retrain the model and provide an updated checkpoint that makes this test pass.Description
TensorFlow 1.15 is no longer supported, this model now works with TensorFlow 2.11. This change change introduces
tf-slim
as a new dependency (tf.contrib was removed in TF 2.0).Type of change
For a new feature or function, please create an issue first to discuss it
with us before submitting a pull request.
Note: Please delete options that are not relevant.
Tests
Ran all the unit tests, using the procedure in https://github.com/tensorflow/models/tree/master/research/attention_ocr#how-to-use-this-code. All tests pass in Mac OS 10.15.7 and Debian Linux 10.
Also started training the model from scratch on the FSNS dataset and verified that it achieves 81% test performance after 24 hours. I will provide the checkpoint at 400k steps once it completes.
Test Configuration:
Cloud instance with 12 vCPUs, 48GB of RAM, 250GB persistent balanced storage, and 1 NVIDIA V100 GPU, running Google Deep Learning VM (version tf2-gpu.2-11.m103). Set up the environment as described in the README.md. Started 4 consoles using tmux and ran each of following commands in each console:
TensorBoard screenshot:
Checklist
This code predates TensorFlow 2, so it does not meet the coding guidelines. There is an ongoing effort to migrate this model to Keras, but in order to facilitate this migration, we need to have this reference code still able to be run using the latest version of TensorFlow.