BigQuant使用文档

深度学习可视化模块API参考

由jliang创建,最终由jliang 被浏览 5 用户

BigQuant 可视化深度学习模型构建

模块

BigQuant将量化投资需要用到的数据、算法、交易等封装为模块,用户可以直接复用和调参,参考如下示例

# 模块: hello
def run(param1: I.bool ..):
    ...
    return I.Outputs(data_1=.., data_2=..)

其中仅 run 函数会被导出到 M 中用于被调用,调用方式如下:

  • m{数字编号} = M.{模块名}.v{版本号}({参数名}={参数值}, ..)
  • 返回 m{数字编号}.{输出端名} 可用于其他模块调用输入参数
  • 多个模块间输出与参数连接形成DAG
from bigmodule import M
m3 = M.hello.v2(param1=True)
m3.data_1

可视化策略

BigQuant支持代码和可视化拖拽两种策略开发模式,其中可视化是在 python 代码上通过代码注释标记实现,支持代码和可视化模式切换。

  • 可视化策略DAG由 # <aistudiograph># </aistudiograph> 包裹,这中间不要写不必要的代码,会导致解析失败。之前和之后可以添加额外的代码,比如在 # <aistudiograph>from bigmodule import M
  • # @module: 模块和参数。注意:参数行不要添加注释,会导致解析失败,比如 epochs=50, # 增加训练轮数以充分学习 这样的注释会导致解析失败,不可以加这个注释
  • # @param(id="m{数字编号}", name="{函数参数名}") 定义模块函数类型参数

策略回测和部署运行

  • AI生成策略:
    • 使用 Claude Sonnet 4 等AI,参考提示词 请仔细阅读文档 https://bigquant.com/wiki/doc/sy2xw3sYTN ,开发一个CNN 选股股策略
    • 进入 BigQuant AIStudio > 新建 可视化空白策略 > 切换到代码模式 > 输入代码 > 切换回可视化模式 > 可人工进一步调优参数
  • 运行策略,查看回测绩效和进一步优化
  • 提交模拟交易和部署运行,在 我的策略 查看真实数据交易的信号和绩效,绑定仿真账户或者实盘账户交易

深度学习可视化策略示例

简单深度学习策略例子

from bigmodule import M

# <aistudiograph>

# @param(id="m1", name="initialize")
# 交易引擎:初始化函数,只执行一次
from bigquant import bigtrader
def m1_initialize_bigquant_run(context: bigtrader.IContext):
    # 输入数据已经按 score 有序
    import numpy as np
    context.data = (context.data.groupby('date', group_keys=False)
                    .head(10)
                    .reset_index(drop=True))
    context.data['weight'] = (context.data.groupby('date')['score']
                                .rank(method='first', ascending=False)
                                .pipe(lambda x: 1 / np.log2(x + 4))
                                .groupby(context.data['date'])
                                .transform(lambda x: x/x.sum()))

    context.data = bigtrader.TradingDaysRebalance(5, roll_forward=False, context=context).select_rebalance_data(context.data)

# @param(id="m1", name="handle_data")
# 交易引擎:bar数据处理函数,每个时间单位执行一次
from bigquant import bigtrader
def m1_handle_data_bigquant_run(context: bigtrader.IContext, data: bigtrader.IBarData):
    return bigtrader.HandleDataLib.handle_data_weight_based(context, data)

# @module(comment="")
m2 = M.keras_input.v1(
    shape="""18,3""",
    dtype="""float32""",
    sparse=False,
    batch_shape="""None""",
    m_name="""m2"""
)

# @module(comment="")
m5 = M.keras_layer_lstm.v1(
    input_layer=m2.data,
    units=60,
    activation="""tanh""",
    recurrent_activation="""sigmoid""",
    use_bias=True,
    kernel_initializer="""GlorotUniform""",
    recurrent_initializer="""OrthogonalInitializer""",
    bias_initializer="""Zeros""",
    unit_forget_bias=True,
    kernel_regularizer="""None""",
    recurrent_regularizer="""None""",
    bias_regularizer="""None""",
    activity_regularizer="""None""",
    kernel_constraint="""None""",
    recurrent_constraint="""None""",
    bias_constraint="""None""",
    dropout=0,
    recurrent_dropout=0,
    return_sequences=False,
    return_state=False,
    go_backwards=False,
    stateful=False,
    unroll=False,
    use_cudnn="""auto""",
    debug=False,
    m_name="""m5"""
)

# @module(comment="")
m6 = M.keras_layer_dense.v2(
    input_layer=m5.data,
    units=1,
    activation="""tanh""",
    use_bias=True,
    kernel_initializer="""GlorotUniform""",
    bias_initializer="""Zeros""",
    kernel_regularizer="""None""",
    bias_regularizer="""None""",
    activity_regularizer="""None""",
    kernel_constraint="""None""",
    bias_constraint="""None""",
    debug=False,
    m_name="""m6"""
)

# @module(comment="""数据标注和特征抽取""")
m12 = M.dai_sql.v1(
    sql="""SELECT
    -- label 标注,一直涨跌停的label=NAN(在训练阶段会被drop)
    CASE
        WHEN m_lag(high, -1) != m_lag(low, -1) THEN c_winsorize((m_lag(close, -5) / m_lag(open, -1) - 1) * 10, 0.01, 0.99)
    END AS label,

    -- 因子特征
    (high - low) / close AS price_range,                    -- 价格波动范围
    (close - open) / open AS daily_return,                  -- 当日收益率
    close / m_lag(close, 5) - 1 AS return_5d,              -- 5日收益率

    date, instrument
FROM
    cn_stock_prefactors
WHERE
    st_status = 0
ORDER BY date, instrument
""",
    extract_data=False,
    m_name="""m12"""
)

# @module(comment="""抽取训练数据""")
m9 = M.extract_data_dai.v20(
    sql=m12.data,
    start_date="""2024-01-01""",
    start_date_bound_to_trading_date=False,
    end_date="""2024-12-31""",
    end_date_bound_to_trading_date=False,
    before_start_days=90,
    keep_before=False,
    debug=False,
    m_name="""m9"""
)

# @module(comment="""抽取预测数据""")
m10 = M.extract_data_dai.v20(
    sql=m12.data,
    start_date="""2025-01-01""",
    start_date_bound_to_trading_date=True,
    end_date="""2025-06-01""",
    end_date_bound_to_trading_date=True,
    before_start_days=90,
    keep_before=True,
    debug=False,
    m_name="""m10"""
)

# @module(comment="")
m7 = M.keras_model.v6(
    inputs=m2.data,
    outputs=m6.data,
    training_data=m9.data,
    test_data=m10.data,
    optimizer="""Adam""",
    loss="""mean_squared_error""",
    metrics=["""Accuracy""", """mean_squared_error"""],
    epochs=1,
    verbose="""1:输出进度条记录""",
    debug=False,
    m_name="""m7"""
)

# @module(comment="")
m1 = M.bigtraderdev.v6(
    data=m7.predictions,
    market="""cn_stock""",
    frequency="""1d""",
    capital_base=1000000,
    benchmark="""000300.SH""",
    initialize=m1_initialize_bigquant_run,
    handle_data=m1_handle_data_bigquant_run,
    order_price_field_buy="""open""",
    order_price_field_sell="""open""",
    volume_limit=1,
    start_date="""""",
    end_date="""""",
    before_start_days=0,
    plot_charts=True,
    backtest_only=False,
    m_name="""m1"""
)
# </aistudiograph>

深度学习可视化模块

GlobalAveragePooling2D

