相关疑难解决方法(0)

在Keras中创建恒定值

我试图在keras模型中创建一个常量变量。到目前为止,我一直在做的是将其作为输入传递。但是它始终是一个常量,因此我希望将其作为常量(输入[1,2,3...50]用于每个示例=>,因此我np.tile(np.array(range(50)),(len(X_input)))通常在每个示例中都进行重现)

所以现在我有了:

constant_input = Input(shape=(50,), dtype='int32', name="constant_input")
Run Code Online (Sandbox Code Playgroud)

给出张量: Tensor("constant_input", shape(?,50), dtype=int32)

现在尝试将其作为常量:

np_constant = np.array(list(range(50))).reshape(1, 50)
tf_constant = K.constant(np_constant)
tensor_constant = Input(tensor=tf_constant, shape=(50,), dtype='int32', name="constant_input")
Run Code Online (Sandbox Code Playgroud)

给出张量: Tensor("constant_input", shape(50,1),dtype=float32)

但是我想要的是在每个批次中要缩放的常数,这意味着张量的形状应该(?, 50)与使用的方式相同Input

有可能这样做吗?

python keras

2
推荐指数
1
解决办法
2807
查看次数

标签 统计

keras ×1

python ×1