Skip to content

Using the pytest fixture rather than run_all_in_keras_and_eager_mode in cohen_kappa #1327

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

Merged
merged 1 commit into from
Mar 18, 2020
Merged
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
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