areiner222

areiner222

Member Since 6 years ago

Experience Points
2
follower
Lessons Completed
0
follow
Lessons Completed
1
stars
Best Reply Awards
10
repos

4 contributions in the last year

Pinned
⚡ Multi-dimensional LSTM implementation in TensorFlow
⚡ Python buildpack
⚡ Lightweight library to build and train neural networks in Theano
⚡ Mirror of Apache Spark
Activity
May
11
1 week ago
Activity icon
issue

areiner222 issue comment tensorflow/tensorflow

areiner222
areiner222

Cannot load_weights with keras StringLookup layer

Click to expand!

Issue Type

Bug

Source

binary

Tensorflow Version

tf 2.8

Custom Code

No

OS Platform and Distribution

macOS Monterey

Mobile device

No response

Python version

3.7.13

Bazel version

No response

GCC/Compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

I am unable to reload the vocabulary of an adapted StringLookup layer by using the {save/load}_weights api of a subclassed keras Model.

Standalone code to reproduce the issue

import tensorflow as tf
class TestModel(tf.keras.models.Model):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.sl = tf.keras.layers.StringLookup()
        
    def adapt(self, df):
        self.sl.adapt(df)
    
        
    def call(self, x):
        return self.sl(x)

inp = tf.repeat(tf.constant(['A', 'B', 'C']), 10)
df_inp = tf.data.Dataset.from_tensor_slices(inp)

test_model  = TestModel()
test_model.adapt(df_inp)
print(test_model.get_weights())

'[array([b'C', b'B', b'A'], dtype=object)]'

test_model.save_weights('tmp/check_weights')

test_model_recon = TestModel()
test_model_recon.load_weights('tmp/check_weights')
print(test_model_recon.get_weights())

'[array([], dtype=object)]'

Relevant log output

No response

areiner222
areiner222

In the process of debugging, found that replacing the StaticHashTable with a MutableHashTable for the lookup_table in the parent IndexLookup layer produces the expected result.

import tensorflow as tf
StringLookup = tf.keras.layers.StringLookup

def _uninitialized_lookup_table(self):
  with tf.init_scope():
    return tf.lookup.experimental.MutableHashTable(
        key_dtype=self._key_dtype, value_dtype=self._value_dtype, default_value=self._default_value
      )
def _lookup_table_from_tokens(self, tokens):
  with tf.init_scope():
    lookup_table = self._uninitialized_lookup_table()
    token_start = self._token_start_index()
    token_end = token_start + tf.size(tokens)
    indices = tf.range(token_start, token_end, dtype=tf.int64)
    keys, values = (indices, tokens) if self.invert else (tokens, indices)
    lookup_table.insert(keys, values)
    return lookup_table
StringLookup._uninitialized_lookup_table = _uninitialized_lookup_table
StringLookup._lookup_table_from_tokens = _lookup_table_from_tokens

class TestModel(tf.keras.models.Model):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.sl = StringLookup()
        
    def adapt(self, df):
        self.sl.adapt(df)
    
        
    def call(self, x):
        return self.sl(x)

inp = tf.repeat(tf.constant(['A', 'B', 'C']), 10)
df_inp = tf.data.Dataset.from_tensor_slices(inp)

test_model  = TestModel()
test_model.adapt(df_inp)
print(test_model.get_weights())
test_model.save_weights('tmp/check_weights')
test_model_recon = TestModel()
test_model_recon.load_weights('tmp/check_weights')
print(test_model_recon.get_weights())

Output:

[array([b'C', b'B', b'A'], dtype=object)]
[array([b'C', b'B', b'A'], dtype=object)]
Activity icon
issue

areiner222 issue comment tensorflow/tensorflow

areiner222
areiner222

Cannot load_weights with keras StringLookup layer

Click to expand!

Issue Type

Bug

Source

binary

Tensorflow Version

tf 2.8

Custom Code

No

OS Platform and Distribution

macOS Monterey

Mobile device

No response

Python version

3.7.13

Bazel version

No response

GCC/Compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

I am unable to reload the vocabulary of an adapted StringLookup layer by using the {save/load}_weights api of a subclassed keras Model.

Standalone code to reproduce the issue

import tensorflow as tf
class TestModel(tf.keras.models.Model):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.sl = tf.keras.layers.StringLookup()
        
    def adapt(self, df):
        self.sl.adapt(df)
    
        
    def call(self, x):
        return self.sl(x)

inp = tf.repeat(tf.constant(['A', 'B', 'C']), 10)
df_inp = tf.data.Dataset.from_tensor_slices(inp)

test_model  = TestModel()
test_model.adapt(df_inp)
print(test_model.get_weights())

'[array([b'C', b'B', b'A'], dtype=object)]'

test_model.save_weights('tmp/check_weights')

test_model_recon = TestModel()
test_model_recon.load_weights('tmp/check_weights')
print(test_model_recon.get_weights())

'[array([], dtype=object)]'

Relevant log output

No response

areiner222
areiner222

@tilakrayal Sorry about including the botched strings - I did it to quickly visualize the output without having to navigate to a gist.

If you remove the strings (like @bhack did) and run the code, you should see the unexpected behavior.

May
10
1 week ago
Activity icon
issue

areiner222 issue tensorflow/tensorflow

areiner222
areiner222

Cannot load_weights with keras StringLookup layer

Issue Type

Bug

Source

binary

Tensorflow Version

tf 2.8

Custom Code

No

OS Platform and Distribution

macOS Monterey

Mobile device

No response

Python version

3.7.13

Bazel version

No response

GCC/Compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

I am unable to reload the vocabulary of an adapted StringLookup layer by using the {save/load}_weights api of a subclassed keras Model.

Standalone code to reproduce the issue

import tensorflow as tf
class TestModel(tf.keras.models.Model):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.sl = tf.keras.layers.StringLookup()
        
    def adapt(self, df):
        self.sl.adapt(df)
    
        
    def call(self, x):
        return self.sl(x)

inp = tf.repeat(tf.constant(['A', 'B', 'C']), 10)
df_inp = tf.data.Dataset.from_tensor_slices(inp)

test_model  = TestModel()
test_model.adapt(df_inp)
print(test_model.get_weights())

'[array([b'C', b'B', b'A'], dtype=object)]'

test_model.save_weights('tmp/check_weights')

test_model_recon = TestModel()
test_model_recon.load_weights('tmp/check_weights')
print(test_model_recon.get_weights())

'[array([], dtype=object)]'

Relevant log output

No response

Apr
1
1 month ago
Activity icon
issue

areiner222 issue comment marek-simonik/record3d

areiner222
areiner222

Support for ARKit Pose during the video session?

I'm a computer vision researcher and would love to get poses for frames we record during dataset collection

areiner222
areiner222

@marek-simonik the world pose information has been working great for me this week!

I have one follow up question, is there a straightforward way to convert the camera translation trajectory from being relative to the initial frame of reference to always being relative to the camera coordinate system? I believe there should be enough information to do this currently, but just looking for a simple methodology.

For e.g., I'd want movement forward in a straight line followed by a 180 degree turn followed by forward motion again to map to a monotonically decreasing trajectory in only the camera-z direction instead of a decreasing then increasing trajectory.

Thanks again for all your help.

Mar
25
1 month ago
Activity icon
issue

areiner222 issue comment marek-simonik/record3d

areiner222
areiner222

Support for ARKit Pose during the video session?

I'm a computer vision researcher and would love to get poses for frames we record during dataset collection

areiner222
areiner222

Any info on when the next update might be? Thank you!