-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for testing calling a method. We add four tests that include: 1. Calling model indirectly using `call` and `__call__` (2 tests) 2. Calling a model directly using `call` and `__call__` (2 tests) Related to #24
- Loading branch information
Showing
5 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
com.ibm.wala.cast.python.test/data/tf2_test_model_call2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
com.ibm.wala.cast.python.test/data/tf2_test_model_call3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
com.ibm.wala.cast.python.test/data/tf2_test_model_call4.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |