MCPcopy
hub / github.com/ddbourgin/numpy-ml / forward

Method forward

numpy_ml/neural_nets/layers/layers.py:3438–3478  ·  view source on GitHub ↗

Compute the layer output given input volume `X`. Parameters ---------- X : :py:class:`ndarray ` of shape `(n_ex, in_rows, in_cols, in_ch)` The input volume consisting of `n_ex` examples, each with dimension (`in_rows`, `in_cols

(self, X, retain_derived=True)

Source from the content-addressed store, hash-verified

3436 }
3437
3438 def forward(self, X, retain_derived=True):
3439 """
3440 Compute the layer output given input volume `X`.
3441
3442 Parameters
3443 ----------
3444 X : :py:class:`ndarray <numpy.ndarray>` of shape `(n_ex, in_rows, in_cols, in_ch)`
3445 The input volume consisting of `n_ex` examples, each with dimension
3446 (`in_rows`, `in_cols`, `in_ch`).
3447 retain_derived : bool
3448 Whether to retain the variables calculated during the forward pass
3449 for use later during backprop. If False, this suggests the layer
3450 will not be expected to backprop through wrt. this input. Default
3451 is True.
3452
3453 Returns
3454 -------
3455 Y : :py:class:`ndarray <numpy.ndarray>` of shape `(n_ex, out_rows, out_cols, out_ch)`
3456 The layer output.
3457 """ # noqa: E501
3458 if not self.is_initialized:
3459 self.in_ch = X.shape[3]
3460 self._init_params()
3461
3462 W = self.parameters["W"]
3463 b = self.parameters["b"]
3464
3465 s, p = self.stride, self.pad
3466 n_ex, in_rows, in_cols, in_ch = X.shape
3467
3468 # pad the input and perform the forward deconvolution
3469 Z = deconv2D_naive(X, W, s, p, 0) + b
3470 Y = self.act_fn(Z)
3471
3472 if retain_derived:
3473 self.X.append(X)
3474 self.derived_variables["Z"].append(Z)
3475 self.derived_variables["out_rows"].append(Z.shape[1])
3476 self.derived_variables["out_cols"].append(Z.shape[2])
3477
3478 return Y
3479
3480 def backward(self, dLdY, retain_grads=True):
3481 """

Callers 1

test_Deconv2DFunction · 0.95

Calls 3

_init_paramsMethod · 0.95
deconv2D_naiveFunction · 0.85
act_fnMethod · 0.80

Tested by 1

test_Deconv2DFunction · 0.76