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

Moved test out of run_in_graph_and_eager_mode in maxout. #1434

Merged
merged 1 commit into from
Mar 27, 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
72 changes: 34 additions & 38 deletions tensorflow_addons/layers/maxout_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,45 @@

import pytest
import numpy as np
import tensorflow as tf

from tensorflow_addons.layers.maxout import Maxout
from tensorflow_addons.utils import test_utils


@test_utils.run_all_in_graph_and_eager_modes
class MaxOutTest(tf.test.TestCase):
def test_simple(self):
test_utils.layer_test(
Maxout, kwargs={"num_units": 3}, input_shape=(5, 4, 2, 18)
)

def test_nchw(self):
test_utils.layer_test(
Maxout, kwargs={"num_units": 4, "axis": 1}, input_shape=(2, 20, 3, 6)
)

test_utils.layer_test(
Maxout, kwargs={"num_units": 4, "axis": -3}, input_shape=(2, 20, 3, 6)
)

def test_unknown(self):
inputs = np.random.random((5, 4, 2, 18)).astype("float32")
test_utils.layer_test(
Maxout,
kwargs={"num_units": 3},
input_shape=(5, 4, 2, None),
input_data=inputs,
)

test_utils.layer_test(
Maxout,
kwargs={"num_units": 3},
input_shape=(None, None, None, None),
input_data=inputs,
)

def test_invalid_shape(self):
with self.assertRaisesRegexp(ValueError, r"number of features"):
test_utils.layer_test(
Maxout, kwargs={"num_units": 3}, input_shape=(5, 4, 2, 7)
)
pytestmark = pytest.mark.usefixtures("maybe_run_functions_eagerly")
AakashKumarNain marked this conversation as resolved.
Show resolved Hide resolved


def test_simple():
test_utils.layer_test(Maxout, kwargs={"num_units": 3}, input_shape=(5, 4, 2, 18))


def test_nchw():
test_utils.layer_test(
Maxout, kwargs={"num_units": 4, "axis": 1}, input_shape=(2, 20, 3, 6)
)

test_utils.layer_test(
Maxout, kwargs={"num_units": 4, "axis": -3}, input_shape=(2, 20, 3, 6)
)


def test_unknown():
inputs = np.random.random((5, 4, 2, 18)).astype("float32")
test_utils.layer_test(
Maxout, kwargs={"num_units": 3}, input_shape=(5, 4, 2, None), input_data=inputs,
)

test_utils.layer_test(
Maxout,
kwargs={"num_units": 3},
input_shape=(None, None, None, None),
input_data=inputs,
)


def test_invalid_shape():
with pytest.raises(ValueError, match="number of features"):
test_utils.layer_test(Maxout, kwargs={"num_units": 3}, input_shape=(5, 4, 2, 7))


if __name__ == "__main__":
Expand Down