本文整理汇总了Python中tensorflow.python.keras.layers.Layer方法的典型用法代码示例。如果您正苦于以下问题:Python layers.Layer方法的具体用法?Python layers.Layer怎么用?Python layers.Layer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.keras.layers
的用法示例。
在下文中一共展示了layers.Layer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: restore_model
# 需要导入模块: from tensorflow.python.keras import layers [as 别名]
# 或者: from tensorflow.python.keras.layers import Layer [as 别名]
def restore_model(cls, model_bytes): # todo: restore optimizer to support incremental learning
with tempfile.TemporaryDirectory() as tmp_path:
with io.BytesIO(model_bytes) as bytes_io:
with zipfile.ZipFile(bytes_io, 'r', zipfile.ZIP_DEFLATED) as f:
f.extractall(tmp_path)
# Comment this block because tf 1.15 is not supporting Keras Customized Layer
# try:
# keras_model = tf.keras.models.load_model(filepath=tmp_path,
# custom_objects={'ConstantLayer': ConstantLayer})
# except IOError:
# import warnings
# warnings.warn('loading the model as SavedModel is still in experimental stages. '
# 'trying tf.keras.experimental.load_from_saved_model...')
keras_model = \
tf.keras.experimental.load_from_saved_model(saved_model_path=tmp_path,
custom_objects={'ConstantLayer': ConstantLayer})
model = cls()
model._set_model(keras_model)
return model
示例2: activation_fun
# 需要导入模块: from tensorflow.python.keras import layers [as 别名]
# 或者: from tensorflow.python.keras.layers import Layer [as 别名]
def activation_fun(activation, fc):
if isinstance(activation, str):
fc = tf.keras.layers.Activation(activation)(fc)
elif issubclass(activation, Layer):
fc = activation()(fc)
else:
raise ValueError(
"Invalid activation,found %s.You should use a str or a Activation Layer Class." % (activation))
return fc
示例3: export_model
# 需要导入模块: from tensorflow.python.keras import layers [as 别名]
# 或者: from tensorflow.python.keras.layers import Layer [as 别名]
def export_model(self):
with tempfile.TemporaryDirectory() as tmp_path:
# Comment this block because tf 1.15 is not supporting Keras Customized Layer
# try:
# # LOGGER.info("Model saved with model.save method.")
# tf.keras.models.save_model(self._model, filepath=tmp_path, save_format="tf")
# except NotImplementedError:
# import warnings
# warnings.warn('Saving the model as SavedModel is still in experimental stages. '
# 'trying tf.keras.experimental.export_saved_model...')
tf.keras.experimental.export_saved_model(self._model, saved_model_path=tmp_path)
model_bytes = zip_dir_as_bytes(tmp_path)
return model_bytes
示例4: activation_layer
# 需要导入模块: from tensorflow.python.keras import layers [as 别名]
# 或者: from tensorflow.python.keras.layers import Layer [as 别名]
def activation_layer(activation):
if activation == "dice" or activation == "Dice":
act_layer = Dice()
elif (isinstance(activation, str)) or (sys.version_info.major == 2 and isinstance(activation, (str, unicode))):
act_layer = tf.keras.layers.Activation(activation)
elif issubclass(activation, Layer):
act_layer = activation()
else:
raise ValueError(
"Invalid activation,found %s.You should use a str or a Activation Layer Class." % (activation))
return act_layer