K.cast和tf.cast不会转换数据类型

时间:2019-10-17 23:03:43

标签: tensorflow keras types casting boolean

我正在使用Keras Functional API

nonNegActivity = K.cast(K.greater_equal(activity,0.05),tf.float32)行应将我的活动转换为bool,然后转换为float32,但在调用fit时出现 TypeError ,说明:

TypeError: Value passed to parameter 'values' has DataType bool not in list of allowed values: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, float16, uint32, uint64

整个模型:

X = Input(shape=(self.Tx,self.kx,))
lstm_regr = LSTM(400,return_sequences=True,activation="tanh")(X)regr = Dense(self.ky)(lstm_regr)
lstm_activity = LSTM(400,return_sequences=True,activation="sigmoid")(X) activity = Dense(self.ky)(lstm_activity)
nonNegActivity = K.cast(K.greater_equal(activity,0.05),tf.float32)
multiplied = Multiply()([nonNegActivity,regr])
out = [multiplied,activity]
model = Model(inputs=X, outputs=out)

0 个答案:

没有答案