Skip to content

Commit

Permalink
Add model call tests (#53)
Browse files Browse the repository at this point in the history
Adding tests for model call.

---------

Co-authored-by: Raffi Khatchadourian <[email protected]>
  • Loading branch information
tatianacv and khatchad authored Oct 23, 2023
1 parent 53a8a02 commit a05986d
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ public void testTf2()
testTf2("tf2_test_tensor_list.py", "add", 2, 3, 2, 3);
testTf2("tf2_test_tensor_list2.py", "add", 0, 2);
testTf2("tf2_test_tensor_list3.py", "add", 0, 2);
testTf2(
"tf2_test_model_call.py",
"SequentialModel.__call__",
0,
2); // NOTE: Change to testTf2("tf2_test_model_call.py", "SequentialModel.__call__", 1, 4,
// 2) once
// https://github.com/wala/ML/issues/24 is fixed.
testTf2(
"tf2_test_model_call2.py",
"SequentialModel.call",
0,
2); // NOTE: Change to testTf2("tf2_test_model_call2.py", "SequentialModel.call", 1, 4, 2)
// once
// https://github.com/wala/ML/issues/24 is fixed.
testTf2("tf2_test_model_call3.py", "SequentialModel.call", 1, 4, 2);
testTf2("tf2_test_model_call4.py", "SequentialModel.__call__", 1, 4, 2);
}

private void testTf2(
Expand Down
34 changes: 34 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import tensorflow as tf


# Create an override model to classify pictures
class SequentialModel(tf.keras.Model):

def __init__(self, **kwargs):
super(SequentialModel, self).__init__(**kwargs)

self.flatten = tf.keras.layers.Flatten(input_shape=(28, 28))

# Add a lot of small layers
num_layers = 100
self.my_layers = [tf.keras.layers.Dense(64, activation="relu")
for n in range(num_layers)]

self.dropout = tf.keras.layers.Dropout(0.2)
self.dense_2 = tf.keras.layers.Dense(10)

def __call__(self, x):
x = self.flatten(x)

for layer in self.my_layers:
x = layer(x)

x = self.dropout(x)
x = self.dense_2(x)

return x

input_data = tf.random.uniform([20, 28, 28])

model = SequentialModel()
result = model(input_data)
36 changes: 36 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_call2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import tensorflow as tf

# Create an override model to classify pictures


class SequentialModel(tf.keras.Model):

def __init__(self, **kwargs):
super(SequentialModel, self).__init__(**kwargs)

self.flatten = tf.keras.layers.Flatten(input_shape=(28, 28))

# Add a lot of small layers
num_layers = 100
self.my_layers = [tf.keras.layers.Dense(64, activation="relu")
for n in range(num_layers)]

self.dropout = tf.keras.layers.Dropout(0.2)
self.dense_2 = tf.keras.layers.Dense(10)

def call(self, x):
x = self.flatten(x)

for layer in self.my_layers:
x = layer(x)

x = self.dropout(x)
x = self.dense_2(x)

return x


input_data = tf.random.uniform([20, 28, 28])

model = SequentialModel()
result = model(input_data)
36 changes: 36 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_call3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import tensorflow as tf

# Create an override model to classify pictures


class SequentialModel(tf.keras.Model):

def __init__(self, **kwargs):
super(SequentialModel, self).__init__(**kwargs)

self.flatten = tf.keras.layers.Flatten(input_shape=(28, 28))

# Add a lot of small layers
num_layers = 100
self.my_layers = [tf.keras.layers.Dense(64, activation="relu")
for n in range(num_layers)]

self.dropout = tf.keras.layers.Dropout(0.2)
self.dense_2 = tf.keras.layers.Dense(10)

def call(self, x):
x = self.flatten(x)

for layer in self.my_layers:
x = layer(x)

x = self.dropout(x)
x = self.dense_2(x)

return x


input_data = tf.random.uniform([20, 28, 28])

model = SequentialModel()
result = model.call(input_data)
36 changes: 36 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_model_call4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import tensorflow as tf

# Create an override model to classify pictures


class SequentialModel(tf.keras.Model):

def __init__(self, **kwargs):
super(SequentialModel, self).__init__(**kwargs)

self.flatten = tf.keras.layers.Flatten(input_shape=(28, 28))

# Add a lot of small layers
num_layers = 100
self.my_layers = [tf.keras.layers.Dense(64, activation="relu")
for n in range(num_layers)]

self.dropout = tf.keras.layers.Dropout(0.2)
self.dense_2 = tf.keras.layers.Dense(10)

def __call__(self, x):
x = self.flatten(x)

for layer in self.my_layers:
x = layer(x)

x = self.dropout(x)
x = self.dense_2(x)

return x


input_data = tf.random.uniform([20, 28, 28])

model = SequentialModel()
result = model.__call__(input_data)

0 comments on commit a05986d

Please sign in to comment.