18
18
import io
19
19
import sys
20
20
import tempfile
21
- import warnings
22
21
23
22
import numpy as np
24
23
import tensorflow .compat .v2 as tf
@@ -5010,31 +5009,23 @@ def test_sequential_model_output(self):
5010
5009
layers_module .Dense (1 , activation = activation ),
5011
5010
]
5012
5011
)
5013
- with warnings .catch_warnings (record = True ) as w :
5014
- warnings .simplefilter ("always" )
5012
+ with self .assertRaisesRegex (
5013
+ ValueError ,
5014
+ "has a single unit output, but the activation is softmax.*" ,
5015
+ ):
5015
5016
model .compile ()
5016
- self .assertIs (w [- 1 ].category , SyntaxWarning )
5017
- self .assertIn (
5018
- "Found a layer with softmax activation and single unit "
5019
- "output" ,
5020
- str (w [- 1 ].message ),
5021
- )
5022
5017
del model
5023
5018
5024
5019
def test_functional_model_output (self ):
5025
5020
inputs = input_layer .Input (shape = (10 ,))
5026
5021
for activation in ["softmax" , tf .nn .softmax , layers_module .Softmax ()]:
5027
5022
x = layers_module .Dense (1 , activation = activation )(inputs )
5028
5023
model = training_module .Model (inputs , x )
5029
- with warnings .catch_warnings (record = True ) as w :
5030
- warnings .simplefilter ("always" )
5024
+ with self .assertRaisesRegex (
5025
+ ValueError ,
5026
+ "has a single unit output, but the activation is softmax.*" ,
5027
+ ):
5031
5028
model .compile ()
5032
- self .assertIs (w [- 1 ].category , SyntaxWarning )
5033
- self .assertIn (
5034
- "Found a layer with softmax activation and single unit "
5035
- "output" ,
5036
- str (w [- 1 ].message ),
5037
- )
5038
5029
del model
5039
5030
5040
5031
def test_multi_output_model (self ):
@@ -5043,15 +5034,11 @@ def test_multi_output_model(self):
5043
5034
x = layers_module .Dense (1 , activation = activation )(inputs )
5044
5035
y = layers_module .Dense (1 , activation = activation )(inputs )
5045
5036
model = training_module .Model (inputs , [x , y ])
5046
- with warnings .catch_warnings (record = True ) as w :
5047
- warnings .simplefilter ("always" )
5037
+ with self .assertRaisesRegex (
5038
+ ValueError ,
5039
+ "has a single unit output, but the activation is softmax.*" ,
5040
+ ):
5048
5041
model .compile ()
5049
- self .assertIs (w [- 1 ].category , SyntaxWarning )
5050
- self .assertIn (
5051
- "Found a layer with softmax activation and single unit "
5052
- "output" ,
5053
- str (w [- 1 ].message ),
5054
- )
5055
5042
del model
5056
5043
5057
5044
def test_multi_input_output_model (self ):
@@ -5063,15 +5050,11 @@ def test_multi_input_output_model(self):
5063
5050
x = layers_module .Dense (1 , activation = activation )(inputs [0 ])
5064
5051
y = layers_module .Dense (1 , activation = activation )(inputs [1 ])
5065
5052
model = training_module .Model (inputs , [x , y ])
5066
- with warnings .catch_warnings (record = True ) as w :
5067
- warnings .simplefilter ("always" )
5053
+ with self .assertRaisesRegex (
5054
+ ValueError ,
5055
+ "has a single unit output, but the activation is softmax.*" ,
5056
+ ):
5068
5057
model .compile ()
5069
- self .assertIs (w [- 1 ].category , SyntaxWarning )
5070
- self .assertIn (
5071
- "Found a layer with softmax activation and single unit "
5072
- "output" ,
5073
- str (w [- 1 ].message ),
5074
- )
5075
5058
del model
5076
5059
5077
5060
0 commit comments