Skip to content

Commit

Permalink
Using the pytest fixture rather than (tensorflow#1327)
Browse files Browse the repository at this point in the history
run_all_in_keras_and_eager_mode in cohen_kappa
  • Loading branch information
gabrieldemarmiesse authored Mar 18, 2020
1 parent 5a64dab commit a1a8d22
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions tensorflow_addons/metrics/cohens_kappa_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,31 +195,35 @@ def test_keras_multiclass_reg_model(self):

model.fit(x, y, epochs=1, verbose=0, batch_size=32)

def test_keras_binary_clasasification_model(self):
kp = CohenKappa(num_classes=2)
inputs = tf.keras.layers.Input(shape=(10,))
outputs = tf.keras.layers.Dense(1, activation="sigmoid")(inputs)
model = tf.keras.models.Model(inputs, outputs)
model.compile(optimizer="sgd", loss="binary_crossentropy", metrics=[kp])

x = np.random.rand(1000, 10).astype(np.float32)
y = np.random.randint(2, size=(1000, 1)).astype(np.float32)
@pytest.mark.usefixtures("maybe_run_functions_eagerly")
def test_keras_binary_clasasification_model():
kp = CohenKappa(num_classes=2)
inputs = tf.keras.layers.Input(shape=(10,))
outputs = tf.keras.layers.Dense(1, activation="sigmoid")(inputs)
model = tf.keras.models.Model(inputs, outputs)
model.compile(optimizer="sgd", loss="binary_crossentropy", metrics=[kp])

model.fit(x, y, epochs=1, verbose=0, batch_size=32)
x = np.random.rand(1000, 10).astype(np.float32)
y = np.random.randint(2, size=(1000, 1)).astype(np.float32)

@pytest.mark.xfail(tf.__version__ == "2.2.0-rc0", reason="TODO: Fix this test")
def test_keras_multiclass_classification_model(self):
kp = CohenKappa(num_classes=5)
inputs = tf.keras.layers.Input(shape=(10,))
outputs = tf.keras.layers.Dense(5, activation="softmax")(inputs)
model = tf.keras.models.Model(inputs, outputs)
model.compile(optimizer="sgd", loss="categorical_crossentropy", metrics=[kp])
model.fit(x, y, epochs=1, verbose=0, batch_size=32)

x = np.random.rand(1000, 10).astype(np.float32)
y = np.random.randint(5, size=(1000,)).astype(np.float32)
y = tf.keras.utils.to_categorical(y, num_classes=5)

model.fit(x, y, epochs=1, verbose=0, batch_size=32)
@pytest.mark.xfail(tf.__version__ == "2.2.0-rc0", reason="TODO: Fix this test")
@pytest.mark.usefixtures("maybe_run_functions_eagerly")
def test_keras_multiclass_classification_model():
kp = CohenKappa(num_classes=5)
inputs = tf.keras.layers.Input(shape=(10,))
outputs = tf.keras.layers.Dense(5, activation="softmax")(inputs)
model = tf.keras.models.Model(inputs, outputs)
model.compile(optimizer="sgd", loss="categorical_crossentropy", metrics=[kp])

x = np.random.rand(1000, 10).astype(np.float32)
y = np.random.randint(5, size=(1000,)).astype(np.float32)
y = tf.keras.utils.to_categorical(y, num_classes=5)

model.fit(x, y, epochs=1, verbose=0, batch_size=32)


@pytest.mark.usefixtures("maybe_run_functions_eagerly")
Expand Down

0 comments on commit a1a8d22

Please sign in to comment.