parent
d319d8d716
commit
fb4381d0b5
tensorflow/python/keras/engine
@ -513,10 +513,11 @@ class Layer(checkpointable.Checkpointable):
|
||||
ValueError: if the layer's `call` method returns None (an invalid value).
|
||||
"""
|
||||
input_list = nest.flatten(inputs)
|
||||
# Accept NumPy inputs by converting to Tensors.
|
||||
if all(isinstance(x, (np.ndarray, float, int)) for x in input_list):
|
||||
inputs = nest.map_structure(ops.convert_to_tensor, inputs)
|
||||
input_list = nest.flatten(inputs)
|
||||
if context.executing_eagerly():
|
||||
# Accept NumPy inputs by converting to Tensors when executing eagerly.
|
||||
if all(isinstance(x, (np.ndarray, float, int)) for x in input_list):
|
||||
inputs = nest.map_structure(ops.convert_to_tensor, inputs)
|
||||
input_list = nest.flatten(inputs)
|
||||
|
||||
# We will attempt to build a TF graph if & only if all inputs are symbolic.
|
||||
# This is always the case in graph mode. It can also be the case in eager
|
||||
|
@ -26,8 +26,6 @@ from tensorflow.python.eager import context
|
||||
from tensorflow.python.framework import ops
|
||||
from tensorflow.python.framework import tensor_shape
|
||||
from tensorflow.python.framework import test_util
|
||||
from tensorflow.python.keras import keras_parameterized
|
||||
from tensorflow.python.keras import testing_utils
|
||||
from tensorflow.python.keras.engine import base_layer
|
||||
from tensorflow.python.keras.optimizer_v2 import rmsprop
|
||||
from tensorflow.python.ops import array_ops
|
||||
@ -73,7 +71,7 @@ class InvalidLayer(base_layer.Layer):
|
||||
raise ValueError('You did something wrong!')
|
||||
|
||||
|
||||
class BaseLayerTest(keras_parameterized.TestCase):
|
||||
class BaseLayerTest(test.TestCase, parameterized.TestCase):
|
||||
|
||||
@parameterized.parameters(DynamicLayer1, DynamicLayer2)
|
||||
def test_dynamic_layer_in_functional_model_in_graph_mode(self, layer_class):
|
||||
@ -212,17 +210,6 @@ class BaseLayerTest(keras_parameterized.TestCase):
|
||||
with self.assertRaisesRegexp(ValueError, 'You did something wrong!'):
|
||||
_ = InvalidLayer()(inputs)
|
||||
|
||||
@keras_parameterized.run_with_all_model_types
|
||||
@test_util.run_in_graph_and_eager_modes
|
||||
def test_build_with_numpy_data(self):
|
||||
model_layers = [
|
||||
keras.layers.Dense(3, activation='relu', kernel_initializer='ones'),
|
||||
keras.layers.Dense(1, activation='sigmoid', kernel_initializer='ones')
|
||||
]
|
||||
model = testing_utils.get_model_from_layers(model_layers, input_shape=(4,))
|
||||
model(np.zeros((2, 4), dtype='float32'))
|
||||
self.assertTrue(model.built)
|
||||
|
||||
def test_using_symbolic_tensors_with_tf_ops(self):
|
||||
# Single-input.
|
||||
x = keras.Input((3,))
|
||||
|
Loading…
Reference in New Issue
Block a user