【发布时间】:2019-08-28 20:12:49
【问题描述】:
我正在 python 3.6.8 中使用 tensorflow 1.14.0 训练去噪自动编码器。每个训练步骤都包括模型的拟合,还应根据先前的预测优化其他变量 theta(损失中使用的二项式分布),这会对下一个预测产生影响。
这是我的问题: 如何在每个列的每个训练步骤之后最小化这个 theta?那么基于当前预测的交替训练作为每列最小化问题的输入?
我已经尝试过的:
将 tf.map_fn 与一个最小化函数结合使用,该函数会为每个列引入一个新会话和优化器以最小化 -> 工作正常,但由于创建多个会话而速度太慢(请参阅来自 Minimize a function of one variable in Tensorflow 的 tf_minimize)
为每列创建优化器哈希表以最小化 theta -> 10 000 列的单独优化器初始化不可行(比较:How to alternate train op's in tensorflow?)
### no functioning python code, just to give you an idea
### input in tensorflow model: ae_input, theta
### training steps
for epoch in range(200):
model.fit( x = ae_input+theta,
y = ae_input,
epochs = epoch+1)
current_pred = model.predict(ae_input+theta)
theta = update_theta(ae_input, current_pred) # PROBLEMATIC STEP
### current way because map_fn is not working and
### would also be too slow due to multiple session creation
def update_theta(y_true, y_pred):
theta_list=[]
for col in range(y_true.get_shape()[1]):
t = theta_optimize(y_true[:,x], y_pred[:,x])
theta_list.append(t)
return theta_list
### minimize theta for single column
def theta_optimize(y_t, y_p):
var_theta = tf.Variable(5.)
func_to_minimize = loss_per_col(y_t, y_p, var_theta)
optimial_theta = tf_minimize(func_to_optimize, output=var_theta)
### tf_minimize from link mentioned above
return optimal_theta
【问题讨论】:
标签: python tensorflow