def __new__(cls, arg, length, ctr): ary = GPUValue(shape=arg.shape) arg = get_gpu(arg) length = get_gpu(length) ctr = get_gpu(ctr) value = cls.calc_value(arg, length, ctr, ary) ret = super(PredCtr, cls).__new__(cls, value) return ret
def __new__(cls, arg, x, y, h, w): ary = GPUValue(shape=arg.shape) x = get_gpu(x) y = get_gpu(y) h = get_gpu(h) w = get_gpu(w) value = cls.calc_value(ary, x, y, h, w) ret = super(AssignPredBox, cls).__new__(cls, value) return ret
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._rhs, Node): rhs = get_gpu(self.attrs._rhs) r_dx = cu_broad_cast(rhs, get_gpu(dy)) self.attrs._rhs._update_diff(context, r_dx, **kwargs) if isinstance(self.attrs._lhs, Node): lhs = get_gpu(self.attrs._lhs) l_dx = cu_broad_cast(lhs, get_gpu(dy)) self.attrs._lhs._update_diff(context, l_dx, **kwargs)
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._lhs, Node): if self._is_advanced_indexing(self.attrs._lhs, self.attrs._rhs): self._backward_cpu(context, to_value(dy), **kwargs) else: zero = get_gpu(self.attrs._lhs).zeros_like_me() zero[self.attrs._rhs] = dy self.attrs._lhs._update_diff(context, zero, **kwargs)
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._lhs, Node): lhs = get_gpu(self.attrs._lhs) rhs = get_gpu(self.attrs._rhs) v = get_gpu(dy) * rhs * (GPUValue.__pow__(lhs, rhs - 1)) dxl = cu_broad_cast(lhs, v) self.attrs._lhs._update_diff(context, dxl, **kwargs) if isinstance(self.attrs._rhs, Node): lhs = get_gpu(self.attrs._lhs).empty_like_me() culoge(get_gpu(self.attrs._lhs), lhs) new_r_dx = get_gpu(dy) * get_gpu(self) * lhs self.attrs._rhs._update_diff(context, new_r_dx, **kwargs)
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._rhs, Node): lhs = get_gpu(self.attrs._lhs) rhs = get_gpu(self.attrs._rhs) dxr = cu_broad_cast(rhs, lhs * get_gpu(dy)) self.attrs._rhs._update_diff(context, dxr, **kwargs) if isinstance(self.attrs._lhs, Node): lhs = get_gpu(self.attrs._lhs) rhs = get_gpu(self.attrs._rhs) dxl = cu_broad_cast(lhs, rhs * get_gpu(dy)) self.attrs._lhs._update_diff(context, dxl, **kwargs)
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._lhs, Node): lhs = get_gpu(self.attrs._lhs) rhs = get_gpu(self.attrs._rhs) dxl = cu_broad_cast(lhs, get_gpu(dy) / rhs) self.attrs._lhs._update_diff(context, dxl, **kwargs) if isinstance(self.attrs._rhs, Node): lhs = get_gpu(self.attrs._lhs) rhs = get_gpu(self.attrs._rhs) v = rhs ** (-2.0) * -1.0 * lhs * get_gpu(dy) dxr = cu_broad_cast(rhs, v) self.attrs._rhs._update_diff(context, dxr, **kwargs)
def __new__(cls, arg, i): arg = get_gpu(arg) ary = GPUValue(shape=(arg.shape[0], 1)) value = cls.calc_value(arg, i, ary) ret = super(GetIthBbox, cls).__new__(cls, value) return ret
def _oper_gpu(cls, arg, i, j): ary = GPUValue(shape=(arg.shape[0], ((arg.shape[1] - (i + 1)) // j) + 1)) arg = get_gpu(arg) cu_get_every_nth_ary(arg, ary, i, j) return ary
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._lhs, Node): zero = get_gpu(self.attrs._lhs).zeros_like_me() cu_get_ith_ary_backward(dy, zero, self.attrs._index) self.attrs._arg._update_diff(context, zero, **kwargs)
def _oper_gpu(cls, lhs, rhs): return - get_gpu(rhs) + get_gpu(lhs)
def _oper_gpu(cls, arg): return +get_gpu(arg)
def _oper_gpu(cls, arg, axis): return get_gpu(arg).transpose(axis)
def _oper_gpu(cls, array, shape): return get_gpu(array).reshape(shape)
def _oper_gpu(cls, lhs, rhs): return get_gpu(lhs)[rhs]
def _oper_gpu(cls, arg): new_ptr = get_gpu(arg).empty_like_me() cuabs_forward(get_gpu(arg), new_ptr) return new_ptr
def _oper_gpu(cls, lhs, rhs): return get_gpu(lhs) ** get_gpu(rhs)
def _oper_gpu(cls, arg): return -(get_gpu(arg))
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._array, Node): self.attrs._array._update_diff(context, get_gpu( dy).reshape(self.attrs._shape), **kwargs)
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._arg, Node): new_ptr = get_gpu(dy).empty_like_me() cuabs_backward(get_gpu(self.attrs._arg), new_ptr) self.attrs._arg._update_diff(context, new_ptr, **kwargs)
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._arg, Node): axis = self.attrs._axis self.attrs._arg._update_diff(context, get_gpu(dy).transpose(axis), **kwargs)
def _oper_gpu(cls, arg): shape = arg.shape fg_ary = GPUValue(shape=(shape[0], shape[1], 1, shape[3], shape[4])) arg = get_gpu(arg) cu_get_fg_ary_forward(arg, fg_ary) return fg_ary
def _backward_gpu(self, context, dy, **kwargs): if isinstance(self.attrs._arg, Node): self.attrs._arg._update_diff(context, get_gpu(dy), **kwargs)
def _oper_gpu(cls, arg, i): shape = arg.shape ith_ary = GPUValue(shape=(shape[1:])) arg = get_gpu(arg) cu_get_ith_ary_forward(arg, ith_ary, i) return ith_ary