Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add summary for tf.keras.Model #158

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,42 @@ public void testModelCall4()
test("tf2_test_model_call4.py", "SequentialModel.__call__", 1, 1, 3);
}

@Test
public void testModelAttributes()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test("tf2_test_model_attributes.py", "f", 1, 1, 2);
}

@Test
public void testModelAttributes2()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test("tf2_test_model_attributes2.py", "f", 1, 1, 2);
}

@Test
public void testModelAttributes3()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test("tf2_test_model_attributes3.py", "f", 1, 1, 2);
}

@Test
public void testModelAttributes4()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test("tf2_test_model_attributes4.py", "f", 1, 1, 2);
}

@Test
public void testModelAttributes5()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test("tf2_test_model_attributes5.py", "f", 1, 1, 2);
}

@Test
public void testModelAttributes6()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test("tf2_test_model_attributes6.py", "f", 1, 1, 2);
}

@Test
public void testCallbacks()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
Expand Down
41 changes: 41 additions & 0 deletions com.ibm.wala.cast.python.ml/data/tensorflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<new def="layers" class="Lobject" />
<putfield class="LRoot" field="layers" fieldType="LRoot" ref="x" value="layers" />
<putfield class="LRoot" field="layers" fieldType="LRoot" ref="keras" value="layers" />
<new def="models" class="Lobject" />
<putfield class="LRoot" field="models" fieldType="LRoot" ref="keras" value="models" />
<new def="app" class="Lobject" />
<putfield class="LRoot" field="app" fieldType="LRoot" ref="x" value="app" />
<new def="run" class="Ltensorflow/app/run" />
Expand Down Expand Up @@ -146,6 +148,9 @@
<putfield class="LRoot" field="Input" fieldType="LRoot" ref="layers" value="Input" />
<new def="Dense" class="Ltensorflow/keras/layers/Dense" />
<putfield class="LRoot" field="Dense" fieldType="LRoot" ref="layers" value="Dense" />
<new def="Model" class="Ltensorflow/keras/models/Model" />
<putfield class="LRoot" field="Model" fieldType="LRoot" ref="keras" value="Model" />
<putfield class="LRoot" field="Model" fieldType="LRoot" ref="models" value="Model" />
<new def="Variable" class="Ltensorflow/functions/Variable" />
<putfield class="LRoot" field="Variable" fieldType="LRoot" ref="x" value="Variable" />
<putfield class="LRoot" field="Variable" fieldType="LRoot" ref="variables" value="Variable" />
Expand Down Expand Up @@ -729,6 +734,42 @@
</method>
</class>
</package>
<package name="tensorflow/keras/models">
<class name="Model" allocatable="true">
<method name="read_data" descriptor="()LRoot;">
<new def="x" class="Ltensorflow/keras/Model/attribute" />
<return value="x" />
</method>
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/keras/models/Model -->
<method name="do" descriptor="()LRoot;" numArgs="4" paramNames="self inputs outputs name">
<new def="__call__" class="Ltensorflow/keras/models/__call__" />
<putfield class="LRoot" field="__call__" fieldType="LRoot" ref="arg0" value="__call__" />
<new def="call" class="Ltensorflow/keras/models/call" />
<putfield class="LRoot" field="call" fieldType="LRoot" ref="arg0" value="call" />
<new def="x" class="Llist" />
<call class="LRoot" name="read_data" descriptor="()LRoot;" type="virtual" arg0="arg0" def="xx" />
<putfield class="LRoot" field="0" fieldType="LRoot" ref="x" value="xx" />
<!-- https://www.tensorflow.org/guide/keras/transfer_learning#freezing_layers_understanding_the_trainable_attribute -->
<putfield class="LRoot" field="trainable_weights" fieldType="LRoot" ref="arg0" value="x" />
<putfield class="LRoot" field="weights" fieldType="LRoot" ref="arg0" value="x" />
<putfield class="LRoot" field="non_trainable_weights" fieldType="LRoot" ref="arg0" value="x" />
<return value="arg0" />
</method>
</class>
<class name="__call__" allocatable="true">
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/keras/Model#call -->
<method name="do" descriptor="()LRoot;" numArgs="4" paramNames="self inputs training mask">
<return value="inputs" />
</method>
</class>
<!-- FIXME: Workaround for https://github.com/wala/ML/issues/106. -->
<class name="call" allocatable="true">
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/keras/Model#call -->
<method name="do" descriptor="()LRoot;" numArgs="4" paramNames="self inputs training mask">
<return value="inputs" />
</method>
</class>
</package>
<package name="tensorflow/keras/layers">
<class name="Dense" allocatable="true">
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/keras/layers/Dense -->
Expand Down
15 changes: 15 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# From https://github.com/tensorflow/tensorflow/issues/14359#issue-272179775

import tensorflow as tf


def f(a):
pass


a = tf.keras.layers.Input(shape=(64,))
b = tf.keras.layers.Dense(5)(a)
model = tf.keras.models.Model(a, b)

for i in model.trainable_weights:
f(i)
16 changes: 16 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_attributes2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# From https://github.com/tensorflow/tensorflow/issues/14359#issue-272179775

import tensorflow as tf


def f(a):
pass


inputs = tf.keras.Input(shape=(3,))
x = tf.keras.layers.Dense(4, activation=tf.nn.relu)(inputs)
outputs = tf.keras.layers.Dense(5, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)

for i in model.trainable_weights:
f(i)
17 changes: 17 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_attributes3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# From https://github.com/tensorflow/tensorflow/issues/14359#issue-272179775

import tensorflow as tf


def f(a):
pass


inputs = tf.keras.Input(shape=(3,))
x = tf.keras.layers.Dense(4, activation=tf.nn.relu)(inputs)
outputs = tf.keras.layers.Dense(5, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)

# From https://www.tensorflow.org/guide/keras/transfer_learning#freezing_layers_understanding_the_trainable_attribute
for i in model.weights:
f(i)
16 changes: 16 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_attributes4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# From https://github.com/tensorflow/tensorflow/issues/14359#issue-272179775

import tensorflow as tf


def f(a):
pass


a = tf.keras.layers.Input(shape=(64,))
b = tf.keras.layers.Dense(5)(a)
model = tf.keras.models.Model(a, b)

# From https://www.tensorflow.org/guide/keras/transfer_learning#freezing_layers_understanding_the_trainable_attribute.
for i in model.weights:
f(i)
17 changes: 17 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_attributes5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# From https://github.com/tensorflow/tensorflow/issues/14359#issue-272179775

import tensorflow as tf


def f(a):
pass


inputs = tf.keras.Input(shape=(3,))
x = tf.keras.layers.Dense(4, activation=tf.nn.relu)(inputs)
outputs = tf.keras.layers.Dense(5, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)

# From https://www.tensorflow.org/guide/keras/transfer_learning#freezing_layers_understanding_the_trainable_attribute
for i in model.non_trainable_weights:
f(i)
16 changes: 16 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_attributes6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# From https://github.com/tensorflow/tensorflow/issues/14359#issue-272179775

import tensorflow as tf


def f(a):
pass


a = tf.keras.layers.Input(shape=(64,))
b = tf.keras.layers.Dense(5)(a)
model = tf.keras.models.Model(a, b)

# From https://www.tensorflow.org/guide/keras/transfer_learning#freezing_layers_understanding_the_trainable_attribute.
for i in model.non_trainable_weights:
f(i)
Loading