【发布时间】:2018-03-10 00:00:54
【问题描述】:
我正在尝试在 keras 模型中创建一个常量变量。到目前为止我所做的是将它作为输入传递。但它始终是一个常数,所以我希望它是一个常数。(每个示例的输入是[1,2,3...50] => 所以我使用np.tile(np.array(range(50)),(len(X_input))) 为每个示例重现它)
所以现在我有:
constant_input = Input(shape=(50,), dtype='int32', name="constant_input")
给出张量: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")
给出张量:Tensor("constant_input", shape(50,1),dtype=float32)
但我想要的是每批要缩放的常数,也就是说张量的形状应该是(?, 50),和Input的使用方式一样。
有可能吗?
【问题讨论】: