本文整理汇总了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")