# M.keras_layer_global_average_pooling_2d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/global_average_pooling2d/

    # import keras

    init_params = dict(
        # data_format=None,
        # keepdims=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    data_format: I.choice("数据格式", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    keepdims: I.bool("是否保留时间维度") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras GlobalAveragePooling2D 层

Conv2D

# M.keras_layer_conv2d.v2
ACTIVATIONS = [
    "elu",
    "exponential",
    "gelu",
    "hard_sigmoid",
    "hard_silu",
    "hard_swish",
    "leaky_relu",
    "linear",
    "log_softmax",
    "mish",
    "relu",
    "relu6",
    "selu",
    "sigmoid",
    "silu",
    "softmax",
    "softplus",
    "softsign",
    "swish",
    "tanh",
    "None",
]
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = ["L1", "L1L2", "L2", "OrthogonalRegularizer", "Regularizer", "None"]
CONSTRAINTS = ["Constraint", "MaxNorm", "MinMaxNorm", "NonNeg", "UnitNorm", "None"]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/convolution2d/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=(1, 1),
        # padding="valid",
        # data_format=None,
        # dilation_rate=(1, 1),
        # groups=1,
        # activation=None,
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # bias_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("卷积核的数量(即输出的维度)。", min=1),  # type: ignore
    kernel_size: I.str("卷积核的大小。可以是一个整数或一个包含两个整数的元组/列表。") = "1",  # type: ignore
    strides: I.str("卷积的步长。可以是一个整数或一个包含两个整数的元组/列表。") = "1",  # type: ignore
    padding: I.choice("填充方法,可以是 'valid' 或 'same'。", ["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式,可以是 'channels_last' 或 'channels_first'。", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("膨胀率。可以是一个整数或一个包含两个整数的元组/列表。") = "1",  # type: ignore
    groups: I.int("输入被分为的组数。每组分别与 filters//groups 个卷积核进行卷积。", min=1) = 1,  # type: ignore
    activation: I.choice("激活函数,如果为 None 则不使用激活函数。", ACTIVATIONS) = "None",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("卷积核的初始化方法", INITIALIZERS) = "GlorotUniform",  # type: ignore
    bias_initializer: I.choice("偏置项的初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    kernel_regularizer: I.choice("卷积核的正则化方法", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置项的正则化方法", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出的正则化方法", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("卷积核的约束方法", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置项的约束方法", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ 二维卷积层,即对图像的空域卷积。

UnitNormalization

# M.keras_layer_unit_normalization.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/normalization_layers/unit_normalization/

    # import keras

    init_params = dict(
        # axis=-1,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    axis: I.str("需要规范化的轴,可以是整数或列表/元组") = -1,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """UnitNormalization 是 Keras 中用于单位规范化的层。它将输入批次中的每个输入规范化,使其在指定轴上的 L2 范数等于 1。

Input

# M.keras_input.v1
def run(
    shape: I.str(
        "shape, 输入张量形状 e.g. `(16, )`, `(16, 32)`,用英文括号和英文逗号(,)分隔的整数列表,例如 `(32,24)`,表示输入数据是一系列的 32x24 的矩阵"
    ) = "None",
    batch_size: I.int("batch_size, static batch size (integer)") = None,
    dtype: I.str("数据类型, The data type expected by the input, as a string (`float32`, `float64`, `int32`...)") = "float32",
    sparse: I.bool("sparse, A boolean specifying whether the placeholder to be created is sparse.") = False,
    batch_shape: I.str(
        "batch_shape, A shape tuple (integer), including the batch size. For instance, `batch_shape=10,32` indicates that the expected input will be batches of 10 32-dimensional vectors. `batch_shape=None,32` indicates batches of an arbitrary number of 32-dimensional vectors."
    ) = "None",
) -> [I.port("layer", "data")]:
    """自定义 Keras 层

ConvLSTM2D

# M.keras_layer_conv_lstm_2d.v1
ACTIVATIONS = [
    "elu",
    "exponential",
    "gelu",
    "hard_sigmoid",
    "hard_silu",
    "hard_swish",
    "leaky_relu",
    "linear",
    "log_softmax",
    "mish",
    "relu",
    "relu6",
    "selu",
    "sigmoid",
    "silu",
    "softmax",
    "softplus",
    "softsign",
    "swish",
    "tanh",
    "None",
]
INITIALIZERS = [
    "glorot_uniform",
    "he_normal",
    "lecun_normal",
    "orthogonal"
]
REGULARIZERS = [
    "l1",
    "l2",
    "l1_l2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "None",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/conv_lstm2d/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=1,
        # padding="valid",
        # data_format=None,
        # dilation_rate=1,
        # activation="tanh",
        # recurrent_activation="sigmoid",
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # recurrent_initializer="orthogonal",
        # bias_initializer="zeros",
        # unit_forget_bias=True,
        # kernel_regularizer=None,
        # recurrent_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # recurrent_constraint=None,
        # bias_constraint=None,
        # dropout=0.0,
        # recurrent_dropout=0.0,
        # seed=None,
        # return_sequences=False,
        # return_state=False,
        # go_backwards=False,
        # stateful=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
        # initial_state=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间维度(卷积中的滤波器数量)。", min=1),  # type: ignore
    kernel_size: I.str("卷积窗口的大小,可以是一个整数或一个包含2个整数的元组/列表。"),  # type: ignore
    strides: I.str("卷积的步长,可以是一个整数或一个包含2个整数的元组/列表。") = "1",  # type: ignore
    padding: I.choice("填充方式,可以是 'valid' 或 'same'。", ["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式,可以是 'channels_last' 或 'channels_first'。", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("膨胀卷积的膨胀率,可以是一个整数或一个包含2个整数的元组/列表。") = "1",  # type: ignore
    activation: I.choice("激活函数,用于将线性输出转换为非线性输出。", ACTIVATIONS) = "tanh",  # type: ignore
    recurrent_activation: I.choice("递归步骤的激活函数。", ACTIVATIONS) = "sigmoid",  # type: ignore
    use_bias: I.bool("是否使用偏置项。") = True,  # type: ignore
    kernel_initializer: I.choice("权重矩阵的初始化方法。", INITIALIZERS) = "glorot_uniform",  # type: ignore
    recurrent_initializer: I.choice("递归权重矩阵的初始化方法。", INITIALIZERS) = "orthogonal",  # type: ignore
    bias_initializer: I.choice("偏置项的初始化方法。", ["zeros", "ones", "None"]) = "zeros",  # type: ignore
    unit_forget_bias: I.bool("是否在初始化时为遗忘门的偏置项加1。") = True,  # type: ignore
    kernel_regularizer: I.choice("应用于权重矩阵的正则化函数。", REGULARIZERS) = "None",  # type: ignore
    recurrent_regularizer: I.choice("应用于递归权重矩阵的正则化函数。", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("应用于偏置向量的正则化函数。", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("应用于输出的正则化函数。", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("应用于权重矩阵的约束函数。", CONSTRAINTS) = "None",  # type: ignore
    recurrent_constraint: I.choice("应用于递归权重矩阵的约束函数。", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("应用于偏置向量的约束函数。", CONSTRAINTS) = "None",  # type: ignore
    dropout: I.float("输入的线性变换中要丢弃的单元的比例。", min=0.0, max=1.0) = 0.0,  # type: ignore
    recurrent_dropout: I.float("递归状态的线性变换中要丢弃的单元的比例。", min=0.0, max=1.0) = 0.0,  # type: ignore
    seed: I.int("随机种子,用于dropout。") = None,  # type: ignore
    return_sequences: I.bool("是否返回输出序列中的最后一个输出,还是完整序列。") = False,  # type: ignore
    return_state: I.bool("是否返回最后一个状态。") = False,  # type: ignore
    go_backwards: I.bool("是否反向处理输入序列并返回反转的序列。") = False,  # type: ignore
    stateful: I.bool("是否使用状态化,默认False。") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ConvLSTM2D 是 Keras 中用于创建2D卷积LSTM层的类。

Dot

# M.keras_layer_dot.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/merging_layers/dot/
    
    # import keras

    init_params = dict(
        # axes,
        # normalize=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    axes: I.str("轴,沿哪个轴进行点积,可以是整数或整数元组") = "1",  # type: ignore
    normalize: I.bool("L2正则化,是否在进行点积前对样本进行L2正则化") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer_1: I.port("第一个输入", optional=False) = None,  # type: ignore
    input_layer_2: I.port("第二个输入", optional=False) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Dot 是 Keras 中用于计算两个张量点积的层。

PReLU

# M.keras_layer_prelu.v1
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = ["L1", "L2", "L1L2", "OrthogonalRegularizer", "Regularizer", "None"]
CONSTRAINTS = ["Constraint", "MaxNorm", "MinMaxNorm", "NonNeg", "UnitNorm", "None"]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/activation_layers/prelu/

    # import keras

    init_params = dict(
        # alpha_initializer="Zeros",
        # alpha_regularizer="None",
        # alpha_constraint="None",
        # shared_axes=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    alpha_initializer: I.choice("权重矩阵初始化方法,alpha_initializer", INITIALIZERS) = "Zeros",  # type: ignore
    alpha_regularizer: I.choice("权重矩阵正则化方法,alpha_regularizer", REGULARIZERS) = "None",  # type: ignore
    alpha_constraint: I.choice("权重矩阵上约束方法,alpha_constraint", CONSTRAINTS) = "None",  # type: ignore
    shared_axes: I.str("共享轴,沿着这些轴共享可学习的参数,例如 [1, 2] 表示在高度和宽度轴上共享参数", specific_type_name="list") = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """PReLU 是 Keras 中的参数化修正线性单元激活层。

ZeroPadding2D

# M.keras_layer_zero_padding_2d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/zero_padding2d/

    # import keras

    init_params = dict(
        # padding=(1, 1),
        # data_format=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    padding: I.str("Padding,可以是整数、2个整数的元组或2个2个整数的元组,表示在图像的高度和宽度方向上的填充量") = "(1, 1)",  # type: ignore
    data_format: I.choice("数据格式,可以是 'channels_last' 或 'channels_first'", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ZeroPadding2D 是 Keras 中用于对 2D 输入(如图片)进行零填充的层。

AveragePooling2D

# M.keras_layer_average_pooling_2d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/average_pooling2d/

    # import keras

    init_params = dict(
        # pool_size,
        # strides=None,
        # padding="valid",
        # data_format=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    pool_size: I.str("池化窗口大小,可以是一个整数或一个包含两个整数的元组"),  # type: ignore
    strides: I.str("池化步长,可以是一个整数或一个包含两个整数的元组,默认为池化窗口大小") = None,  # type: ignore
    padding: I.choice("填充模式", ["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式", ["channels_last", "channels_first"]) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras AveragePooling2D 层

Masking

# M.keras_layer_masking.v2
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/core_layers/masking/

    # import keras

    init_params = dict(
        # mask_value = 0.0,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    mask_value: I.float("用于跳过时间步的掩码值") = 0.0,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """屏蔽层。使用给定的值对输入的序列信号进行“屏蔽”,用以定位需要跳过的时间步。对于输入张量的时间步,即输入张量的第1维度(维度从0开始算,见例子),如果输入张量在该时间步上都等于mask_value,则该时间步将在模型接下来的所有层(只要支持masking)被跳过(屏蔽)。如果模型接下来的一些层不支持masking,却接受到masking过的数据,则抛出异常。

Conv2DTranspose

# M.keras_layer_conv2d_transpose.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "min_max_norm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/convolution2d_transpose/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=(1, 1),
        # padding="valid",
        # data_format=None,
        # dilation_rate=(1, 1),
        # activation=None,
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # bias_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间维度,即卷积核的数量", min=1),  # type: ignore
    kernel_size: I.str("卷积核大小,可以是一个整数或一个包含2个整数的元组/列表") = "3",  # type: ignore
    strides: I.str("卷积步长,可以是一个整数或一个包含2个整数的元组/列表") = "1",  # type: ignore
    padding: I.choice("填充方式,valid表示不填充,same表示填充使得输出尺寸等于输入尺寸", values=["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式,channels_last表示通道在最后,channels_first表示通道在最前", values=["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("扩张率,可以是一个整数或一个包含2个整数的元组/列表") = "1",  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "relu",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权值初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    kernel_regularizer: I.choice("权值正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权值约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """keras Conv2DTranspose层

MaxPooling1D

# M.keras_layer_max_pooling_1d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/max_pooling1d/

    # import keras

    init_params = dict(
        # pool_size=2,
        # strides=None,
        # padding="valid",
        # data_format="channels_last",
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    pool_size: I.int("Max pooling 窗口大小, pool_size, 正整数", min=1) = 2,  # type: ignore
    strides: I.int("Max pooling 步幅, strides, 可以为正整数或 None。如果为 None,默认等于 pool_size") = None,  # type: ignore
    padding: I.choice("填充方式, padding,'valid' 表示不填充,'same' 表示填充保持输出大小等于输入大小", ["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式, data_format,输入数据的维度顺序,'channels_last' 表示 (batch, steps, features),'channels_first' 表示 (batch, features, steps)", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras MaxPooling1D 层

ActivityRegularization

# M.keras_layer_activity_regularization.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/regularization_layers/activity_regularization/

    # import keras

    init_params = dict(
        # l1=0.0,
        # l2=0.0,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    l1: I.float("L1 正则化因子(正浮点数)", min=0.0) = 0.0,  # type: ignore
    l2: I.float("L2 正则化因子(正浮点数)", min=0.0) = 0.0,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ActivityRegularization 是一个 Keras 层,用于根据输入活动对成本函数应用更新。

Dense

# M.keras_layer_dense.v2
ACTIVATIONS = [
    "elu",
    "exponential",
    "gelu",
    "hard_sigmoid",
    "hard_silu",
    "hard_swish",
    "leaky_relu",
    "linear",
    "log_softmax",
    "mish",
    "relu",
    "relu6",
    "selu",
    "sigmoid",
    "silu",
    "softmax",
    "softplus",
    "softsign",
    "swish",
    "tanh",
    "None",
]
LOSSES = [
    "binary_crossentropy",
    "binary_focal_crossentropy",
    "categorical_crossentropy",
    "categorical_focal_crossentropy",
    "categorical_hinge",
    "cosine_similarity",
    "ctc",
    "dice",
    "hinge",
    "huber",
    "kl_divergence",
    "log_cosh",
    "mean_absolute_error",
    "mean_absolute_percentage_error",
    "mean_squared_error",
    "mean_squared_logarithmic_error",
    "poisson",
    "sparse_categorical_crossentropy",
    "squared_hinge",
    "None"
]
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = ["L1", "L1L2", "L2", "OrthogonalRegularizer", "Regularizer", "None"]
CONSTRAINTS = ["Constraint", "MaxNorm", "MinMaxNorm", "NonNeg", "UnitNorm", "None"]
LORA_RANK_DESC = """lora_rank/低秩适应,这个参数用于实现 LoRA(Low-Rank Adaptation,低秩适应)。
LoRA 是一种用于减少大规模全连接层(Dense Layer)微调计算成本的方法。
LoRA(Low-Rank Adaptation)是一种技术,通过将层的权重矩阵分解为两个较低秩的可训练矩阵,从而减少参数数量和计算复杂度。这对于微调大型模型特别有用,因为它可以显著降低计算和存储成本,同时保持模型的性能。
如果设置了 lora_rank,Dense 层的前向传递将实现 LoRA。具体来说,这会将层的权重矩阵设为不可训练,并用两个低秩可训练矩阵的乘积来表示这个权重矩阵的变化。这对于减少大型全连接层微调的计算成本非常有用。
你可以在创建 Dense 层时通过设置 lora_rank 参数来启用 LoRA。如果你已经有一个定义好的 Dense 层,也可以通过调用 layer.enable_lora(rank) 方法来启用 LoRA。
"""
USER_FUNC_DESC = """自定义函数,自定义设置层构建参数和调用参数"""
USER_FUNC = """def bigquant_run():
    # https://keras.io/api/layers/core_layers/dense/

    # import keras

    init_params = dict(
        # units,
        # activation=None,
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # bias_constraint=None,
        # lora_rank=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    units: I.int("输出空间维度,该层神经元的数量,决定了输出的维度。", min=1),  # type: ignore
    activation: I.choice("激活函数,用于将线性输出转换为非线性输出", ACTIVATIONS) = "tanh",  # type: ignore
    use_bias: I.bool("use_bias,是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权重矩阵初始化方法,kernel_initializer", INITIALIZERS) = "GlorotUniform",  # type: ignore
    bias_initializer: I.choice("偏置项初始化方法,bias_initializer,使用的是使用默认参数", INITIALIZERS) = "Zeros",  # type: ignore
    kernel_regularizer: I.choice("权重矩阵正则化方法,kernel_regularizer", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置项正则项,bias_regularizer", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项,activity_regularizer", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权重矩阵上约束方法,kernel_constraint", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置项约束方法,bias_constraint", CONSTRAINTS) = "None",  # type: ignore
    lora_rank: I.int(LORA_RANK_DESC) = None,  # type: ignore
    user_func: I.code(USER_FUNC_DESC, I.code_python, USER_FUNC, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Dense 是 Keras 中用于创建全连接层(也称为密集层、全连接层)的类。全连接层是神经网络中最基本的层类型之一,其中每个输入节点与每个输出节点都连接。

Identity

# M.keras_layer_identity.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/core_layers/identity/

    # import keras

    init_params = dict(
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras Identity 层

GroupedQueryAttention

# M.keras_layer_group_query_attention.v1
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = [
    "L1",
    "L2",
    "L1L2",
    "OrthogonalRegularizer",
    "Regularizer",
    "None"
]
CONSTRAINTS = [
    "Constraint",
    "MaxNorm",
    "MinMaxNorm",
    "NonNeg",
    "UnitNorm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/attention_layers/group_query_attention/

    # import keras

    init_params = dict(
        # head_dim,
        # num_query_heads,
        # num_key_value_heads,
        # dropout=0.0,
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # bias_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # query,
        # value,
        # key=None,
        # attention_mask=None,
        # return_attention_scores=False,
        # training=None,
        # use_causal_mask=False,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    head_dim: I.int("每个注意力头的尺寸。", min=1),  # type: ignore
    num_query_heads: I.int("查询注意力头的数量。", min=1),  # type: ignore
    num_key_value_heads: I.int("键和值注意力头的数量。", min=1),  # type: ignore
    dropout: I.float("dropout概率。", min=0.0, max=1.0) = 0.0,  # type: ignore
    use_bias: I.bool("是否使用偏置项。") = True,  # type: ignore
    kernel_initializer: I.choice("权重矩阵初始化方法,kernel_initializer", INITIALIZERS) = "GlorotUniform",  # type: ignore
    bias_initializer: I.choice("偏置项初始化方法,bias_initializer", INITIALIZERS) = "Zeros",  # type: ignore
    kernel_regularizer: I.choice("权重矩阵正则化方法,kernel_regularizer", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置项正则项,bias_regularizer", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项,activity_regularizer", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权重矩阵上约束方法,kernel_constraint", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置项约束方法,bias_constraint", CONSTRAINTS) = "None",  # type: ignore
    query: I.port("Query tensor", optional=True) = None,  # type: ignore
    value: I.port("Value tensor", optional=True) = None,  # type: ignore
    key: I.port("Key tensor", optional=True) = None,  # type: ignore
    attention_mask: I.port("Attention mask", optional=True) = None,  # type: ignore
    return_attention_scores: I.bool("是否返回注意力分数。") = False,  # type: ignore
    training: I.bool("是否在训练模式下运行。") = None,  # type: ignore
    use_causal_mask: I.bool("是否使用因果蒙版。") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
) -> [
    I.port("attention_output", "attention_output"),
    I.port("attention_scores", "attention_scores"),
    ]:  # type: ignore
    """GroupedQueryAttention 是 Keras 中用于创建分组查询注意力层的类。

Bidirectional

# M.keras_layer_bidirectional.v1
MERGE_MODES = [
    "sum",
    "mul",
    "concat",
    "ave",
    "None",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/bidirectional/

    # import keras

    init_params = dict(
        # layer,
        # merge_mode='concat',
        # weights=None,
        # backward_layer=None,
        # **kwargs
    )
    call_params = dict(
        # sequence,
        # training=None,
        # mask=None,
        # initial_state=None
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    layer: I.port("待封装的RNN层", optional=False) = None,  # type: ignore
    merge_mode: I.choice("前向和后向 RNN 的输出合并模式", MERGE_MODES,) = "concat",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    backward_layer: I.port("用于处理后向输入的RNN层", optional=True) = None,  # type: ignore
    input_layer: I.port("一个三维张量, [batch, timesteps, feature]", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras Bidirectional 层

ZeroPadding3D

# M.keras_layer_zero_padding_3d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/zero_padding3d/

    # import keras

    init_params = dict(
        # padding=((1, 1), (1, 1), (1, 1)),
        # data_format=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    padding: I.str("Padding,可以是一个整数或一个包含三个整数的元组,或一个包含三个二元组的元组") = "((1, 1), (1, 1), (1, 1))",  # type: ignore
    data_format: I.choice("数据格式,可以是 'channels_last' 或 'channels_first'", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ZeroPadding3D 是 Keras 中用于在 3D 数据(空间或时空数据)上添加零填充的层。

DepthwiseConv1D

# M.keras_layer_depthwise_conv1d.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "min_max_norm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/depthwise_convolution1d/

    # import keras

    init_params = dict(
        # kernel_size,
        # strides=1,
        # padding="valid",
        # depth_multiplier=1,
        # data_format=None,
        # dilation_rate=1,
        # activation=None,
        # use_bias=True,
        # depthwise_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # depthwise_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # depthwise_constraint=None,
        # bias_constraint=None,
        # **kwargs,
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    kernel_size: I.str("卷积核大小,可以是一个整数或一个包含1个整数的元组/列表") = "3",  # type: ignore
    strides: I.str("卷积步长,可以是一个整数或一个包含1个整数的元组/列表") = "1",  # type: ignore
    padding: I.choice("填充方式,valid表示不填充,same表示填充使得输出尺寸等于输入尺寸", values=["valid", "same"]) = "valid",  # type: ignore
    depth_multiplier: I.int("每个输入通道的深度卷积输出通道数", min=1) = 1,  # type: ignore
    data_format: I.choice("数据格式,channels_last表示通道在最后,channels_first表示通道在最前", values=["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("膨胀率,可以是一个整数或一个包含1个整数的元组/列表") = "1",  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "relu",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    depthwise_initializer: I.choice("深度卷积核初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    depthwise_regularizer: I.choice("深度卷积核正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    depthwise_constraint: I.choice("深度卷积核约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras DepthwiseConv1D 层

SimpleRNNCell

# M.keras_layer_simple_rnn_cell.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "MaxNorm",
    "NonNeg",
    "UnitNorm",
    "MinMaxNorm",
    "None",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/simple_rnn_cell/

    # import keras

    init_params = dict(
        # units,
        # activation="tanh",
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # recurrent_initializer="orthogonal",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # recurrent_regularizer=None,
        # bias_regularizer=None,
        # kernel_constraint=None,
        # recurrent_constraint=None,
        # bias_constraint=None,
        # dropout=0.0,
        # recurrent_dropout=0.0,
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # states,
        # training=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    units: I.int("输出空间维度,units,正整数", min=1),  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "tanh",  # type: ignore
    use_bias: I.bool("use_bias,是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权值初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    recurrent_initializer: I.choice("循环权值初始化方法", INITIALIZERS) = "orthogonal",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "zeros",  # type: ignore
    kernel_regularizer: I.choice("权值正则项", REGULARIZERS) = "None",  # type: ignore
    recurrent_regularizer: I.choice("循环权值正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权值约束项", CONSTRAINTS) = "None",  # type: ignore
    recurrent_constraint: I.choice("循环权值约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    dropout: I.float("输入的随机丢弃比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    recurrent_dropout: I.float("循环状态的随机丢弃比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    seed: I.int("随机种子,用于dropout") = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
    states: I.port("状态", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras SimpleRNNCell 层

MaxPooling3D

# M.keras_layer_max_pooling_3d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/max_pooling3d/

    # import keras

    init_params = dict(
        # pool_size=(2, 2, 2),
        # strides=None,
        # padding="valid",
        # data_format="channels_last",
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    pool_size: I.str("Max pooling 窗口大小, pool_size, 可以是整数或含有3个整数的元组,格式如 '2,2,2'", specific_type_name="tuple") = "2,2,2",  # type: ignore
    strides: I.str("Max pooling 步幅, strides, 可以为整数、含有3个整数的元组或 None。如果为 None,默认等于 pool_size", specific_type_name="tuple") = None,  # type: ignore
    padding: I.choice("填充方式, padding,'valid' 表示不填充,'same' 表示填充保持输出大小等于输入大小", ["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式, data_format,输入数据的维度顺序,'channels_last' 表示 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels),'channels_first' 表示 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras MaxPooling3D 层

Conv1DTranspose

# M.keras_layer_conv1d_transpose.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "min_max_norm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/convolution1d_transpose/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=1,
        # padding="valid",
        # data_format=None,
        # dilation_rate=1,
        # activation=None,
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # bias_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间维度,即卷积核的数量", min=1),  # type: ignore
    kernel_size: I.str("卷积核大小,可以是一个整数或一个包含1个整数的元组/列表") = "3",  # type: ignore
    strides: I.str("卷积步长,可以是一个整数或一个包含1个整数的元组/列表") = "1",  # type: ignore
    padding: I.choice("填充方式,valid表示不填充,same表示填充使得输出尺寸等于输入尺寸", values=["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式,channels_last表示通道在最后,channels_first表示通道在最前", values=["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("扩张率,可以是一个整数或一个包含1个整数的元组/列表") = "1",  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "relu",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权值初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    kernel_regularizer: I.choice("权值正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权值约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入1", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras Conv1DTranspose 层

BaseRNN

# M.keras_layer_base_rnn.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/rnn/

    # import keras

    init_params = dict(
        # cell,
        # return_sequences=False,
        # return_state=False,
        # go_backwards=False,
        # stateful=False,
        # unroll=False,
        # zero_output_for_mask=False,
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
        # initial_state=None
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    cell: I.port("RNN单元实例或RNN单元实例列表", optional=False) = None,  # type: ignore
    return_sequences: I.bool("是否返回整个序列") = False,  # type: ignore
    return_state: I.bool("是否返回最终状态") = False,  # type: ignore
    go_backwards: I.bool("是否反向处理输入序列") = False,  # type: ignore
    stateful: I.bool("是否保持状态") = False,  # type: ignore
    unroll: I.bool("是否展开循环") = False,  # type: ignore
    zero_output_for_mask: I.bool("是否在掩码时间步输出零") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras BaseRNN 层

SeparableConv1D

# M.keras_layer_separable_conv1d.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "l1_l2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "min_max_norm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/separable_convolution1d/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=1,
        # padding="valid",
        # data_format=None,
        # dilation_rate=1,
        # depth_multiplier=1,
        # activation=None,
        # use_bias=True,
        # depthwise_initializer="glorot_uniform",
        # pointwise_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # depthwise_regularizer=None,
        # pointwise_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # depthwise_constraint=None,
        # pointwise_constraint=None,
        # bias_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间维度,即卷积核的数量", min=1),  # type: ignore
    kernel_size: I.str("卷积核大小,可以是一个整数或一个包含1个整数的元组/列表") = "3",  # type: ignore
    strides: I.str("卷积步长,可以是一个整数或一个包含1个整数的元组/列表") = "1",  # type: ignore
    padding: I.choice("填充方式,valid表示不填充,same表示填充使得输出尺寸等于输入尺寸", values=["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式,channels_last表示通道在最后,channels_first表示通道在最前", values=["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("膨胀率,可以是一个整数或一个包含1个整数的元组/列表") = "1",  # type: ignore
    depth_multiplier: I.int("每个输入通道的深度卷积输出通道数", min=1) = 1,  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "relu",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    depthwise_initializer: I.choice("深度卷积核初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    pointwise_initializer: I.choice("点卷积核初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    depthwise_regularizer: I.choice("深度卷积核正则项", REGULARIZERS) = "None",  # type: ignore
    pointwise_regularizer: I.choice("点卷积核正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    depthwise_constraint: I.choice("深度卷积核约束项", CONSTRAINTS) = "None",  # type: ignore
    pointwise_constraint: I.choice("点卷积核约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras SeparableConv1D 层

Cropping1D

# M.keras_layer_cropping_1d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/cropping1d/

    # import keras

    init_params = dict(
        # cropping,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    cropping: I.str("裁剪参数,可以是单个整数,或包含两个整数的元组。") = "(1,1)",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Cropping1D 是 Keras 中用于创建 1D 裁剪层的类。它沿着时间维度(轴 1)进行裁剪。

AveragePooling1D

# M.keras_layer_average_pooling_1d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/average_pooling1d/

    # import keras

    init_params = dict(
        # pool_size,
        # strides=None,
        # padding="valid",
        # data_format=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    pool_size: I.int("最大池化窗口的大小", min=1),  # type: ignore
    strides: I.int("池化步长,默认为池化窗口大小", min=1) = None,  # type: ignore
    padding: I.choice("填充模式", ["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式", ["channels_last", "channels_first"]) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras AveragePooling1D 层

Conv1D

# M.keras_layer_conv1d.v2
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "l1",
    "l2",
    "l1_l2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "min_max_norm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/convolution1d/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides = 1,
        # padding = "valid",
        # data_format = None,
        # dilation_rate = 1,
        # groups = 1,
        # activation = None,
        # use_bias = True,
        # kernel_initializer = "glorot_uniform",
        # bias_initializer = "zeros",
        # kernel_regularizer = None,
        # bias_regularizer = None,
        # activity_regularizer = None,
        # kernel_constraint = None,
        # bias_constraint = None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间维度,即卷积核的数量)", min=1),  # type: ignore
    kernel_size: I.int("卷积窗口的大小"),  # type: ignore
    strides: I.int("卷积的步长长度") = 1,  # type: ignore
    padding: I.choice("填充模式", ["valid", "same", "causal"]) = "valid",  # type: ignore
    data_format: I.choice("输入的维度顺序", ["channels_last", "channels_first"]) = None,  # type: ignore
    dilation_rate: I.int("膨胀率") = 1,  # type: ignore
    groups: I.int("输入沿通道轴分组的数量") = 1,  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "linear",  # type: ignore
    use_bias: I.bool("是否在输出中添加偏置") = True,  # type: ignore
    kernel_initializer: I.choice("卷积核的初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    bias_initializer: I.choice("偏置向量的初始化方法", INITIALIZERS) = "zeros",  # type: ignore
    kernel_regularizer: I.choice("卷积核的正则化函数", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量的正则化函数", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出的正则化函数", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("应用于卷积核的约束函数", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("应用于偏置向量的约束函数", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """一维卷积层(即时域卷积),用以在一维输入信号上进行邻域滤波。

TimeDistributed

# M.keras_layer_time_distributed.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/time_distributed/

    # import keras

    init_params = dict(
        # layer,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    layer: I.port("待封装的层", optional=False) = None,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """TimeDistributed 层

StackedRNNCells

# M.keras_layer_stacked_rnn_cell.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/stacked_rnn_cell/

    # import keras

    init_params = dict(
        # cells,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    cells: I.port("RNN单元实例列表", optional=False) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """StackedRNNCells 层

SimpleRNN

# M.keras_layer_simple_rnn.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "MaxNorm",
    "NonNeg",
    "UnitNorm",
    "MinMaxNorm",
    "None",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/simple_rnn/

    # import keras

    init_params = dict(
        # units,
        # activation="tanh",
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # recurrent_initializer="orthogonal",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # recurrent_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # recurrent_constraint=None,
        # bias_constraint=None,
        # dropout=0.0,
        # recurrent_dropout=0.0,
        # return_sequences=False,
        # return_state=False,
        # go_backwards=False,
        # stateful=False,
        # unroll=False,
        # **kwargs
    )
    call_params = dict(
        # sequence,
        # mask=None,
        # training=None,
        # initial_state=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    units: I.int("输出空间维度,正整数", min=1),  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "tanh",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权值初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    recurrent_initializer: I.choice("循环权值初始化方法", INITIALIZERS) = "orthogonal",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "zeros",  # type: ignore
    kernel_regularizer: I.choice("权值正则项", REGULARIZERS) = "None",  # type: ignore
    recurrent_regularizer: I.choice("循环权值正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权值约束项", CONSTRAINTS) = "None",  # type: ignore
    recurrent_constraint: I.choice("循环权值约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    dropout: I.float("输入的随机丢弃比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    recurrent_dropout: I.float("循环状态的随机丢弃比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    return_sequences: I.bool("是否返回整个序列") = False,  # type: ignore
    return_state: I.bool("是否返回最终状态") = False,  # type: ignore
    go_backwards: I.bool("是否反向处理输入序列") = False,  # type: ignore
    stateful: I.bool("是否保持状态") = False,  # type: ignore
    unroll: I.bool("是否展开循环") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("一个三维张量, [batch, timesteps, feature]", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras SimpleRNN 层

TextVectorization

# M.keras_layer_text_vectorization.v1
STANDARDIZES = [
    "None",
    "lower_and_strip_punctuation",
    "lower",
    "strip_punctuation"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run(
    # https://keras.io/api/layers/preprocessing_layers/text/text_vectorization/

    # import keras

    init_params = dict(
        # max_tokens=None,
        # standardize="lower_and_strip_punctuation",
        # split="whitespace",
        # ngrams=None,
        # output_mode="int",
        # output_sequence_length=None,
        # pad_to_max_tokens=False,
        # vocabulary=None,
        # idf_weights=None,
        # sparse=False,
        # ragged=False,
        # encoding="utf-8",
        # name=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    max_tokens: I.int("最大词汇表大小", min=1) = None,  # type: ignore
    standardize: I.choice("标准化选项", STANDARDIZES) = "lower_and_strip_punctuation",     # type: ignore
    split: I.choice("拆分选项", ["None", "whitespace", "character"]) = "whitespace",   # type: ignore
    ngrams: I.str("n-grams 选项,可以为 None, 整数或整数元组") = None,  # type: ignore
    output_mode: I.choice("输出模式", ["int", "multi_hot", "count", "tf_idf"]) = "int",  # type: ignore
    output_sequence_length: I.int("输出序列长度,仅在 output_mode 为 int 时有效") = None,  # type: ignore
    pad_to_max_tokens: I.bool("是否填充到最大词汇表大小,仅在 multi_hot、count 和 tf_idf 模式下有效") = False,  # type: ignore
    vocabulary: I.str("词汇表,可以是字符串数组或文件路径") = None,  # type: ignore
    idf_weights: I.str("逆文档频率权重,仅在 output_mode 为 tf_idf 时有效") = None,  # type: ignore
    sparse: I.bool("是否返回稀疏张量,仅在 multi_hot、count 和 tf_idf 模式下有效") = False,  # type: ignore
    ragged: I.bool("是否返回不规则张量,仅在 output_mode 为 int 时有效") = False,  # type: ignore
    encoding: I.str("文本编码") = "utf-8",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras TextVectorization 层

ConvLSTM3D

# M.keras_layer_conv_lstm_3d.v1
ACTIVATIONS = [
    "elu",
    "exponential",
    "gelu",
    "hard_sigmoid",
    "hard_silu",
    "hard_swish",
    "leaky_relu",
    "linear",
    "log_softmax",
    "mish",
    "relu",
    "relu6",
    "selu",
    "sigmoid",
    "silu",
    "softmax",
    "softplus",
    "softsign",
    "swish",
    "tanh",
    "None",
]
INITIALIZERS = [
    "glorot_uniform",
    "he_normal",
    "lecun_normal",
    "orthogonal"
]
REGULARIZERS = [
    "l1",
    "l2",
    "l1_l2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "None",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/conv_lstm3d/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=1,
        # padding="valid",
        # data_format=None,
        # dilation_rate=1,
        # activation="tanh",
        # recurrent_activation="sigmoid",
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # recurrent_initializer="orthogonal",
        # bias_initializer="zeros",
        # unit_forget_bias=True,
        # kernel_regularizer=None,
        # recurrent_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # recurrent_constraint=None,
        # bias_constraint=None,
        # dropout=0.0,
        # recurrent_dropout=0.0,
        # seed=None,
        # return_sequences=False,
        # return_state=False,
        # go_backwards=False,
        # stateful=False,
        # **kwargs
    )

    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
        # initial_state=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间维度,该层卷积滤波器的数量。", min=1),  # type: ignore
    kernel_size: I.str("卷积窗口的大小,整数或包含3个整数的元组/列表。") = "3,3,3",  # type: ignore
    strides: I.str("卷积的步长,整数或包含3个整数的元组/列表。") = "1,1,1",  # type: ignore
    padding: I.choice("填充方式,可以是 'valid' 或 'same'。", ["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式,可以是 'channels_last' 或 'channels_first'。", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("膨胀率,整数或包含3个整数的元组/列表。") = "1,1,1",  # type: ignore
    activation: I.choice("激活函数,用于将线性输出转换为非线性输出", ACTIVATIONS) = "tanh",  # type: ignore
    recurrent_activation: I.choice("用于递归步骤的激活函数。", ACTIVATIONS) = "sigmoid",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权重矩阵初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    recurrent_initializer: I.choice("递归权重矩阵初始化方法", INITIALIZERS) = "orthogonal",  # type: ignore
    bias_initializer: I.choice("偏置项初始化方法", INITIALIZERS) = "zeros",  # type: ignore
    unit_forget_bias: I.bool("是否添加1到遗忘门的偏置项。") = True,  # type: ignore
    kernel_regularizer: I.choice("权重矩阵正则化方法", REGULARIZERS) = "None",  # type: ignore
    recurrent_regularizer: I.choice("递归权重矩阵正则化方法", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置项正则化方法", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则化方法", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权重矩阵约束方法", CONSTRAINTS) = "None",  # type: ignore
    recurrent_constraint: I.choice("递归权重矩阵约束方法", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置项约束方法", CONSTRAINTS) = "None",  # type: ignore
    dropout: I.float("输入的dropout比率。", min=0.0, max=1.0) = 0.0,  # type: ignore
    recurrent_dropout: I.float("递归状态的dropout比率。", min=0.0, max=1.0) = 0.0,  # type: ignore
    seed: I.int("随机种子。") = None,  # type: ignore
    return_sequences: I.bool("是否返回输出序列中的最后一个输出,或完整序列。") = False,  # type: ignore
    return_state: I.bool("是否返回最后一个状态。") = False,  # type: ignore
    go_backwards: I.bool("是否倒序处理输入序列并返回反转的序列。") = False,  # type: ignore
    stateful: I.bool("是否将每个批次的最后一个状态作为下一个批次的初始状态。") = False,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ConvLSTM3D 是 Keras 中用于创建三维卷积长短期记忆层(ConvLSTM3D)的类。

Keras 模型训练&预测

# M.keras_model.v6
USER_PARAMS_DESC = """自定义参数"""
DEFAULT_USER_PARAMS = """def bigquant_run(model):
    # 自定义 model.compile 和 model.fit 的参数
    # https://keras.io/api/models/model_training_apis/

    import keras

    # class CustomMetric(keras.metrics.Metric):
    #     ... ask QuantChat to write one for you

    # 定义数据生成器
    # class DataGenerator(Sequence):
    #     def __init__(self, data, seq_length, batch_size):
    #         self.data = data
    #         self.seq_length = seq_length
    #         self.batch_size = batch_size
    #         self.indices = np.arange(len(data) - seq_length)
    #     def __len__(self):
    #         return len(self.indices) // self.batch_size
    #     def __getitem__(self, idx):
    #         batch_indices = self.indices[idx * self.batch_size:(idx + 1) * self.batch_size]
    #         x_batch = np.array([self.data[i:i + self.seq_length] for i in batch_indices])
    #         y_batch = np.array([self.data[i + self.seq_length, 1] for i in batch_indices])
    #         y_batch = y_batch.reshape(-1, 1)
    #         return x_batch, y_batch

    compile_params = {
        # "optimizer": keras.optimizers.Adam(learning_rate=0.01),
        # "loss": keras.losses.SparseCategoricalCrossentropy(),
        # "loss_weights": None,
        # "metrics": ['accuracy', keras.metrics.Precision(), keras.metrics.Recall(), CustomMetric()]),
        # "weighted_metrics": None,
        # "run_eagerly": False,
        # "steps_per_execution": 1,
        # "jit_compile": "auto",
        # "auto_scale_loss": True,
    }

    fit_params = {
        # "batch_size": None,
        # "epochs": 1,
        # "verbose": "auto",
        # "callbacks": None,
        # "validation_split": 0.0,
        # "validation_data": None,
        # "shuffle": True,
        # "class_weight": None,
        # "sample_weight": None,
        # "initial_epoch": 0,
        # "steps_per_epoch": None,
        # "validation_steps": None,
        # "validation_batch_size": None,
        # "validation_freq": 1,
    }

    # load model and model.predict params
    predict_params = {
        # "batch_size": None,
        # "verbose": "auto",
        # "steps": None,
        # "callbacks": None,
    }

    return {"compile": compile_params, "fit": fit_params, "predict": predict_params}
"""
OPTIMIZERS = ["SGD", "RMSprop", "Adam", "AdamW", "Adadelta", "Adagrad", "Adamax", "Adafactor", "Nadam", "Ftrl", "Lion"]
OPTIMIZER_DESC = """优化器/optimizer: https://keras.io/api/optimizers/ 优化器使用的是使用默认参数。可以使用 自定义参数"""
LOSSES = [
    "binary_crossentropy",
    "binary_focal_crossentropy",
    "categorical_crossentropy",
    "categorical_focal_crossentropy",
    "categorical_hinge",
    "cosine_similarity",
    "ctc",
    "deserialize",
    "dice",
    "get",
    "hinge",
    "huber",
    "kl_divergence",
    "log_cosh",
    "mean_absolute_error",
    "mean_absolute_percentage_error",
    "mean_squared_error",
    "mean_squared_logarithmic_error",
    "poisson",
    "serialize",
    "sparse_categorical_crossentropy",
    "squared_hinge",
]
LOSS_DESC = "损失函数/loss: https://keras.io/api/losses/ 如果需要自定义,可以使用 自定义参数"
METRICS = [
    "AUC",
    "Accuracy",
    "BinaryAccuracy",
    "BinaryCrossentropy",
    "BinaryIoU",
    "CategoricalAccuracy",
    "CategoricalCrossentropy",
    "CategoricalHinge",
    "CosineSimilarity",
    "F1Score",
    "FBetaScore",
    "FalseNegatives",
    "FalsePositives",
    "Hinge",
    "IoU",
    "KLDivergence",
    "LogCoshError",
    "Mean",
    "MeanAbsoluteError",
    "MeanAbsolutePercentageError",
    "MeanIoU",
    "MeanMetricWrapper",
    "MeanSquaredError",
    "MeanSquaredLogarithmicError",
    "Metric",
    "OneHotIoU",
    "OneHotMeanIoU",
    "Poisson",
    "Precision",
    "PrecisionAtRecall",
    "R2Score",
    "Recall",
    "RecallAtPrecision",
    "RootMeanSquaredError",
    "SensitivityAtSpecificity",
    "SparseCategoricalAccuracy",
    "SparseCategoricalCrossentropy",
    "SparseTopKCategoricalAccuracy",
    "SpecificityAtSensitivity",
    "SquaredHinge",
    "Sum",
    "TopKCategoricalAccuracy",
    "TrueNegatives",
    "TruePositives",
    "binary_accuracy",
    "binary_crossentropy",
    "binary_focal_crossentropy",
    "categorical_accuracy",
    "categorical_crossentropy",
    "categorical_focal_crossentropy",
    "categorical_hinge",
    "deserialize",
    "get",
    "hinge",
    "huber",
    "kl_divergence",
    "log_cosh",
    "mean_absolute_error",
    "mean_absolute_percentage_error",
    "mean_squared_error",
    "mean_squared_logarithmic_error",
    "poisson",
    "serialize",
    "sparse_categorical_accuracy",
    "sparse_categorical_crossentropy",
    "sparse_top_k_categorical_accuracy",
    "squared_hinge",
    "top_k_categorical_accuracy",
]
METRICS_DESC = """评估指标,模型编译时指定一个或多个评估指标,用于评估模型在训练和测试阶段的性能。这些指标不会影响训练过程,但会在每个训练周期结束时计算并显示,以帮助您评估模型的表现。
https://keras.io/api/metrics/
可以使用 自定义参数
"""
EPOCHS_DESC = """epochs/迭代次数: 模型在训练数据上迭代的次数。一次 epoch 是指模型完整地遍历一遍训练数据集(除非 steps_per_epoch 参数被设置为其他值)。
每次 epoch 后,模型参数(例如,权重和偏置)都会根据损失函数和优化算法进行更新。
请注意,结合 initial_epoch 参数时,epochs 应理解为“最终周期”。模型并不会按照给定的周期数进行迭代训练,而是仅仅训练到索引为 epochs 的周期为止。
假设你有一个训练数据集 X,包含 N 个样本。如果你设置 epochs=10,这意味着模型会在整个数据集上训练 10 次,每次都会更新模型的权重。

为什么需要多个 epochs:
- 提高精度:在每个 epoch 中,模型会不断调整其参数以最小化损失函数,从而提高预测精度。
- 避免过拟合:通过使用多次训练,模型可以更好地泛化到未见过的数据,但需要注意的是,过多的 epochs 可能会导致过拟合。为了防止过拟合,可以使用验证集、早停(Early Stopping)和正则化等技术。

选择合适的 epochs 值通常依赖于以下几点:
- 数据集大小:较大的数据集可能需要更多的 epochs 来充分学习数据的特征。
- 模型复杂度:复杂的模型可能需要更多的 epochs 来收敛到一个较好的解。
- 早停策略:可以使用早停策略,在验证误差不再下降时提前停止训练,以防止过拟合。
"""
def run(
    optimizer: I.choice(OPTIMIZER_DESC, OPTIMIZERS) = "Adam",  # type: ignore
    loss: I.choice(LOSS_DESC, LOSSES) = "mean_squared_error",  # type: ignore
    metrics: I.choice(METRICS_DESC, METRICS, multi=True) = ["mean_squared_error", "Accuracy"],  # type: ignore
    fit_batch_size: I.int("训练batch_size,进行梯度下降时每个batch包含的样本数。训练时一个batch的样本会被计算一次梯度下降,使目标函数优化一步。") = None,  # type: ignore
    epochs: I.int(EPOCHS_DESC) = 1,  # type: ignore
    # TODO n_gpus: I.int('gpu个数,本模块使用的gpu个数') = 0,
    user_params: I.code(USER_PARAMS_DESC, I.code_python, DEFAULT_USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    verbose: I.choice("日志级别", ["0:不显示", "1:输出进度条记录", "2:每个epoch输出一行记录"]) = "1:输出进度条记录",  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    inputs: I.port("输入层", optional=True) = None,  # type: ignore
    outputs: I.port("输出层", optional=True) = None,  # type: ignore
    base_model: I.port("base model", optional=True) = None,  # type: ignore
    training_data: I.port("训练数据", optional=True) = None,  # type: ignore
    test_data: I.port("测试数据", optional=True) = None,  # type: ignore
    m_meta_kwargs=None,  # type: ignore
) -> [  # type: ignore
    I.port("model", "model"),  # type: ignore
    I.port("预测结果", "predictions"),  # type: ignore
]:
    """Keras 模型训练&预测

UpSampling1D

# M.keras_layer_up_sampling_1d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run(
    # https://keras.io/api/layers/reshaping_layers/up_sampling1d/

    # import keras

    init_params = dict(
        # size,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    size: I.int("上采样因子", min=1) = 2,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """UpSampling1D 是 Keras 中用于对 1D 输入进行上采样的层。它会沿时间轴重复每个时间步 size 次。

Flatten

# M.keras_layer_flatten.v1
DATA_FORMATS = ["channels_last", "channels_first"]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run(
    # https://keras.io/api/layers/reshaping_layers/flatten/

    # import keras

    init_params = dict(
        # data_format="channels_last",
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    data_format: I.choice("输入数据的格式,data_format", values=DATA_FORMATS) = "channels_last",  # type: ignore
    input_layer: I.port("输入", optional=False) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Flatten 是 Keras 中用于将输入展平的层,不会影响批处理大小。

Multiply

# M.keras_layer_multiply.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/merging_layers/multiply/

    # import keras

    init_params = dict(
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer_1: I.port("输入1", optional=False) = None,  # type: ignore
    input_layer_2: I.port("输入2", optional=False) = None,  # type: ignore
    input_layer_3: I.port("输入3", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Multiply 是 Keras 中用于执行元素级乘法的层。它接受一个形状相同的张量列表作为输入,并返回一个形状相同的单一张量。

EinsumDense

# M.keras_layer_einsum_dense.v1
ACTIVATIONS = [
    "elu",
    "exponential",
    "gelu",
    "hard_sigmoid",
    "hard_silu",
    "hard_swish",
    "leaky_relu",
    "linear",
    "log_softmax",
    "mish",
    "relu",
    "relu6",
    "selu",
    "sigmoid",
    "silu",
    "softmax",
    "softplus",
    "softsign",
    "swish",
    "tanh",
    "None",
]
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = ["L1", "L1L2", "L2", "OrthogonalRegularizer", "Regularizer", "None"]
CONSTRAINTS = ["Constraint", "MaxNorm", "MinMaxNorm", "NonNeg", "UnitNorm", "None"]
LORA_RANK_DESC = """lora_rank/低秩适应,这个参数用于实现 LoRA(Low-Rank Adaptation,低秩适应)。
LoRA 是一种用于减少大规模全连接层(Dense Layer)微调计算成本的方法。
LoRA(Low-Rank Adaptation)是一种技术,通过将层的权重矩阵分解为两个较低秩的可训练矩阵,从而减少参数数量和计算复杂度。这对于微调大型模型特别有用,因为它可以显著降低计算和存储成本,同时保持模型的性能。
如果设置了 lora_rank,EinsumDense 层的前向传递将实现 LoRA。具体来说,这会将层的权重矩阵设为不可训练,并用两个低秩可训练矩阵的乘积来表示这个权重矩阵的变化。这对于减少大型全连接层微调的计算成本非常有用。
你可以在创建 EinsumDense 层时通过设置 lora_rank 参数来启用 LoRA。如果你已经有一个定义好的 EinsumDense 层,也可以通过调用 layer.enable_lora(rank) 方法来启用 LoRA。
"""
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/core_layers/einsum_dense/

    # import keras

    init_params = dict(
        # equation,
        # output_shape,
        # activation=None,
        # bias_axes=None,
        # kernel_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # bias_regularizer=None,
        # kernel_constraint=None,
        # bias_constraint=None,
        # lora_rank=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    equation: I.str("描述要执行的einsum的方程。这必须是一个有效的einsum字符串。"),  # type: ignore
    output_shape: I.str("预期的输出张量形状(不包括批次维度和任何由省略号表示的维度)。对于任何未知或可以从输入形状推断的维度,可以指定None。"),  # type: ignore
    activation: I.choice("激活函数,用于将线性输出转换为非线性输出", ACTIVATIONS) = "linear",  # type: ignore
    bias_axes: I.str("包含要应用偏置的输出维度的字符串。") = None,  # type: ignore
    kernel_initializer: I.choice("权重矩阵初始化方法,kernel_initializer", INITIALIZERS) = "GlorotUniform",  # type: ignore
    bias_initializer: I.choice("偏置项初始化方法,bias_initializer,使用的是使用默认参数", INITIALIZERS) = "Zeros",  # type: ignore
    kernel_regularizer: I.choice("权重矩阵正则化方法,kernel_regularizer", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置项正则项,bias_regularizer", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权重矩阵上约束方法,kernel_constraint", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置项约束方法,bias_constraint", CONSTRAINTS) = "None",  # type: ignore
    lora_rank: I.int(LORA_RANK_DESC) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """EinsumDense 是 Keras 中用于执行爱因斯坦求和操作的层。

LSTM

# M.keras_layer_lstm.v1
ACTIVATIONS = [
    "elu",
    "exponential",
    "gelu",
    "hard_sigmoid",
    "hard_silu",
    "hard_swish",
    "leaky_relu",
    "linear",
    "log_softmax",
    "mish",
    "relu",
    "relu6",
    "selu",
    "sigmoid",
    "silu",
    "softmax",
    "softplus",
    "softsign",
    "swish",
    "tanh",
    "None",
]
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = ["L1", "L1L2", "L2", "OrthogonalRegularizer", "Regularizer", "None"]
CONSTRAINTS = ["Constraint", "MaxNorm", "MinMaxNorm", "NonNeg", "UnitNorm", "None"]
USER_FUNC_DESC = """自定义函数,自定义设置层构建参数和调用参数"""
USER_FUNC = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/lstm/

    # import keras

    init_params = dict(
        # units,
        # activation="tanh",
        # recurrent_activation="sigmoid",
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # recurrent_initializer="orthogonal",
        # bias_initializer="zeros",
        # unit_forget_bias=True,
        # kernel_regularizer=None,
        # recurrent_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # recurrent_constraint=None,
        # bias_constraint=None,
        # dropout=0.0,
        # recurrent_dropout=0.0,
        # seed=None,
        # return_sequences=False,
        # return_state=False,
        # go_backwards=False,
        # stateful=False,
        # unroll=False,
        # use_cudnn="auto",
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # mask=None,
        # training=None,
        # initial_state=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    units: I.int("输出空间的维度", min=1),  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "tanh",  # type: ignore
    recurrent_activation: I.choice("递归步骤的激活函数", ACTIVATIONS) = "sigmoid",  # type: ignore
    use_bias: I.bool("是否使用偏置向量") = True,  # type: ignore
    kernel_initializer: I.choice("核权重矩阵的初始化方法", INITIALIZERS) = "GlorotUniform",  # type: ignore
    recurrent_initializer: I.choice("递归核权重矩阵的初始化方法", INITIALIZERS) = "OrthogonalInitializer",  # type: ignore
    bias_initializer: I.choice("偏置向量的初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    unit_forget_bias: I.bool("是否在初始化时给遗忘门的偏置加 1") = True,  # type: ignore
    kernel_regularizer: I.choice("核权重矩阵的正则化方法", REGULARIZERS) = "None",  # type: ignore
    recurrent_regularizer: I.choice("递归核权重矩阵的正则化方法", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量的正则化方法", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出的正则化方法", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("核权重矩阵的约束方法", CONSTRAINTS) = "None",  # type: ignore
    recurrent_constraint: I.choice("递归核权重矩阵的约束方法", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量的约束方法", CONSTRAINTS) = "None",  # type: ignore
    dropout: I.float("输入线性变换的丢弃比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    recurrent_dropout: I.float("递归状态线性变换的丢弃比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    seed: I.int("用于 dropout 的随机种子", min=0) = None,  # type: ignore
    return_sequences: I.bool("是否返回完整输出序列") = False,  # type: ignore
    return_state: I.bool("是否返回输出外加最后一个状态") = False,  # type: ignore
    go_backwards: I.bool("是否反向处理输入序列并返回倒序") = False,  # type: ignore
    stateful: I.bool("是否使用批次中索引 i 的最后状态用于下一个批次中索引 i 的初始状态") = False,  # type: ignore
    unroll: I.bool("是否展开网络") = False,  # type: ignore
    use_cudnn: I.choice("是否使用 cuDNN 支持的实现", ["auto", "True", "False"]) = "auto",  # type: ignore
    user_func: I.code(USER_FUNC_DESC, I.code_python, USER_FUNC, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """LSTM 是 Keras 中用于创建长短期记忆(Long Short-Term Memory, LSTM)层的类。LSTM 是一种特殊的循环神经网络(RNN),其主要优点在于能够在序列数据中捕捉长期依赖关系。

UpSampling2D

# M.keras_layer_up_sampling_2d.v1
INTERPOLATIONS = ["nearest", "bilinear", "bicubic", "lanczos3", "lanczos5"]
DATA_FORMATS = ["channels_last", "channels_first", "None"]
USER_PARAMS_DESC = """自定义函数,自定义设置层构建参数和调用参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/up_sampling2d/

    # import keras

    init_params = dict(
        # size=(2, 2),
        # data_format=None,
        # interpolation="nearest",
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    size: I.str("上采样因子,可以是一个整数,或者是一个包含两个整数的元组。") = "(2, 2)",  # type: ignore
    data_format: I.choice("数据格式,'channels_last' 或 'channels_first'", DATA_FORMATS) = "channels_last",  # type: ignore
    interpolation: I.choice("插值方法,'nearest'、'bilinear'、'bicubic'、'lanczos3' 或 'lanczos5'", INTERPOLATIONS) = "nearest",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """UpSampling2D 是 Keras 中用于对 2D 输入进行上采样的层。上采样层通过插值方法来调整输入数据的大小。

Activation

# M.keras_layer_activation.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/core_layers/activation/

    # import keras

    init_params = dict(
        # activation = "relu",
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    activation: I.choice('激活函数', ACTIVATIONS) = 'tanh',  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port('输入') = None  # type: ignore
)->[
    I.port('输出', 'data')  # type: ignore
]:
    """Keras Activation 层

Cropping2D

# M.keras_layer_cropping_2d.v1
DATA_FORMATS = ["channels_last", "channels_first"]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/cropping2d/

    # import keras

    init_params = dict(
        # cropping=((0, 0), (0, 0)),
        # data_format=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    cropping: I.str("裁剪参数,整数或2个整数的元组,或2个2整数的元组。", specific_type_name="json") = "((0, 0), (0, 0))",  # type: ignore
    data_format: I.choice("数据格式,输入维度的顺序", DATA_FORMATS) = "channels_last",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Cropping2D 是 Keras 中用于对2D输入(例如图片)进行裁剪的层。该层可以沿着空间维度(即高度和宽度)进行裁剪。

ELU

# M.keras_layer_elu.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/activation_layers/elu/

    # import keras

    init_params = dict(
        # negative_slope=0.3,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    alpha: I.float("负区间的斜率,默认为1.0", min=0.0) = 1.0,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ELU 层用于将输入应用指数线性单元(Exponential Linear Unit)激活函数。

AlphaDropout

# M.keras_layer_alpha_dropout.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/regularization_layers/alpha_dropout/

    # import keras

    init_params = dict(
        # rate,
        # noise_shape=None,
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    rate: I.float("介于0和1之间的浮点数,乘法噪声的标准差为 sqrt(rate / (1 - rate))。", min=0.0, max=1.0),  # type: ignore
    noise_shape: I.str("1D整数张量,表示将与输入相乘的二进制alpha dropout掩码的形状。") = None,  # type: ignore
    seed: I.int("用于随机种子的Python整数。") = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ AlphaDropout 是一种 Dropout,保持输入的均值和方差与原始值一致,以确保即使在这种 dropout 后仍然具有自正则化属性。

GlobalAveragePooling3D

# M.keras_layer_global_average_pooling_3d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/global_average_pooling3d/

    # import keras

    init_params = dict(
        # data_format=None,
        # keepdims=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    data_format: I.choice("数据格式", ["channels_last", "channels_first"]) = None,  # type: ignore
    keepdims: I.bool("是否保留空间维度") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras GlobalAveragePooling2D 层

Attention

# M.keras_layer_attention.v1
SCORE_MODES = ["dot", "concat"]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/attention_layers/attention/

    # import keras

    init_params = dict(
        # use_scale=False,
        # score_mode="dot",
        # dropout=0.0,
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # mask=None,
        # return_attention_scores=False,
        # training=True,
        # use_causal_mask=False,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    use_scale: I.bool("是否创建一个标量变量来缩放注意力分数", specific_type_name="bool") = False,  # type: ignore
    score_mode: I.choice("用于计算注意力分数的函数", SCORE_MODES) = "dot",  # type: ignore
    dropout: I.float("用于注意力分数的丢弃单元的比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    seed: I.int("用于随机种子的整数", min=0) = None,  # type: ignore
    input_query: I.port("查询张量输入", optional=False) = None,  # type: ignore
    input_value: I.port("值张量输入", optional=False) = None,  # type: ignore
    input_key: I.port("键张量输入", optional=True) = None,  # type: ignore
    query_mask: I.port("查询掩码张量", optional=True) = None,  # type: ignore
    value_mask: I.port("值掩码张量", optional=True) = None,  # type: ignore
    return_attention_scores: I.bool("是否返回注意力分数") = False,  # type: ignore
    training: I.bool("是否在训练模式下运行。") = None,  # type: ignore
    use_causal_mask: I.bool("使用因果掩码") = False,  # type: ignore
    user_params: I.code("自定义函数,自定义设置层构建参数和调用参数", language="python", default=None, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
) -> [
    I.port("attention_output", "attention_output"),
    I.port("attention_scores", "attention_scores"),
    ]:  # type: ignore
    """Attention 层是用于实现点积注意力机制的层,也称为 Luong 风格注意力。

MultiHeadAttention

# M.keras_layer_multi_head_attention.v2
USER_PARAMS_DESC = """自定义参数"""
DEFAULT_USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/attention_layers/multi_head_attention/

    # import keras

    init_params = {
        # "num_heads": 8,
        # "key_dim": 64,
        # "value_dim": None,
        # "dropout": 0.0,
        # "use_bias": True,
        # "output_shape": None,
        # "attention_axes": None,
        # "kernel_initializer": "glorot_uniform",
        # "bias_initializer": "zeros",
        # "kernel_regularizer": None,
        # "bias_regularizer": None,
        # "activity_regularizer": None,
        # "kernel_constraint": None,
        # "bias_constraint": None,
    }
    call_params = {
        # query
        # value
        # "key": None,
        # "query_mask": None,
        # "value_mask": None,
        # "key_mask": None,
        # "attention_mask": None,
        # "return_attention_scores": False,
        # "training": None,
        # "use_causal_mask": False,
    }

    return {"init": init_params, "call": call_params}
"""
def run(
    query: I.port("query/查询输入张量"),  # type: ignore
    value: I.port("value/值输入张量"),  # type: ignore
    num_heads: I.int("num_heads/注意力头数,多头注意力机制中的头数。注意力头数越多,模型可以并行处理的信息越多。"),  # type: ignore
    key_dim: I.int("key_dim/每个注意力头的维度。这个参数决定了每个头在计算注意力分数时使用的维度大小。通常情况下,key_dim 与 value_dim 相同,但也可以不同。"),  # type: ignore
    value_dim: I.int("value_dim/每个注意力头的值向量的维度。如果未指定,则默认为 key_dim。") = None,  # type: ignore
    dropout: I.float("dropout/注意力权重的丢弃率。用于在训练过程中防止过拟合。") = None,  # type: ignore
    use_bias: I.bool("use_bias/在计算注意力权重时使用偏置项。默认值为 True。") = True,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, DEFAULT_USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    key: I.port("key/键输入张量", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """MultiHeadAttention 是 Transformer 模型中的一个关键组件,能够增强模型捕捉不同位置之间依赖关系的能力。它的核心思想是通过多个“头”并行地执行注意力操作,以捕捉不同的特征子空间。

UpSampling3D

# M.keras_layer_up_sampling_3d.v1
DATA_FORMATS = ["channels_last", "channels_first"]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/up_sampling3d/

    # import keras

    init_params = dict(
        # size=(2, 2, 2),
        # data_format=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    size: I.str("上采样因子,为一个整数或3个整数的元组") = "(2, 2, 2)",  # type: ignore
    data_format: I.choice("数据格式,用于指定输入数据的维度顺序", DATA_FORMATS) = "channels_last",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """UpSampling3D 是 Keras 中用于对 3D 输入进行上采样的层。

Permute

# M.keras_layer_permute.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/permute/

    # import keras

    init_params = dict(
        # dims,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    dims: I.str("维度置换模式,不包括批量维度。索引从1开始,例如 (2, 1) 将置换输入的第一和第二维度。"),  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Permute 是 Keras 中用于根据给定模式置换输入维度的类。

Subtract

# M.keras_layer_subtract.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/merging_layers/subtract/

    # import keras

    init_params = dict(
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer_1: I.port("输入1", optional=False) = None,  # type: ignore
    input_layer_2: I.port("输入2", optional=False) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Subtract 是 Keras 中用于执行元素级减法的层。它接受两个形状相同的张量列表作为输入,并返回一个形状相同的单一张量(inputs[0] - inputs[1])。

DepthwiseConv2D

# M.keras_layer_depthwise_conv2d.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "min_max_norm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/depthwise_convolution2d/

    # import keras

    init_params = dict(
        # kernel_size,
        # strides=(1, 1),
        # padding="valid",
        # depth_multiplier=1,
        # data_format=None,
        # dilation_rate=(1, 1),
        # activation=None,
        # use_bias=True,
        # depthwise_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # depthwise_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # depthwise_constraint=None,
        # bias_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None
        # mask=None
    )
"""
def run(
    kernel_size: I.str("卷积核大小,可以是一个整数或一个包含2个整数的元组/列表") = "3",  # type: ignore
    strides: I.str("卷积步长,可以是一个整数或一个包含2个整数的元组/列表") = "1",  # type: ignore
    padding: I.choice("填充方式,valid表示不填充,same表示填充使得输出尺寸等于输入尺寸", values=["valid", "same"]) = "valid",  # type: ignore
    depth_multiplier: I.int("每个输入通道的深度卷积输出通道数", min=1) = 1,  # type: ignore
    data_format: I.choice("数据格式,channels_last表示通道在最后,channels_first表示通道在最前", values=["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("膨胀率,可以是一个整数或一个包含2个整数的元组/列表") = "1",  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "relu",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    depthwise_initializer: I.choice("深度卷积核初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    depthwise_regularizer: I.choice("深度卷积核正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    depthwise_constraint: I.choice("深度卷积核约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras DepthwiseConv2D 层

HashedCrossing

# M.keras_layer_hashed_crossing.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/preprocessing_layers/categorical/hashed_crossing/

    # import keras

    init_params = dict(
        # num_bins,
        # output_mode="int",
        # sparse=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )    

    return {"init": init_params, "call": call_params}
"""
def run(
    num_bins: I.int("哈希桶的数量") = None,  # type: ignore
    output_mode: I.choice("输出模式", ["int", "one_hot"]) = "int",  # type: ignore
    sparse: I.bool("是否返回稀疏张量,仅在 one_hot 模式下有效") = False,  # type: ignore
    input_features: I.port("输入特征列表", optional=True) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """HashedCrossing 层

Add

# M.keras_layer_add.v2
def run(
    input_1: I.port("输入1", optional=True) = None,  # type: ignore
    input_2: I.port("输入2", optional=True) = None,  # type: ignore
    input_3: I.port("输入3", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Add 层是一种用于对两个或多个张量逐元素相加的层。这在构建多输入、多输出模型时特别有用,例如残差网络(ResNet)中常用的跳跃连接(skip connections)。

ZeroPadding1D

# M.keras_layer_zero_padding_1d.v2
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/zero_padding1d/

    # import keras

    init_params = dict(
        padding=1,
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    padding: I.str("Padding,可以是1个整数或者由2个整数组成的元组") = "1",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ZeroPadding1D 是 Keras 中用于对1D输入(例如时间序列)进行零填充的类。

LayerNormalization

# M.keras_layer_layer_normalization.v1
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = [
    "L1",
    "L2",
    "L1L2",
    "OrthogonalRegularizer",
    "Regularizer",
    "None"
]
CONSTRAINTS = [
    "Constraint",
    "MaxNorm",
    "MinMaxNorm",
    "NonNeg",
    "UnitNorm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/normalization_layers/layer_normalization/

    # import keras

    init_params = dict(
        # axis=-1,
        # epsilon=1e-3,
        # center=True,
        # scale=True,
        # rms_scaling=False,
        # beta_initializer='Zeros',
        # gamma_initializer='Ones',
        # beta_regularizer='None',
        # gamma_regularizer='None',
        # beta_constraint='None',
        # gamma_constraint='None',
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    axis: I.str("归一化的轴,通常是特征轴。为整数或包含整数的元组/列表。-1表示最后一个维度。", specific_type_name="int or list/tuple") = "-1",  # type: ignore
    epsilon: I.float("避免除以零的小浮点数。", min=1e-10, max=1e-1) = 1e-3,  # type: ignore
    center: I.bool("是否加上beta偏置。") = True,  # type: ignore
    scale: I.bool("是否乘以gamma。") = True,  # type: ignore
    rms_scaling: I.bool("是否使用RMS scaling。") = False,  # type: ignore
    beta_initializer: I.choice("beta权重的初始化方法。", INITIALIZERS) = "Zeros",  # type: ignore
    gamma_initializer: I.choice("gamma权重的初始化方法。", INITIALIZERS) = "Ones",  # type: ignore
    beta_regularizer: I.choice("beta权重的正则化方法。", REGULARIZERS) = "None",  # type: ignore
    gamma_regularizer: I.choice("gamma权重的正则化方法。", REGULARIZERS) = "None",  # type: ignore
    beta_constraint: I.choice("beta权重的约束方法。", CONSTRAINTS) = "None",  # type: ignore
    gamma_constraint: I.choice("gamma权重的约束方法。", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """LayerNormalization 是 Keras 中用于对每个样本的激活进行归一化处理的类。

ReLU

# M.keras_layer_relu.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/activation_layers/relu/

    # import keras

    init_params = dict(
        # max_value=None,
        # negative_slope=0.0,
        # threshold=0.0,
        # **kwargs
    )
    call_params = dict(
        # inputs
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    max_value: I.float("最大激活值,None 表示无限制。", min=0.0) = None,  # type: ignore
    negative_slope: I.float("负斜率系数。", min=0.0) = 0.0,  # type: ignore
    threshold: I.float("阈值,用于阈值激活。", min=0.0) = 0.0,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ReLU 是 Keras 中用于创建修正线性单元激活函数层的类。

GRUCell

# M.keras_layer_gru_cell.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "MaxNorm",
    "NonNeg",
    "UnitNorm",
    "MinMaxNorm",
    "None",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/gru_cell/

    # import keras

    init_params = dict(
        # units,
        # activation="tanh",
        # recurrent_activation="sigmoid",
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # recurrent_initializer="orthogonal",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # recurrent_regularizer=None,
        # bias_regularizer=None,
        # kernel_constraint=None,
        # recurrent_constraint=None,
        # bias_constraint=None,
        # dropout=0.0,
        # recurrent_dropout=0.0,
        # reset_after=True,
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # states,
        # training,
    )
"""
def run(
    units: I.int("输出空间维度,正整数", min=1),  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "tanh",  # type: ignore
    recurrent_activation: I.choice("循环激活函数", ACTIVATIONS) = "sigmoid",  # type: ignore
    use_bias: I.bool("use_bias,是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权值初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    recurrent_initializer: I.choice("循环权值初始化方法", INITIALIZERS) = "orthogonal",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "zeros",  # type: ignore
    kernel_regularizer: I.choice("权值正则项", REGULARIZERS) = "None",  # type: ignore
    recurrent_regularizer: I.choice("循环权值正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权值约束项", CONSTRAINTS) = "None",  # type: ignore
    recurrent_constraint: I.choice("循环权值约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    dropout: I.float("输入的随机丢弃比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    recurrent_dropout: I.float("循环状态的随机丢弃比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    reset_after: I.bool("是否在矩阵乘法后应用重置门") = True,  # type: ignore
    seed: I.int("随机种子,用于dropout") = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
    states: I.port("循环状态", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras GRUCell 层

Maximum

# M.keras_layer_maximum.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/merging_layers/maximum/

    # import keras

    init_params = dict(
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer_1: I.port("输入", optional=False) = None,  # type: ignore
    input_layer_2: I.port("输入", optional=False) = None,  # type: ignore
    input_layer_3: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Maximum 是 Keras 中用于计算多个输入张量的逐元素最大值的层。

AdditiveAttention

# M.keras_layer_additive_attention.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/attention_layers/additive_attention/

    # import keras

    init_params = dict(
        # use_scale=True,
        # dropout=0.0,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
        # return_attention_scores=False,
        # use_causal_mask=False,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    use_scale: I.bool("是否创建一个标量变量来缩放注意力得分。") = True,  # type: ignore
    dropout: I.float("注意力得分的丢弃率,取值范围为0到1。") = 0.0,  # type: ignore
    query_input: I.port("查询张量输入", optional=False) = None,  # type: ignore
    value_input: I.port("值张量输入", optional=False) = None,  # type: ignore
    key_input: I.port("键张量输入", optional=True) = None,  # type: ignore
    query_mask: I.port("查询掩码输入", optional=True) = None,  # type: ignore
    value_mask: I.port("值掩码输入", optional=True) = None,  # type: ignore
    return_attention_scores: I.bool("是否返回注意力得分(经过掩码和softmax处理后)作为附加输出参数。") = False,  # type: ignore
    training: I.bool("是否在训练模式下运行。") = None,  # type: ignore
    use_causal_mask: I.bool("用于解码器自注意力的掩码。阻止位置i关注位置j > i,防止信息从未来向过去传播。") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
) -> [
    I.port("attention_output", "attention_output"),
    I.port("attention_scores", "attention_scores"),
    ]:  # type: ignore
    """AdditiveAttention 是一种加性注意力层,也称为 Bahdanau-style 注意力。

GRU

# M.keras_layer_gru.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "MaxNorm",
    "NonNeg",
    "UnitNorm",
    "MinMaxNorm",
    "None",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/gru/

    # import keras

    init_params = dict(
        # units,
        # activation="tanh",
        # recurrent_activation="sigmoid",
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # recurrent_initializer="orthogonal",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # recurrent_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # recurrent_constraint=None,
        # bias_constraint=None,
        # dropout=0.0,
        # recurrent_dropout=0.0,
        # seed=None,
        # return_sequences=False,
        # return_state=False,
        # go_backwards=False,
        # stateful=False,
        # unroll=False,
        # reset_after=True,
        # use_cudnn="auto",
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
        # initial_state
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    units: I.int("输出空间维度,正整数", min=1),  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "tanh",  # type: ignore
    recurrent_activation: I.choice("循环激活函数", ACTIVATIONS) = "sigmoid",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权值初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    recurrent_initializer: I.choice("循环权值初始化方法", INITIALIZERS) = "orthogonal",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "zeros",  # type: ignore 
    kernel_regularizer: I.choice("权值正则项", REGULARIZERS) = "None",  # type: ignore
    recurrent_regularizer: I.choice("循环权值正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权值约束项", CONSTRAINTS) = "None",  # type: ignore
    recurrent_constraint: I.choice("循环权值约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    dropout: I.float("输入的随机丢弃比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    recurrent_dropout: I.float("循环状态的随机丢弃比例", min=0.0, max=1.0) = 0.0, # type: ignore
    seed: I.int("随机种子,用于dropout") = None,  # type: ignore
    return_sequences: I.bool("是否返回整个序列") = False,  # type: ignore
    return_state: I.bool("是否返回最终状态") = False,  # type: ignore
    go_backwards: I.bool("是否反向处理输入序列") = False,  # type: ignore
    stateful: I.bool("是否保持状态") = False,  # type: ignore
    unroll: I.bool("是否展开循环") = False,  # type: ignore
    reset_after: I.bool("是否在矩阵乘法后应用重置门") = True,  # type: ignore
    use_cudnn: I.choice("是否使用cuDNN实现", ["auto", "True", "False"]) = "auto",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras GRU 层

Hashing

# M.keras_layer_hashing.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/preprocessing_layers/categorical/hashing/

    # import keras

    init_params = dict(
        # num_bins,
        # mask_value=None,
        # salt=None,
        # output_mode="int",
        # sparse=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    num_bins: I.int("哈希桶的数量") = None,  # type: ignore
    mask_value: I.str("掩码值,表示被掩码的输入,映射到索引0") = None,  # type: ignore
    salt: I.str("SipHash64的盐值,可以是一个整数或一个包含两个整数的元组/列表") = None,  # type: ignore
    output_mode: I.choice("输出模式", ["int", "one_hot", "multi_hot", "count"]) = "int",  # type: ignore
    sparse: I.bool("是否返回稀疏张量,仅在 one_hot、multi_hot 和 count 模式下有效") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Hashing 层

Lambda

# M.keras_layer_lambda.v1
DEFAULT_FUNCTION = """def bigquant_run(x):
    # x为输入,即上一层的输出
    # 在这里添加您的代码
    return x + 1
"""
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/core_layers/lambda/

    # import keras

    init_params = dict(
        # function,
        # output_shape=None,
        # mask=None,
        # arguments=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    function: I.code("需要被评估的函数。接收输入张量作为第一个参数", language="python", specific_type_name="函数", default = DEFAULT_FUNCTION) = None,  # type: ignore
    output_shape: I.str("从函数中预期输出的形状。可以是元组或函数。如果是元组,它只指定第一个维度;如果是函数,它指定整个形状") = None,  # type: ignore
    mask: I.str("掩码,None表示不进行掩码操作") = None,  # type: ignore
    arguments: I.str("可选的关键字参数字典,将传递给函数", specific_type_name="dict") = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Lambda 是 Keras 中用于将任意表达式包装为层对象的类。这使得在构建 Sequential 和 Functional API 模型时可以使用任意表达式作为层。

IntegerLookup

# M.keras_layer_integer_lookup.v1
OUTPUT_MODES = [
    "int",
    "one_hot",
    "multi_hot",
    "count",
    "tf_idf"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/preprocessing_layers/categorical/integer_lookup/

    # import keras

    init_params = dict(
        # max_tokens=None,
        # num_oov_indices=1,
        # mask_token=None,
        # oov_token=-1,
        # vocabulary=None,
        # vocabulary_dtype="int64",
        # idf_weights=None,
        # invert=False,
        # output_mode="int",
        # sparse=False,
        # pad_to_max_tokens=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    max_tokens: I.int("词汇表的最大大小。如果为None,则词汇表大小不受限制。", min=1) = None,  # type: ignore
    num_oov_indices: I.int("使用的超出词汇表范围的标记数。", min=0) = 1,  # type: ignore
    mask_token: I.int("表示掩码输入的整数标记。") = None,  # type: ignore
    oov_token: I.int("超出词汇表范围的标记。") = -1,  # type: ignore
    vocabulary: I.port("词汇表,可以是整数数组或文件路径。", optional=True) = None,  # type: ignore
    vocabulary_dtype: I.choice("词汇表项的类型。", ["int64", "int32"]) = "int64",  # type: ignore
    idf_weights: I.port("仅在output_mode为'tf_idf'时有效。包含浮点数逆文档频率权重的数组。", optional=True) = None,  # type: ignore
    invert: I.bool("如果为True,此层将映射索引到词汇表项而不是词汇表项到索引。") = False,  # type: ignore
    output_mode: I.choice("层的输出模式。", OUTPUT_MODES) = "int",  # type: ignore
    pad_to_max_tokens: I.bool("是否将输出特征轴填充到最大令牌数。") = False,  # type: ignore
    sparse: I.bool("是否返回SparseTensor。仅适用于'multi_hot', 'count', 'tf_idf'输出模式。") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """IntegerLookup 是一个预处理层,用于将整数映射到(可能编码的)索引。

Softmax

# M.keras_layer_softmax.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/activation_layers/softmax/

    # import keras

    init_params = dict(
        # axis=-1,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    axis: I.str("沿着哪个或哪些轴应用softmax归一化。") = "-1",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Softmax Keras 中用于创建Softmax激活层的类。Softmax激活函数常用于分类任务中,将输入向量转换为概率分布。

Embedding

# M.keras_layer_embedding.v1
EMBEDDINGS_INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
    "uniform",
]
EMBEDDINGS_REGULARIZERS = ["L1", "L2", "L1L2", "None"]
EMBEDDINGS_CONSTRAINTS = ["max_norm", "non_neg", "unit_norm", "min_max_norm", "None"]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/core_layers/embedding/

    # import keras

    init_params = dict(
        # "input_dim": 1000,
        # "output_dim": 64,
        # "embeddings_initializer": "uniform",
        # "embeddings_regularizer": "None",
        # "embeddings_constraint": "None",
        # "mask_zero": False,
        # "weights": None,
        # "lora_rank": None,
        # "input_length": None,
        # "input_layer": None,
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    input_dim: I.int("词汇表大小,即最大整数索引 + 1"),  # type: ignore
    output_dim: I.int("密集嵌入的维度"),  # type: ignore
    embeddings_initializer: I.choice("嵌入矩阵的初始化方法", EMBEDDINGS_INITIALIZERS) = "uniform",  # type: ignore
    embeddings_regularizer: I.choice("应用于嵌入矩阵的正则化函数", EMBEDDINGS_REGULARIZERS) = "None",  # type: ignore
    embeddings_constraint: I.choice("应用于嵌入矩阵的约束函数", EMBEDDINGS_CONSTRAINTS) = "None",  # type: ignore
    mask_zero: I.bool("输入值0是否是一个特殊的“填充”值,应被屏蔽") = False,  # type: ignore
    weights: I.port("初始嵌入值的可选浮点矩阵", optional=True) = None,  # type: ignore
    lora_rank: I.int("lora_rank, Optional integer. If set, the layer's forward pass will implement LoRA (Low-Rank Adaptation) with the provided rank.") = None,  # type: ignore
    input_length: I.int('input_length,当输入序列的长度固定时,该值为其长度。如果要在该层后接Flatten层,然后接Dense层,则必须指定该参数,否则Dense层的输出维度无法自动推断') = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras Embedding 层

MaxPooling2D

# M.keras_layer_max_pooling_2d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/max_pooling2d/

    # import keras

    init_params = dict(
        # pool_size=(2, 2),
        # strides=None,
        # padding="valid",
        # data_format=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    pool_size: I.str("Max pooling 窗口大小, pool_size, 可以是整数或含有2个整数的元组,格式如 '2,2'", specific_type_name="tuple") = "2,2",  # type: ignore
    strides: I.str("Max pooling 步幅, strides, 可以为整数、含有2个整数的元组或 None。如果为 None,默认等于 pool_size", specific_type_name="tuple") = None,  # type: ignore
    padding: I.choice("填充方式, padding,'valid' 表示不填充,'same' 表示填充保持输出大小等于输入大小", ["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式, data_format,输入数据的维度顺序,'channels_last' 表示 (batch, height, width, channels),'channels_first' 表示 (batch, channels, height, width)", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras MaxPooling2D 层

StringLookup

# M.keras_layer_string_lookup.v1
OUTPUT_MODES = [
    "int",
    "one_hot",
    "multi_hot",
    "count",
    "tf_idf"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # "https://keras.io/api/layers/preprocessing_layers/categorical/string_lookup/"

    # import keras

    init_params = dict(
        # max_tokens=None,
        # num_oov_indices=1,
        # mask_token=None,
        # oov_token="[UNK]",
        # vocabulary=None,
        # idf_weights=None,
        # invert=False,
        # output_mode="int",
        # pad_to_max_tokens=False,
        # sparse=False,
        # encoding="utf-8",
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    max_tokens: I.int("词汇的最大大小。", min=1) = None,  # type: ignore
    num_oov_indices: I.int("使用的OOV(词汇表之外)标记的数量。", min=0) = 1,  # type: ignore
    mask_token: I.str("表示掩码输入的标记。") = None,  # type: ignore
    oov_token: I.str("OOV标记。") = "[UNK]",  # type: ignore
    vocabulary: I.str("词汇,可以是整数数组或文本文件路径。") = None,  # type: ignore
    idf_weights: I.port("逆文档频率权重。", optional=True) = None,  # type: ignore
    invert: I.bool("是否反转词汇表。") = False,  # type: ignore
    output_mode: I.choice("输出模式。", OUTPUT_MODES) = "int",  # type: ignore
    pad_to_max_tokens: I.bool("是否将输出特征轴填充到最大令牌数。") = False,  # type: ignore
    sparse: I.bool("是否返回稀疏张量。") = False,  # type: ignore
    encoding: I.str("文本编码格式。") = "utf-8",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """StringLookup 是一种用于将字符串映射到(可能编码的)索引的预处理层。

LeakyReLU

# M.keras_layer_leakyrelu.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/activation_layers/leaky_relu/

    # import keras

    init_params = dict(
        # negative_slope=0.3,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    negative_slope: I.float("负斜率系数,当输入小于0时,输出值为负斜率乘以输入值。", min=0.0) = 0.3,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """LeakyReLU 是 Keras 中用于创建带有负斜率的修正线性单元激活层的类。

GlobalMaxPooling2D

# M.keras_layer_global_max_pooling_2d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/global_max_pooling2d/

    # import keras

    init_params = dict(
        # data_format="channels_last",
        # keepdims=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    data_format: I.choice("数据格式, data_format,输入数据的维度顺序,'channels_last' 表示 (batch, height, width, channels),'channels_first' 表示 (batch, channels, height, width)", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    keepdims: I.bool("是否保留空间维度, keepdims, 如果为 False (默认),则张量的秩会因空间维度减少。如果为 True,则保留空间维度,长度为 1") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras GlobalMaxPooling2D 层

GlobalMaxPooling3D

# M.keras_layer_global_max_pooling_3d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/global_max_pooling3d/

    # import keras

    init_params = dict(
        # data_format="channels_last",
        # keepdims=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    data_format: I.choice("数据格式, data_format,输入数据的维度顺序,'channels_last' 表示 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels),'channels_first' 表示 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    keepdims: I.bool("是否保留空间维度, keepdims, 如果为 False (默认),则张量的秩会因空间维度减少。如果为 True,则保留空间维度,长度为 1") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras GlobalMaxPooling3D 层

LSTMCell

# M.keras_layer_lstm_cell.v1
ACTIVATIONS = [
    "elu",
    "exponential",
    "gelu",
    "hard_sigmoid",
    "hard_silu",
    "hard_swish",
    "leaky_relu",
    "linear",
    "log_softmax",
    "mish",
    "relu",
    "relu6",
    "selu",
    "sigmoid",
    "silu",
    "softmax",
    "softplus",
    "softsign",
    "swish",
    "tanh",
    "None",
]
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = ["L1", "L1L2", "L2", "OrthogonalRegularizer", "Regularizer", "None"]
CONSTRAINTS = ["Constraint", "MaxNorm", "MinMaxNorm", "NonNeg", "UnitNorm", "None"]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/lstm_cell/

    # import keras

    init_params = dict(
        # units,
        # activation="tanh",
        # recurrent_activation="sigmoid",
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # recurrent_initializer="orthogonal",
        # bias_initializer="zeros",
        # unit_forget_bias=True,
        # kernel_regularizer=None,
        # recurrent_regularizer=None,
        # bias_regularizer=None,
        # kernel_constraint=None,
        # recurrent_constraint=None,
        # bias_constraint=None,
        # dropout=0.0,
        # recurrent_dropout=0.0,
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # states,
        # training=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    units: I.int("正整数,输出空间的维度。", min=1),  # type: ignore
    activation: I.choice("激活函数,用于将线性输出转换为非线性输出", ACTIVATIONS) = "tanh",  # type: ignore
    recurrent_activation: I.choice("用于循环步骤的激活函数", ACTIVATIONS) = "sigmoid",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权重矩阵初始化方法", INITIALIZERS) = "GlorotUniform",  # type: ignore
    recurrent_initializer: I.choice("循环权重矩阵初始化方法", INITIALIZERS) = "OrthogonalInitializer",  # type: ignore
    bias_initializer: I.choice("偏置项初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    unit_forget_bias: I.bool("是否使用unit forget bias") = True,  # type: ignore
    kernel_regularizer: I.choice("权重矩阵正则化方法", REGULARIZERS) = "None",  # type: ignore
    recurrent_regularizer: I.choice("循环权重矩阵正则化方法", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置项正则化方法", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权重矩阵约束方法", CONSTRAINTS) = "None",  # type: ignore
    recurrent_constraint: I.choice("循环权重矩阵约束方法", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置项约束方法", CONSTRAINTS) = "None",  # type: ignore
    dropout: I.float("输入的dropout比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    recurrent_dropout: I.float("循环状态的dropout比例", min=0.0, max=1.0) = 0.0,  # type: ignore
    seed: I.int("随机种子") = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
    states: I.port("循环状态", optional=True) = None,  # type: ignore
) -> [I.port("cell", "data")]:  # type: ignore
    """LSTMCell 是 Keras 中用于创建 LSTM 单元的类。

Reshape

# M.keras_layer_reshape.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/reshape/

    # import keras

    init_params = dict(
        # target_shape,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    target_shape: I.str("目标形状,整数元组,不包括样本维度(批次大小)。") = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Reshape 是 Keras 中用于重塑输入形状的层。

SpatialDropout2D

# M.keras_layer_spatial_dropout_2d.v1
DATA_FORMATS = [
    "channels_first",
    "channels_last",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/regularization_layers/spatial_dropout2d/

    # import keras

    init_params = dict(
        # rate,
        # data_format="channels_last",
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    rate: I.float("输入单元的丢弃比例,范围在0到1之间。", min=0.0, max=1.0),  # type: ignore
    data_format: I.choice("数据格式,指定输入的维度顺序", DATA_FORMATS) = "channels_last",  # type: ignore
    seed: I.int("随机数种子,用于创建随机数", min=0) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """SpatialDropout2D 是 Keras 中用于创建空间2D随机失活层的类。与 Dropout 类似,但它会丢弃整个2D特征图而不是单个元素。

CategoryEncoding

# M.keras_layer_category_encoding.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/preprocessing_layers/categorical/category_encoding/

    # import keras

    init_params = dict(
        # num_tokens=None,
        # output_mode="multi_hot",
        # sparse=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # count_weights=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    num_tokens: I.int("支持的最大token数量,所有输入值必须在 0 到 num_tokens 之间") = None,  # type: ignore
    output_mode: I.choice("输出模式", ["one_hot", "multi_hot", "count"]) = "multi_hot",  # type: ignore
    sparse: I.bool("是否返回稀疏张量") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
    count_weights: I.port("计数权重,仅在count模式下使用", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """CategoryEncoding 是 Keras 中用于对分类特征进行编码的层。

SpatialDropout1D

# M.keras_layer_spatial_dropout_1d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/regularization_layers/spatial_dropout1d/

    # import keras

    init_params = dict(
        # rate,
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    rate: I.float("输入单元丢弃的比例", min=0.0, max=1.0) = 0.5,  # type: ignore
    seed: I.int("随机种子,用于生成随机数", min=0, max=2147483647) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """SpatialDropout1D 是 Keras 中用于创建一维空间 dropout 层的类。它会丢弃整个 1D 特征图而不是单个元素。

Conv3D

# M.keras_layer_conv3d.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "min_max_norm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/convolution3d/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=(1, 1, 1),
        # padding="valid",
        # data_format=None,
        # dilation_rate=(1, 1, 1),
        # groups=1,
        # activation=None,
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # bias_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间维度,即卷积核的数量", min=1),  # type: ignore
    kernel_size: I.str("卷积核大小,可以是一个整数或一个包含3个整数的元组/列表") = "3",  # type: ignore
    strides: I.str("卷积步长,可以是一个整数或一个包含3个整数的元组/列表") = "1",  # type: ignore
    padding: I.choice("填充方式,valid表示不填充,same表示填充使得输出尺寸等于输入尺寸", values=["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式,channels_last表示通道在最后,channels_first表示通道在最前", values=["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("膨胀率,可以是一个整数或一个包含3个整数的元组/列表") = "1",  # type: ignore
    groups: I.int("输入分组的数量,每一组分别进行卷积,输入通道数和卷积核数量必须能被groups数整除", min=1) = 1,  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "relu",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权值初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "zeros",  # type: ignore
    kernel_regularizer: I.choice("权值正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权值约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """三维卷积对三维的输入进行滑动窗卷积

Discretization

# M.keras_layer_discretization.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/preprocessing_layers/numerical/discretization/

    # import keras

    init_params = dict(
        # bin_boundaries=None,
        # num_bins=None,
        # epsilon=0.01,
        # output_mode="int",
        # sparse=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    bin_boundaries: I.str("箱边界列表,用于将连续特征分箱") = None,  # type: ignore
    num_bins: I.int("要计算的箱数") = None,  # type: ignore
    epsilon: I.float("误差容限,通常是接近零的小数") = 0.01,  # type: ignore
    output_mode: I.choice("输出模式", ["int", "one_hot", "multi_hot", "count"]) = "int",  # type: ignore
    sparse: I.bool("是否返回稀疏张量,仅在 one_hot、multi_hot 和 count 模式下有效") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Discretization 是 Keras 中用于将连续特征分箱的层。

AveragePooling3D

# M.keras_layer_average_pooling_3d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/average_pooling3d/

    # import keras

    init_params = dict(
        # pool_size,
        # strides=None,
        # padding="valid",
        # data_format=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    pool_size: I.str("池化窗口大小,可以是一个整数或一个包含三个整数的元组"),  # type: ignore
    strides: I.str("池化步长,可以是一个整数或一个包含三个整数的元组,默认为池化窗口大小") = None,  # type: ignore
    padding: I.choice("填充模式", ["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式", ["channels_last", "channels_first"]) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras AveragePooling3D 层

Dropout

# M.keras_layer_dropout.v2
USER_PARAMS_DESC = """自定义参数"""
DEFAULT_USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/regularization_layers/dropout/

    # import keras

    init_params = {
        # "rate": 0.2,
        # "noise_shape": (None, 10, 1),
        # "seed": 123,
    }
    call_params = {
        # "inputs": None,
        # "training": None,
    }

    return {"init": init_params, "call": call_params}
"""
def run(
    rate: I.float("rate/要丢弃的输入单元的比例。例如,如果 rate=0.5,则表示在训练过程中,每个输入单元有 50% 的概率被丢弃。", min=0, max=1),  # type: ignore
    seed: I.int("seed/随机数种子") = 123,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, DEFAULT_USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    input_layer: I.port("输入1", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Dropout 是一种在训练过程中用于防止神经网络过拟合的正则化技术。在训练过程中,Dropout 层会以一定概率随机将输入单元设为零,从而防止模型过度依赖某些神经元,增强模型的泛化能力。

Minimum

# M.keras_layer_minimum.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/merging_layers/minimum/

    # import keras

    init_params = dict(
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer_1: I.port("输入", optional=False) = None,  # type: ignore
    input_layer_2: I.port("输入", optional=False) = None,  # type: ignore
    input_layer_3: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Minimum 是 Keras 中用于计算输入张量列表的逐元素最小值的层。

Cropping3D

# M.keras_layer_cropping_3d.v1
DATA_FORMATS = ["channels_last", "channels_first"]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/reshaping_layers/cropping3d/

    # import keras

    init_params = dict(
        # cropping=((1, 1), (1, 1), (1, 1)),
        # data_format=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    cropping: I.str("裁剪参数,Int或3个Int的tuple或3个包含2个Int的tuple。") = "((1, 1), (1, 1), (1, 1))",  # type: ignore
    data_format: I.choice("数据格式,channels_last 或 channels_first", DATA_FORMATS) = "channels_last",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Cropping3D 是 Keras 中用于3D数据(例如空间或时空数据)的裁剪层。

BatchNormalization

# M.keras_layer_batch_normalization.v1
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = [
    "L1",
    "L1L2",
    "L2",
    "OrthogonalRegularizer",
    "Regularizer",
    "None"
]
CONSTRAINTS = [
    "Constraint",
    "MaxNorm",
    "MinMaxNorm",
    "NonNeg",
    "UnitNorm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/normalization_layers/batch_normalization/

    # import keras

    init_params = dict(
        # axis=-1,
        # momentum=0.99,
        # epsilon=0.001,
        # center=True,
        # scale=True,
        # beta_initializer="zeros",
        # gamma_initializer="ones",
        # moving_mean_initializer="zeros",
        # moving_variance_initializer="ones",
        # beta_regularizer=None,
        # gamma_regularizer=None,
        # beta_constraint=None,
        # gamma_constraint=None,
        # synchronized=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    axis: I.int("需要规范化的轴(通常是特征轴)。例如,对于 Conv2D 层,使用 data_format='channels_first',则axis=1。") = -1,  # type: ignore
    momentum: I.float("用于移动平均的动量。", min=0.0, max=1.0) = 0.99,  # type: ignore
    epsilon: I.float("添加到方差以避免除零的小浮点数。", min=0.0) = 0.001,  # type: ignore
    center: I.bool("如果为 True,将 beta 添加到规范化张量。如果为 False,则忽略 beta。") = True,  # type: ignore
    scale: I.bool("如果为 True,则乘以 gamma。如果为 False,则不使用 gamma。当下一层是线性时,可以禁用此功能,因为缩放将由下一层完成。") = True,  # type: ignore
    beta_initializer: I.choice("beta 权重的初始化器。", INITIALIZERS) = "Zeros",  # type: ignore
    gamma_initializer: I.choice("gamma 权重的初始化器。", INITIALIZERS) = "Ones",  # type: ignore
    moving_mean_initializer: I.choice("moving_mean 的初始化器。", INITIALIZERS) = "Zeros",  # type: ignore
    moving_variance_initializer: I.choice("moving_variance 的初始化器。", INITIALIZERS) = "Ones",  # type: ignore
    beta_regularizer: I.choice("beta 权重的正则化器。", REGULARIZERS) = "None",  # type: ignore
    gamma_regularizer: I.choice("gamma 权重的正则化器。", REGULARIZERS) = "None",  # type: ignore
    beta_constraint: I.choice("beta 权重的约束。", CONSTRAINTS) = "None",  # type: ignore
    gamma_constraint: I.choice("gamma 权重的约束。", CONSTRAINTS) = "None",  # type: ignore
    synchronized: I.bool("如果为 True,则在分布式训练策略中的每个训练步骤中同步本层的全局批次统计数据(均值和方差)。仅适用于 TensorFlow 后端。如果为 False,则每个副本使用其自己的本地批次统计数据。") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """BatchNormalization 是在 Keras 中用于对输入进行规范化的层。

GroupNormalization

# M.keras_layer_group_normalization.v1
INITIALIZERS = [
    "Constant",
    "GlorotNormal",
    "GlorotUniform",
    "HeNormal",
    "HeUniform",
    "Identity",
    "Initializer",
    "LecunNormal",
    "LecunUniform",
    "Ones",
    "OrthogonalInitializer",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Zeros",
    "None",
]
REGULARIZERS = [
    "L1",
    "L2",
    "L1L2",
    "OrthogonalRegularizer",
    "Regularizer",
    "None"
]
CONSTRAINTS = [
    "Constraint",
    "MaxNorm",
    "MinMaxNorm",
    "NonNeg",
    "UnitNorm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/normalization_layers/group_normalization/

    # import keras

    init_params = dict(
        # groups=32,
        # axis=-1,
        # epsilon=0.001,
        # center=True,
        # scale=True,
        # beta_initializer="zeros",
        # gamma_initializer="ones",
        # beta_regularizer=None,
        # gamma_regularizer=None,
        # beta_constraint=None,
        # gamma_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    groups: I.int("组的数量,用于 Group Normalization。可以在范围 [1, N] 之间,其中 N 是输入维度。输入维度必须能被组的数量整除。", min=1) = 32,  # type: ignore
    axis: I.choice("需要规范化的轴,可以是整数或列表/元组", [-1, 0, 1, 2, 3]) = -1,  # type: ignore
    epsilon: I.float("为了避免除以零而加到方差中的小浮点数。", min=1e-10, max=1e-1) = 1e-3,  # type: ignore
    center: I.bool("如果为 True,则将 beta 偏移添加到规范化张量中。如果为 False,则忽略 beta。") = True,  # type: ignore
    scale: I.bool("如果为 True,则乘以 gamma。如果为 False,则不使用 gamma。") = True,  # type: ignore
    beta_initializer: I.choice("beta 权重的初始化方法。", INITIALIZERS) = "Zeros",  # type: ignore
    gamma_initializer: I.choice("gamma 权重的初始化方法。", INITIALIZERS) = "Ones",  # type: ignore
    beta_regularizer: I.choice("beta 权重的正则化方法。", REGULARIZERS) = "None",  # type: ignore
    gamma_regularizer: I.choice("gamma 权重的正则化方法。", REGULARIZERS) = "None",  # type: ignore
    beta_constraint: I.choice("beta 权重的约束方法。", CONSTRAINTS) = "None",  # type: ignore
    gamma_constraint: I.choice("gamma 权重的约束方法。", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """GroupNormalization 是 Keras 中用于组归一化的层。它将通道划分为组,并在每组内计算均值和方差以进行归一化。

Normalization

# M.keras_layer_normalization.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run(
    # https://keras.io/api/layers/preprocessing_layers/numerical/normalization/

    # import keras

    init_params = dict(
        # axis=-1,
        # mean=None,
        # variance=None,
        # invert=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    axis: I.str("指定在哪些轴上进行归一化, 可以是整数、元组或列表,也可以为None") = "-1",  # type: ignore
    mean: I.str("归一化的均值,可以是标量或数组") = None,  # type: ignore
    variance: I.str("归一化的方差,可以是标量或数组") = None,  # type: ignore
    invert: I.bool("是否应用逆变换,将归一化后的输入恢复到原始形式") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Normalization 层

ConvLSTM1D

# M.keras_layer_conv_lstm_1d.v1
ACTIVATIONS = [
    "elu",
    "exponential",
    "gelu",
    "hard_sigmoid",
    "hard_silu",
    "hard_swish",
    "leaky_relu",
    "linear",
    "log_softmax",
    "mish",
    "relu",
    "relu6",
    "selu",
    "sigmoid",
    "silu",
    "softmax",
    "softplus",
    "softsign",
    "swish",
    "tanh",
    "None",
]
INITIALIZERS = [
    "glorot_uniform",
    "he_normal",
    "lecun_normal",
    "orthogonal"
]
REGULARIZERS = [
    "l1",
    "l2",
    "l1_l2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "None",
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/recurrent_layers/conv_lstm1d/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=1,
        # padding="valid",
        # data_format=None,
        # dilation_rate=1,
        # activation="tanh",
        # recurrent_activation="sigmoid",
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # recurrent_initializer="orthogonal",
        # bias_initializer="zeros",
        # unit_forget_bias=True,
        # kernel_regularizer=None,
        # recurrent_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # recurrent_constraint=None,
        # bias_constraint=None,
        # dropout=0.0,
        # recurrent_dropout=0.0,
        # seed=None,
        # return_sequences=False,
        # return_state=False,
        # go_backwards=False,
        # stateful=False,
        # **kwargs
    )

    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
        # initial_state=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间的维度,即卷积中的滤波器数量。", min=1),  # type: ignore
    kernel_size: I.int("卷积窗口的大小。", min=1),  # type: ignore
    strides: I.int("卷积步幅的长度。", min=1) = 1,  # type: ignore
    padding: I.choice("填充模式:'valid' 或 'same'", values=["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式:'channels_last' 或 'channels_first'", values=["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.int("膨胀卷积的膨胀率。", min=1) = 1,  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "tanh",  # type: ignore
    recurrent_activation: I.choice("递归步骤的激活函数", ACTIVATIONS) = "sigmoid",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权重矩阵的初始化方法", values=INITIALIZERS) = "glorot_uniform",  # type: ignore
    recurrent_initializer: I.choice("递归权重矩阵的初始化方法", values=INITIALIZERS) = "orthogonal",  # type: ignore
    bias_initializer: I.choice("偏置项的初始化方法", values=["zeros", "ones"]) = "zeros",  # type: ignore
    unit_forget_bias: I.bool("是否使用 unit forget bias") = True,  # type: ignore
    kernel_regularizer: I.choice("权重矩阵的正则化方法", values=REGULARIZERS) = "None",  # type: ignore
    recurrent_regularizer: I.choice("递归权重矩阵的正则化方法", values=REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置项的正则化方法", values=REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出的正则化方法", values=REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权重矩阵的约束方法", values=CONSTRAINTS) = "None",  # type: ignore
    recurrent_constraint: I.choice("递归权重矩阵的约束方法", values=CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置项的约束方法", values=CONSTRAINTS) = "None",  # type: ignore
    dropout: I.float("输入的 dropout 率", min=0.0, max=1.0) = 0.0,  # type: ignore
    recurrent_dropout: I.float("递归状态的 dropout 率", min=0.0, max=1.0) = 0.0,  # type: ignore
    seed: I.int("dropout 的随机种子") = None,  # type: ignore
    return_sequences: I.bool("是否返回输出序列中的最后一个输出或整个序列") = False,  # type: ignore
    return_state: I.bool("是否返回最后的状态") = False,  # type: ignore
    go_backwards: I.bool("是否反向处理输入序列") = False,  # type: ignore
    stateful: I.bool("是否使用 stateful 模式") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于 debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """ConvLSTM1D 是 Keras 中用于创建一维卷积长短期记忆(LSTM)层的类。它类似于 LSTM 层,但输入和递归变换都是卷积的。

GaussianNoise

# M.keras_layer_gaussian_noise.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/regularization_layers/gaussian_noise/

    # import keras

    init_params = dict(
        # stddev,
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    stddev: I.float("噪声分布的标准差", min=0.0) = 1.0,  # type: ignore
    seed: I.int("可选的随机种子,以启用确定性行为", min=0) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """GaussianNoise 是 Keras 中用于应用加性零均值高斯噪声的层。

SpatialDropout3D

# M.keras_layer_spatial_dropout_3d.v1
DATA_FORMATS = [
    "channels_first",
    "channels_last"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/regularization_layers/spatial_dropout3d/

    # import keras

    init_params = dict(
        # rate,
        # data_format=None,
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    rate: I.float("输入单元将被丢弃的比例,在0到1之间", min=0.0, max=1.0) = 0.5,  # type: ignore
    data_format: I.choice("数据格式,可以是 'channels_first' 或 'channels_last'", DATA_FORMATS) = "None",  # type: ignore
    seed: I.int("随机种子,用于确保结果的可重复性", min=0) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """SpatialDropout3D 是 Keras 中用于在3D特征图上应用空间Dropout的层。

GlobalAveragePooling1D

# M.keras_layer_global_average_pooling_1d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/global_average_pooling1d/

    # import keras

    init_params = dict(
        # data_format=None,
        # keepdims=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    data_format: I.choice("数据格式", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    keepdims: I.bool("是否保留时间维度") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras GlobalAveragePooling1D 层

Concatenate

# M.keras_layer_concatenate.v2
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/merging_layers/concatenate/

    # import keras

    init_params = dict(
        # axis=-1,
        # **kwargs
    )
    call_params = dict(
        # inputs
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    axis: I.int("沿着哪个轴进行拼接。") = -1,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer_1: I.port("输入1", optional=False) = None,  # type: ignore
    input_layer_2: I.port("输入2", optional=False) = None,  # type: ignore
    input_layer_3: I.port("输入3", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Concatenate 是 Keras 中用于拼接多个输入张量的层。

GaussianDropout

# M.keras_layer_gaussian_dropout.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/regularization_layers/gaussian_dropout/

    # import keras

    init_params = dict(
        # rate,
        # seed=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    rate: I.float("丢弃概率,乘法噪声的标准差为 sqrt(rate / (1 - rate))。", min=0.0, max=1.0),  # type: ignore
    seed: I.int("随机种子,用于确定性行为", min=0, max=2147483647) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """GaussianDropout 是 Keras 中用于应用乘法1中心高斯噪声的类。由于它是正则化层,因此仅在训练时才活跃。

RepeatVector

# M.keras_layer_repeat_vector.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run(
    # https://keras.io/api/layers/reshaping_layers/repeat_vector/

    # import keras

    init_params = dict(
        # n,
        # **kwargs
    )
    call_params = dict(
        # inputs,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    n: I.int("重复因子,指定输入重复的次数。", min=1),  # type: ignore
    input_layer: I.port("输入", optional=False) = None,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """RepeatVector 是 Keras 中用于将输入重复 n 次的层。

Conv3DTranspose

# M.keras_layer_conv3d_transpose.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "min_max_norm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/convolution3d_transpose/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=(1, 1, 1),
        # padding="valid",
        # data_format=None,
        # dilation_rate=(1, 1, 1),
        # activation=None,
        # use_bias=True,
        # kernel_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # kernel_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # kernel_constraint=None,
        # bias_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间维度,即卷积核的数量", min=1),  # type: ignore
    kernel_size: I.str("卷积核大小,可以是一个整数或一个包含3个整数的元组/列表") = "3",  # type: ignore
    strides: I.str("卷积步长,可以是一个整数或一个包含3个整数的元组/列表") = "1",   # type: ignore
    padding: I.choice("填充方式,valid表示不填充,same表示填充使得输出尺寸等于输入尺寸", values=["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式,channels_last表示通道在最后,channels_first表示通道在最前", values=["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("扩张率,可以是一个整数或一个包含3个整数的元组/列表") = "1",  # type: ignore
    activation: I.choice("激活函数,激活函数使用的是默认参数", ACTIVATIONS) = "relu",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    kernel_initializer: I.choice("权值初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法", INITIALIZERS) = "Zeros",  # type: ignore
    kernel_regularizer: I.choice("权值正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    kernel_constraint: I.choice("权值约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras Conv3DTranspose 层

SpectralNormalization

# M.keras_layer_spectral_normalization.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run(
    # https://keras.io/api/layers/preprocessing_layers/numerical/spectral_normalization/

    # import keras

    init_params = dict(
        # layer=None,
        # power_iterations=1,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=None,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    layer: I.port("目标层,必须是一个包含 kernel 或 embeddings 属性的 Keras 层") = None,  # type: ignore
    power_iterations: I.int("归一化过程中的迭代次数", min=1) = 1,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入层", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """SpectralNormalization 层

GlobalMaxPooling1D

# M.keras_layer_global_max_pooling_1d.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/pooling_layers/global_max_pooling1d/

    # import keras

    init_params = dict(
        # data_format="channels_last",
        # keepdims=False,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    data_format: I.choice("数据格式, data_format,输入数据的维度顺序,'channels_last' 表示 (batch, steps, features),'channels_first' 表示 (batch, features, steps)", ["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    keepdims: I.bool("是否保留时间维度, keepdims, 如果为 False (默认),则张量的秩会因空间维度减少。如果为 True,则保留时间维度,长度为 1") = False,  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras GlobalMaxPooling1D 层

SeparableConv2D

# M.keras_layer_separable_conv2d.v1
ACTIVATIONS = [
    "softmax",
    "elu",
    "selu",
    "softplus",
    "softsign",
    "relu",
    "tanh",
    "sigmoid",
    "hard_sigmoid",
    "linear",
    "None",
]
INITIALIZERS = [
    "Zeros",
    "Ones",
    "Constant",
    "RandomNormal",
    "RandomUniform",
    "TruncatedNormal",
    "VarianceScaling",
    "Orthogonal",
    "Identiy",
    "lecun_uniform",
    "lecun_normal",
    "glorot_normal",
    "glorot_uniform",
    "he_normal",
    "he_uniform",
]
REGULARIZERS = [
    "L1L2",
    "None",
]
CONSTRAINTS = [
    "max_norm",
    "non_neg",
    "unit_norm",
    "min_max_norm",
    "None"
]
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/convolution_layers/separable_convolution2d/

    # import keras

    init_params = dict(
        # filters,
        # kernel_size,
        # strides=(1, 1),
        # padding="valid",
        # data_format=None,
        # dilation_rate=(1, 1),
        # depth_multiplier=1,
        # activation=None,
        # use_bias=True,
        # depthwise_initializer="glorot_uniform",
        # pointwise_initializer="glorot_uniform",
        # bias_initializer="zeros",
        # depthwise_regularizer=None,
        # pointwise_regularizer=None,
        # bias_regularizer=None,
        # activity_regularizer=None,
        # depthwise_constraint=None,
        # pointwise_constraint=None,
        # bias_constraint=None,
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # training=True,
        # mask=None,
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    filters: I.int("输出空间维度,即卷积核的数量", min=1),  # type: ignore
    kernel_size: I.str("卷积核大小,可以是一个整数或一个包含2个整数的元组/列表") = "3",  # type: ignore
    strides: I.str("卷积步长,可以是一个整数或一个包含2个整数的元组/列表") = "1",  # type: ignore
    padding: I.choice("填充方式,valid表示不填充,same表示填充使得输出尺寸等于输入尺寸", values=["valid", "same"]) = "valid",  # type: ignore
    data_format: I.choice("数据格式,channels_last表示通道在最后,channels_first表示通道在最前", values=["channels_last", "channels_first"]) = "channels_last",  # type: ignore
    dilation_rate: I.str("扩张率,可以是一个整数或一个包含2个整数的元组/列表") = "1",  # type: ignore
    depth_multiplier: I.int("每个输入通道的深度卷积输出通道数", min=1) = 1,  # type: ignore
    activation: I.choice("激活函数", ACTIVATIONS) = "relu",  # type: ignore
    use_bias: I.bool("是否使用偏置项") = True,  # type: ignore
    depthwise_initializer: I.choice("深度卷积核初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    pointwise_initializer: I.choice("点卷积核初始化方法", INITIALIZERS) = "glorot_uniform",  # type: ignore
    bias_initializer: I.choice("偏置向量初始化方法",INITIALIZERS) = "Zeros",  # type: ignore
    depthwise_regularizer: I.choice("深度卷积核正则项", REGULARIZERS) = "None",  # type: ignore
    pointwise_regularizer: I.choice("点卷积核正则项", REGULARIZERS) = "None",  # type: ignore
    bias_regularizer: I.choice("偏置向量正则项", REGULARIZERS) = "None",  # type: ignore
    activity_regularizer: I.choice("输出正则项", REGULARIZERS) = "None",  # type: ignore
    depthwise_constraint: I.choice("深度卷积核约束项", CONSTRAINTS) = "None",  # type: ignore
    pointwise_constraint: I.choice("点卷积核约束项", CONSTRAINTS) = "None",  # type: ignore
    bias_constraint: I.choice("偏置向量约束项", CONSTRAINTS) = "None",  # type: ignore
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layer: I.port("输入", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Keras SeparableConv2D 层

Average

# M.keras_layer_average.v1
USER_PARAMS_DESC = """自定义参数"""
USER_PARAMS = """def bigquant_run():
    # https://keras.io/api/layers/merging_layers/average/

    # import keras

    init_params = dict(
        # **kwargs
    )
    call_params = dict(
        # inputs,
        # **kwargs
    )

    return {"init": init_params, "call": call_params}
"""
def run(
    user_params: I.code(USER_PARAMS_DESC, I.code_python, USER_PARAMS, specific_type_name="函数", auto_complete_type="python") = None,  # type: ignore
    debug: I.bool("输出调试信息,输出更多日志用于debug") = False,  # type: ignore
    input_layers_1: I.port("输入1", optional=False) = None,  # type: ignore
    input_layers_2: I.port("输入2", optional=False) = None,  # type: ignore
    input_layers_3: I.port("输入3", optional=True) = None,  # type: ignore
) -> [I.port("layer", "data")]:  # type: ignore
    """Average 层是 Keras 中用于对一组输入张量进行元素级平均的类。

Keras 自定义层

# M.keras_layer.v1
DEFAULT_RUN = """# input_1/2/3 对应三个输入端
def bigquant_run(input_1, input_2, input_3):
    import keras

    layer = keras.Input(shape=(28, 28, 1))

    return layer
"""
def run(
    run: I.code("自定义层函数, 返回 keras layer", I.code_python, default=DEFAULT_RUN, specific_type_name="函数", auto_complete_type="python"),
    input_1: I.port("输入1", optional=True) = None,
    input_2: I.port("输入2", optional=True) = None,
    input_3: I.port("输入3", optional=True) = None,
) -> [I.port("layer", "data")]:
    """自定义 Keras 层

\

标签

深度学习
{link}