if end is not None:
end_ind = [lr.name for lr in self.layers].index(end)
outputs = set([end] + diffs)
else:
end_ind = 0
outputs = set(self.inputs + diffs)
if kwargs:
if set(kwargs.keys()) != set(self.outputs):
raise Exception("Top diff arguments do not match net outputs.")
// Set top diffs according to defined shapes and make arrays single and
// C-contiguous as Caffe expects.
for top, diff in kwargs.iteritems():
if diff.shape[0] != self.blobs[top].num:
raise Exception("Diff is not batch sized")
if diff.ndim != 4:
raise Exception("{} diff is not 4-d".format(top))
self.blobs[top].diff[...] = diff
self._backward(start_ind, end_ind)
// Unpack diffs to extract
return {out: self.blobs[out].diff for out in outputs}
def _Net_forward_all(self, blobs=None, **kwargs):