Deep-Learning-21-Examples icon indicating copy to clipboard operation
Deep-Learning-21-Examples copied to clipboard

第四章 rende_naive中,g /= g.std() + 1e-8,除以梯度的均值是什么意思?求解答

Open zcc720 opened this issue 7 years ago • 0 comments

`def render_naive(t_obj, img0, iter_n=20, step=50.0): # t_score是优化目标。它是t_obj的平均值 # 结合调用处看,实际上就是layer_output[:, :, :, channel]的平均值 t_score = tf.reduce_mean(t_obj) # 计算t_score对t_input的梯度 t_grad = tf.gradients(t_score, t_input)[0]

# 创建新图
img = img0.copy()
for i in range(iter_n):
    # 在sess中计算梯度,以及当前的score
    g, score = sess.run([t_grad, t_score], {t_input: img})
    # 对img应用梯度。step可以看做“学习率”
    g /= g.std() + 1e-8
    img += g * step
    print('score(mean)=%f' % (score))
# 保存图片
savearray(img, 'naive.jpg')`

zcc720 avatar Nov 10 '18 06:11 zcc720