Example #1
0
 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
Example #2
0
 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
Example #3
0
    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)
Example #4
0
 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)
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    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)
Example #8
0
 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
Example #9
0
 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
Example #10
0
 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)
Example #11
0
 def _oper_gpu(cls, lhs, rhs):
     return - get_gpu(rhs) + get_gpu(lhs)
Example #12
0
 def _oper_gpu(cls, arg):
     return +get_gpu(arg)
Example #13
0
 def _oper_gpu(cls, arg, axis):
     return get_gpu(arg).transpose(axis)
Example #14
0
 def _oper_gpu(cls, array, shape):
     return get_gpu(array).reshape(shape)
Example #15
0
 def _oper_gpu(cls, lhs, rhs):
     return get_gpu(lhs)[rhs]
Example #16
0
 def _oper_gpu(cls, arg):
     new_ptr = get_gpu(arg).empty_like_me()
     cuabs_forward(get_gpu(arg), new_ptr)
     return new_ptr
Example #17
0
 def _oper_gpu(cls, lhs, rhs):
     return get_gpu(lhs) ** get_gpu(rhs)
Example #18
0
 def _oper_gpu(cls, arg):
     return -(get_gpu(arg))
Example #19
0
 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)
Example #20
0
 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)
Example #21
0
 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)
Example #22
0
 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
Example #23
0
 def _backward_gpu(self, context, dy, **kwargs):
     if isinstance(self.attrs._arg, Node):
         self.attrs._arg._update_diff(context, get_gpu(dy), **kwargs)
Example #24
0
 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