Commit afd5579f authored by Kaushik Shivakumar's avatar Kaushik Shivakumar
Browse files

Merge remote-tracking branch 'upstream/master' into context_tf2

parents dcd96e02 567bd18d
...@@ -36,7 +36,7 @@ def normalize_image(image, original_minval, original_maxval, target_minval, ...@@ -36,7 +36,7 @@ def normalize_image(image, original_minval, original_maxval, target_minval,
Returns: Returns:
image: image which is the same shape as input image. image: image which is the same shape as input image.
""" """
with tf.name_scope('NormalizeImage', values=[image]): with tf.compat.v1.name_scope('NormalizeImage', values=[image]):
original_minval = float(original_minval) original_minval = float(original_minval)
original_maxval = float(original_maxval) original_maxval = float(original_maxval)
target_minval = float(target_minval) target_minval = float(target_minval)
...@@ -68,16 +68,17 @@ def generate_tfexample_image(input_example_strings, ...@@ -68,16 +68,17 @@ def generate_tfexample_image(input_example_strings,
A tensor with shape [batch_size, height, width, channels] of type float32 A tensor with shape [batch_size, height, width, channels] of type float32
with values in the range [0..1] with values in the range [0..1]
""" """
batch_size = tf.shape(input_example_strings)[0] batch_size = tf.shape(input=input_example_strings)[0]
images_shape = tf.stack( images_shape = tf.stack(
[batch_size, image_height, image_width, image_channels]) [batch_size, image_height, image_width, image_channels])
tf_example_image_key = 'image/encoded' tf_example_image_key = 'image/encoded'
feature_configs = { feature_configs = {
tf_example_image_key: tf_example_image_key:
tf.FixedLenFeature( tf.io.FixedLenFeature(
image_height * image_width * image_channels, dtype=tf.float32) image_height * image_width * image_channels, dtype=tf.float32)
} }
feature_tensors = tf.parse_example(input_example_strings, feature_configs) feature_tensors = tf.io.parse_example(
serialized=input_example_strings, features=feature_configs)
float_images = tf.reshape( float_images = tf.reshape(
normalize_image( normalize_image(
feature_tensors[tf_example_image_key], feature_tensors[tf_example_image_key],
...@@ -97,11 +98,11 @@ def attention_ocr_attention_masks(num_characters): ...@@ -97,11 +98,11 @@ def attention_ocr_attention_masks(num_characters):
names = ['%s/Softmax:0' % (prefix)] names = ['%s/Softmax:0' % (prefix)]
for i in range(1, num_characters): for i in range(1, num_characters):
names += ['%s_%d/Softmax:0' % (prefix, i)] names += ['%s_%d/Softmax:0' % (prefix, i)]
return [tf.get_default_graph().get_tensor_by_name(n) for n in names] return [tf.compat.v1.get_default_graph().get_tensor_by_name(n) for n in names]
def build_tensor_info(tensor_dict): def build_tensor_info(tensor_dict):
return { return {
k: tf.saved_model.utils.build_tensor_info(t) k: tf.compat.v1.saved_model.utils.build_tensor_info(t)
for k, t in tensor_dict.items() for k, t in tensor_dict.items()
} }
...@@ -29,7 +29,7 @@ _CHECKPOINT_URL = ( ...@@ -29,7 +29,7 @@ _CHECKPOINT_URL = (
def _clean_up(): def _clean_up():
tf.gfile.DeleteRecursively(tf.test.get_temp_dir()) tf.io.gfile.rmtree(tf.compat.v1.test.get_temp_dir())
def _create_tf_example_string(image): def _create_tf_example_string(image):
...@@ -47,7 +47,7 @@ class AttentionOcrExportTest(tf.test.TestCase): ...@@ -47,7 +47,7 @@ class AttentionOcrExportTest(tf.test.TestCase):
for suffix in ['.meta', '.index', '.data-00000-of-00001']: for suffix in ['.meta', '.index', '.data-00000-of-00001']:
filename = _CHECKPOINT + suffix filename = _CHECKPOINT + suffix
self.assertTrue( self.assertTrue(
tf.gfile.Exists(filename), tf.io.gfile.exists(filename),
msg='Missing checkpoint file %s. ' msg='Missing checkpoint file %s. '
'Please download and extract it from %s' % 'Please download and extract it from %s' %
(filename, _CHECKPOINT_URL)) (filename, _CHECKPOINT_URL))
...@@ -57,7 +57,8 @@ class AttentionOcrExportTest(tf.test.TestCase): ...@@ -57,7 +57,8 @@ class AttentionOcrExportTest(tf.test.TestCase):
os.path.dirname(__file__), 'datasets/testdata/fsns') os.path.dirname(__file__), 'datasets/testdata/fsns')
tf.test.TestCase.setUp(self) tf.test.TestCase.setUp(self)
_clean_up() _clean_up()
self.export_dir = os.path.join(tf.test.get_temp_dir(), 'exported_model') self.export_dir = os.path.join(
tf.compat.v1.test.get_temp_dir(), 'exported_model')
self.minimal_output_signature = { self.minimal_output_signature = {
'predictions': 'AttentionOcr_v1/predicted_chars:0', 'predictions': 'AttentionOcr_v1/predicted_chars:0',
'scores': 'AttentionOcr_v1/predicted_scores:0', 'scores': 'AttentionOcr_v1/predicted_scores:0',
...@@ -93,10 +94,10 @@ class AttentionOcrExportTest(tf.test.TestCase): ...@@ -93,10 +94,10 @@ class AttentionOcrExportTest(tf.test.TestCase):
size=self.dataset.image_shape).astype('uint8'), size=self.dataset.image_shape).astype('uint8'),
} }
signature_def = graph_def.signature_def[ signature_def = graph_def.signature_def[
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY] tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY]
if serving: if serving:
input_name = signature_def.inputs[ input_name = signature_def.inputs[
tf.saved_model.signature_constants.CLASSIFY_INPUTS].name tf.saved_model.CLASSIFY_INPUTS].name
# Model for serving takes input: inputs['inputs'] = 'tf_example:0' # Model for serving takes input: inputs['inputs'] = 'tf_example:0'
feed_dict = { feed_dict = {
input_name: [ input_name: [
...@@ -126,11 +127,11 @@ class AttentionOcrExportTest(tf.test.TestCase): ...@@ -126,11 +127,11 @@ class AttentionOcrExportTest(tf.test.TestCase):
export_for_serving: True if the model was exported for Serving. This export_for_serving: True if the model was exported for Serving. This
affects how input is fed into the model. affects how input is fed into the model.
""" """
tf.reset_default_graph() tf.compat.v1.reset_default_graph()
sess = tf.Session() sess = tf.compat.v1.Session()
graph_def = tf.saved_model.loader.load( graph_def = tf.compat.v1.saved_model.loader.load(
sess=sess, sess=sess,
tags=[tf.saved_model.tag_constants.SERVING], tags=[tf.saved_model.SERVING],
export_dir=self.export_dir) export_dir=self.export_dir)
feed_dict = self.create_input_feed(graph_def, export_for_serving) feed_dict = self.create_input_feed(graph_def, export_for_serving)
results = sess.run(self.minimal_output_signature, feed_dict=feed_dict) results = sess.run(self.minimal_output_signature, feed_dict=feed_dict)
......
...@@ -52,7 +52,7 @@ class ModelTest(tf.test.TestCase): ...@@ -52,7 +52,7 @@ class ModelTest(tf.test.TestCase):
self.num_char_classes) self.num_char_classes)
self.length_logit_shape = (self.batch_size, self.seq_length + 1) self.length_logit_shape = (self.batch_size, self.seq_length + 1)
# Placeholder knows image dimensions, but not batch size. # Placeholder knows image dimensions, but not batch size.
self.input_images = tf.placeholder( self.input_images = tf.compat.v1.placeholder(
tf.float32, tf.float32,
shape=(None, self.image_height, self.image_width, 3), shape=(None, self.image_height, self.image_width, 3),
name='input_node') name='input_node')
...@@ -89,8 +89,8 @@ class ModelTest(tf.test.TestCase): ...@@ -89,8 +89,8 @@ class ModelTest(tf.test.TestCase):
with self.test_session() as sess: with self.test_session() as sess:
endpoints_tf = ocr_model.create_base( endpoints_tf = ocr_model.create_base(
images=self.input_images, labels_one_hot=None) images=self.input_images, labels_one_hot=None)
sess.run(tf.global_variables_initializer()) sess.run(tf.compat.v1.global_variables_initializer())
tf.tables_initializer().run() tf.compat.v1.tables_initializer().run()
endpoints = sess.run( endpoints = sess.run(
endpoints_tf, feed_dict={self.input_images: self.fake_images}) endpoints_tf, feed_dict={self.input_images: self.fake_images})
...@@ -127,7 +127,7 @@ class ModelTest(tf.test.TestCase): ...@@ -127,7 +127,7 @@ class ModelTest(tf.test.TestCase):
ocr_model = self.create_model() ocr_model = self.create_model()
conv_tower = ocr_model.conv_tower_fn(self.input_images) conv_tower = ocr_model.conv_tower_fn(self.input_images)
sess.run(tf.global_variables_initializer()) sess.run(tf.compat.v1.global_variables_initializer())
conv_tower_np = sess.run( conv_tower_np = sess.run(
conv_tower, feed_dict={self.input_images: self.fake_images}) conv_tower, feed_dict={self.input_images: self.fake_images})
...@@ -141,9 +141,9 @@ class ModelTest(tf.test.TestCase): ...@@ -141,9 +141,9 @@ class ModelTest(tf.test.TestCase):
ocr_model = self.create_model() ocr_model = self.create_model()
ocr_model.create_base(images=self.input_images, labels_one_hot=None) ocr_model.create_base(images=self.input_images, labels_one_hot=None)
with self.test_session() as sess: with self.test_session() as sess:
tfprof_root = tf.profiler.profile( tfprof_root = tf.compat.v1.profiler.profile(
sess.graph, sess.graph,
options=tf.profiler.ProfileOptionBuilder options=tf.compat.v1.profiler.ProfileOptionBuilder
.trainable_variables_parameter()) .trainable_variables_parameter())
model_size_bytes = 4 * tfprof_root.total_parameters model_size_bytes = 4 * tfprof_root.total_parameters
...@@ -163,9 +163,9 @@ class ModelTest(tf.test.TestCase): ...@@ -163,9 +163,9 @@ class ModelTest(tf.test.TestCase):
summaries = ocr_model.create_summaries( summaries = ocr_model.create_summaries(
data, endpoints, charset, is_training=False) data, endpoints, charset, is_training=False)
with self.test_session() as sess: with self.test_session() as sess:
sess.run(tf.global_variables_initializer()) sess.run(tf.compat.v1.global_variables_initializer())
sess.run(tf.local_variables_initializer()) sess.run(tf.compat.v1.local_variables_initializer())
tf.tables_initializer().run() tf.compat.v1.tables_initializer().run()
sess.run(summaries) # just check it is runnable sess.run(summaries) # just check it is runnable
def test_sequence_loss_function_without_label_smoothing(self): def test_sequence_loss_function_without_label_smoothing(self):
...@@ -188,7 +188,7 @@ class ModelTest(tf.test.TestCase): ...@@ -188,7 +188,7 @@ class ModelTest(tf.test.TestCase):
Returns: Returns:
a list of tensors with encoded image coordinates in them. a list of tensors with encoded image coordinates in them.
""" """
batch_size = tf.shape(net)[0] batch_size = tf.shape(input=net)[0]
_, h, w, _ = net.shape.as_list() _, h, w, _ = net.shape.as_list()
h_loc = [ h_loc = [
tf.tile( tf.tile(
...@@ -200,7 +200,8 @@ class ModelTest(tf.test.TestCase): ...@@ -200,7 +200,8 @@ class ModelTest(tf.test.TestCase):
h_loc = tf.concat([tf.expand_dims(t, 2) for t in h_loc], 2) h_loc = tf.concat([tf.expand_dims(t, 2) for t in h_loc], 2)
w_loc = [ w_loc = [
tf.tile( tf.tile(
tf.contrib.layers.one_hot_encoding(tf.constant([i]), num_classes=w), tf.contrib.layers.one_hot_encoding(
tf.constant([i]), num_classes=w),
[h, 1]) for i in range(w) [h, 1]) for i in range(w)
] ]
w_loc = tf.concat([tf.expand_dims(t, 2) for t in w_loc], 2) w_loc = tf.concat([tf.expand_dims(t, 2) for t in w_loc], 2)
...@@ -272,8 +273,8 @@ class ModelTest(tf.test.TestCase): ...@@ -272,8 +273,8 @@ class ModelTest(tf.test.TestCase):
endpoints_tf = ocr_model.create_base( endpoints_tf = ocr_model.create_base(
images=self.fake_images, labels_one_hot=None) images=self.fake_images, labels_one_hot=None)
sess.run(tf.global_variables_initializer()) sess.run(tf.compat.v1.global_variables_initializer())
tf.tables_initializer().run() tf.compat.v1.tables_initializer().run()
endpoints = sess.run(endpoints_tf) endpoints = sess.run(endpoints_tf)
self.assertEqual(endpoints.predicted_text.shape, (self.batch_size,)) self.assertEqual(endpoints.predicted_text.shape, (self.batch_size,))
...@@ -289,7 +290,7 @@ class CharsetMapperTest(tf.test.TestCase): ...@@ -289,7 +290,7 @@ class CharsetMapperTest(tf.test.TestCase):
charset_mapper = model.CharsetMapper(charset) charset_mapper = model.CharsetMapper(charset)
with self.test_session() as sess: with self.test_session() as sess:
tf.tables_initializer().run() tf.compat.v1.tables_initializer().run()
text = sess.run(charset_mapper.get_text(ids)) text = sess.run(charset_mapper.get_text(ids))
self.assertAllEqual(text, [b'hello', b'world']) self.assertAllEqual(text, [b'hello', b'world'])
......
...@@ -29,13 +29,13 @@ import sequence_layers ...@@ -29,13 +29,13 @@ import sequence_layers
def fake_net(batch_size, num_features, feature_size): def fake_net(batch_size, num_features, feature_size):
return tf.convert_to_tensor( return tf.convert_to_tensor(
np.random.uniform(size=(batch_size, num_features, feature_size)), value=np.random.uniform(size=(batch_size, num_features, feature_size)),
dtype=tf.float32) dtype=tf.float32)
def fake_labels(batch_size, seq_length, num_char_classes): def fake_labels(batch_size, seq_length, num_char_classes):
labels_np = tf.convert_to_tensor( labels_np = tf.convert_to_tensor(
np.random.randint( value=np.random.randint(
low=0, high=num_char_classes, size=(batch_size, seq_length))) low=0, high=num_char_classes, size=(batch_size, seq_length)))
return slim.one_hot_encoding(labels_np, num_classes=num_char_classes) return slim.one_hot_encoding(labels_np, num_classes=num_char_classes)
......
This diff is collapsed.
This diff is collapsed.
...@@ -109,6 +109,18 @@ Sergi Caelles Prat, Shan Yang, Sudheendra Vijayanarasimhan, Tina Tian, Tomer ...@@ -109,6 +109,18 @@ Sergi Caelles Prat, Shan Yang, Sudheendra Vijayanarasimhan, Tina Tian, Tomer
Kaftan, Vighnesh Birodkar, Vishnu Banna, Vivek Rathod, Yanhui Liang, Yiming Shi, Kaftan, Vighnesh Birodkar, Vishnu Banna, Vivek Rathod, Yanhui Liang, Yiming Shi,
Yixin Shi, Yu-hui Chen, Zhichao Lu. Yixin Shi, Yu-hui Chen, Zhichao Lu.
### MobileDet GPU
We have released SSDLite with MobileDet GPU backbone, which achieves 17% mAP
higher than the MobileNetV2 SSDLite (27.5 mAP vs 23.5 mAP) on a NVIDIA Jetson
Xavier at comparable latency (3.2ms vs 3.3ms).
Along with the model definition, we are also releasing model checkpoints trained
on the COCO dataset.
<b>Thanks to contributors</b>: Yongzhe Wang, Bo Chen, Hanxiao Liu, Le An
(NVIDIA), Yu-Te Cheng (NVIDIA), Oliver Knieps (NVIDIA), and Josh Park (NVIDIA).
### Context R-CNN ### Context R-CNN
We have released [Context R-CNN](https://arxiv.org/abs/1912.03538), a model that We have released [Context R-CNN](https://arxiv.org/abs/1912.03538), a model that
......
This diff is collapsed.
This diff is collapsed.
...@@ -332,7 +332,7 @@ class ContextRCNNMetaArch(faster_rcnn_meta_arch.FasterRCNNMetaArch): ...@@ -332,7 +332,7 @@ class ContextRCNNMetaArch(faster_rcnn_meta_arch.FasterRCNNMetaArch):
""" """
box_features = self._crop_and_resize_fn( box_features = self._crop_and_resize_fn(
features_to_crop, proposal_boxes_normalized, [features_to_crop], proposal_boxes_normalized, None,
[self._initial_crop_size, self._initial_crop_size]) [self._initial_crop_size, self._initial_crop_size])
attention_features = self._context_feature_extract_fn( attention_features = self._context_feature_extract_fn(
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment