当前位置: 首页>>代码示例>>Python>>正文


Python layers.Layer方法代码示例

本文整理汇总了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 
开发者ID:FederatedAI,项目名称:FATE,代码行数:22,代码来源:backend.py

示例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 
开发者ID:ShenDezhou,项目名称:icme2019,代码行数:12,代码来源:activation.py

示例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 
开发者ID:FederatedAI,项目名称:FATE,代码行数:17,代码来源:backend.py

示例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 
开发者ID:shenweichen,项目名称:DeepCTR,代码行数:13,代码来源:activation.py


注:本文中的tensorflow.python.keras.layers.Layer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。