【发布时间】:2017-02-02 22:18:06
【问题描述】:
我正在做一点深度学习,我想获取所有隐藏层的值。所以我最终写了这样的函数:
def forward_pass(x, ws, bs):
activations = []
u = x
for w, b in zip(ws, bs):
u = np.maximum(0, u.dot(w)+b)
activations.append(u)
return activations
如果我不必获取中间值,我会使用更简洁的形式:
out = reduce(lambda u, (w, b): np.maximum(0, u.dot(w)+b), zip(ws, bs), x)
巴姆。一条线,美观紧凑。但我不能保留任何中间值。
那么,有什么方法可以让我的蛋糕(漂亮紧凑的单衬里)也吃掉(返回中间值)?
【问题讨论】:
-
您想保留哪些
intermediate values? -
告诉我们
x,ws,bs,尤其是它们的尺寸。甚至可能是一个带有输出的样本集。 -
(w, b)给了我一个语法错误(在 Py3 中) -
我认为这个问题并不重要,但形状是:x_shape:
(n_samples, n_dims[0]),w_shapes:[(n_dims[i], n_dims[i+1]) for i in range(len(ws))],b_shapes:[(n_dims[i], ) for i in range(len(ws))]。我正在使用 python 2.7,很惊讶它会导致 Python 3 中的语法错误。
标签: python numpy deep-learning reduce