本文整理匯總了Python中keras.models.Model.from_config方法的典型用法代碼示例。如果您正苦於以下問題:Python Model.from_config方法的具體用法?Python Model.from_config怎麽用?Python Model.from_config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類keras.models.Model
的用法示例。
在下文中一共展示了Model.from_config方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: from_config
# 需要導入模塊: from keras.models import Model [as 別名]
# 或者: from keras.models.Model import from_config [as 別名]
def from_config(cls, config, custom_objects={}):
if type(custom_objects) is list:
custom_objects = {obj.__name__: obj for obj in custom_objects}
custom_objects.update(_get_cells())
config = config.copy()
model_config = config.pop('model_config')
if model_config is None:
model = None
else:
model = Model.from_config(model_config, custom_objects)
if type(model.input) is list:
input = model.input[0]
initial_states = model.input[1:]
else:
input = model.input
initial_states = None
if type(model.output) is list:
output = model.output[0]
final_states = model.output[1:]
else:
output = model.output
final_states = None
return cls(input, output, initial_states, final_states, **config)
示例2: test_layer_call_arguments
# 需要導入模塊: from keras.models import Model [as 別名]
# 或者: from keras.models.Model import from_config [as 別名]
def test_layer_call_arguments():
# Test the ability to pass and serialize arguments to `call`.
inp = layers.Input(shape=(2,))
x = layers.Dense(3)(inp)
x = layers.Dropout(0.5)(x, training=True)
model = Model(inp, x)
assert not model.uses_learning_phase
# Test that argument is kept when applying the model
inp2 = layers.Input(shape=(2,))
out2 = model(inp2)
assert not out2._uses_learning_phase
# Test that argument is kept after loading a model
config = model.get_config()
model = Model.from_config(config)
assert not model.uses_learning_phase
示例3: test_layer_sharing_at_heterogeneous_depth
# 需要導入模塊: from keras.models import Model [as 別名]
# 或者: from keras.models.Model import from_config [as 別名]
def test_layer_sharing_at_heterogeneous_depth():
x_val = np.random.random((10, 5))
x = Input(shape=(5,))
A = Dense(5, name='A')
B = Dense(5, name='B')
output = A(B(A(B(x))))
M = Model(x, output)
output_val = M.predict(x_val)
config = M.get_config()
weights = M.get_weights()
M2 = Model.from_config(config)
M2.set_weights(weights)
output_val_2 = M2.predict(x_val)
np.testing.assert_allclose(output_val, output_val_2, atol=1e-6)
示例4: test_layer_sharing_at_heterogeneous_depth_with_concat
# 需要導入模塊: from keras.models import Model [as 別名]
# 或者: from keras.models.Model import from_config [as 別名]
def test_layer_sharing_at_heterogeneous_depth_with_concat():
input_shape = (16, 9, 3)
input_layer = Input(shape=input_shape)
A = Dense(3, name='dense_A')
B = Dense(3, name='dense_B')
C = Dense(3, name='dense_C')
x1 = B(A(input_layer))
x2 = A(C(input_layer))
output = layers.concatenate([x1, x2])
M = Model(inputs=input_layer, outputs=output)
x_val = np.random.random((10, 16, 9, 3))
output_val = M.predict(x_val)
config = M.get_config()
weights = M.get_weights()
M2 = Model.from_config(config)
M2.set_weights(weights)
output_val_2 = M2.predict(x_val)
np.testing.assert_allclose(output_val, output_val_2, atol=1e-6)
示例5: test_activity_regularization
# 需要導入模塊: from keras.models import Model [as 別名]
# 或者: from keras.models.Model import from_config [as 別名]
def test_activity_regularization():
layer = layers.ActivityRegularization(l1=0.01, l2=0.01)
# test in functional API
x = layers.Input(shape=(3,))
z = layers.Dense(2)(x)
y = layer(z)
model = Model(x, y)
model.compile('rmsprop', 'mse')
model.predict(np.random.random((2, 3)))
# test serialization
model_config = model.get_config()
model = Model.from_config(model_config)
model.compile('rmsprop', 'mse')
示例6: reset_pingpong
# 需要導入模塊: from keras.models import Model [as 別名]
# 或者: from keras.models.Model import from_config [as 別名]
def reset_pingpong(self):
""" Reset the models for pingpong training """
logger.debug("Resetting models")
# Clear models and graph
self.predictors = dict()
K.clear_session()
# Load Models for current training run
for model in self.networks.values():
model.network = Model.from_config(model.config)
model.network.set_weights(model.weights)
inputs = self.get_inputs()
self.build_autoencoders(inputs)
self.compile_predictors(initialize=False)
logger.debug("Reset models")