Ejemplo n.º 1
0
    def forward(self, w_value, x_value, b_value, is_numba):
        self.w_value = w_value
        self.x_value = x_value
        self.b_value = b_value

        if is_numba:
            x_value, col, col_w, out = self._forward(w_value, x_value, b_value,
                                                     self.pad, self.stride)
            self.x_value = x_value
            self.col = col
            self.col_w = col_w
            return out
        else:
            FN, C, FH, FW = self.w_value.shape
            N, C, H, W = x_value.shape
            out_h = 1 + int((H + 2 * self.pad - FH) / self.stride)
            out_w = 1 + int((W + 2 * self.pad - FW) / self.stride)

            col = tff.im2col(x_value, FH, FW, self.stride, self.pad)
            col_w = self.w_value.reshape(FN, -1).T

            out = np.dot(col, col_w) + self.b_value
            out = out.reshape(N, out_h, out_w, -1).transpose(0, 3, 1, 2)

            self.x_value = x_value
            self.col = col
            self.col_w = col_w

            return out
Ejemplo n.º 2
0
    def _forward(w_value, x_value, b_value, pad, stride):
        FN, C, FH, FW = w_value.shape
        N, C, H, W = x_value.shape
        out_h = 1 + int((H + 2 * pad - FH) / stride)
        out_w = 1 + int((W + 2 * pad - FW) / stride)

        col = tff.im2col(x_value, FH, FW, stride, pad)
        col_w = w_value.reshape(FN, -1).T

        out = np.dot(col, col_w) + b_value
        out = out.reshape(N, out_h, out_w, -1).transpose(0, 3, 1, 2)

        return x_value, col, col_w, out
Ejemplo n.º 3
0
    def _forward(x_value, filter_h, filter_w, pad, stride):
        N, C, H, W = x_value.shape
        out_h = int(1 + (H - filter_h) / stride)
        out_w = int(1 + (W - filter_w) / stride)

        col = tff.im2col(x_value, filter_h, filter_w, stride, pad)
        col = col.reshape(-1, filter_h * filter_w)

        arg_max = np.argmax(col, axis=1)
        out = np.max(col, axis=1)
        out = out.reshape(N, out_h, out_w, C).transpose(0, 3, 1, 2)

        return arg_max, out
Ejemplo n.º 4
0
    def _forward(w_value, x_value, pad, stride):
        FN, C, FH, FW = w_value.shape
        N, C, H, W = x_value.shape
        out_h = int(1 + (H - FH) / stride)
        out_w = int(1 + (W - FW) / stride)

        col = tff.im2col(x_value, FH, FW, stride, pad)
        col = col.reshape(-1, FH * FW)

        arg_max = np.argmax(col, axis=1)
        out = np.max(col, axis=1)
        out = out.reshape(N, out_h, out_w, C).transpose(0, 3, 1, 2)

        return arg_max, out
Ejemplo n.º 5
0
    def forward(self, x_value, is_train=True, is_numba=False):
        self.x_value = x_value

        if is_numba:
            arg_max, out = self._forward(self.x_value, self.filter_h,
                                         self.filter_w, self.pad, self.stride)
            self.arg_max = arg_max
            return out
        else:
            N, C, H, W = self.x_value.shape
            out_h = int(1 + (H - self.filter_h) / self.stride)
            out_w = int(1 + (W - self.filter_w) / self.stride)

            col = tff.im2col(self.x_value, self.filter_h, self.filter_w,
                             self.stride, self.pad)
            col = col.reshape(-1, self.filter_h * self.filter_w)

            arg_max = np.argmax(col, axis=1)
            out = np.max(col, axis=1)
            out = out.reshape(N, out_h, out_w, C).transpose(0, 3, 1, 2)

            self.arg_max = arg_max
            return out
Ejemplo n.º 6
0
    def forward(self, w_value, x_value, is_numba):
        self.w_value = w_value
        self.x_value = x_value

        if is_numba:
            arg_max, out = self._forward(self.w_value, self.x_value, self.pad,
                                         self.stride)
            self.arg_max = arg_max
            return out
        else:
            FN, C, FH, FW = self.w_value.shape
            N, C, H, W = self.x_value.shape
            out_h = int(1 + (H - FH) / self.stride)
            out_w = int(1 + (W - FW) / self.stride)

            col = tff.im2col(self.x_value, FH, FW, self.stride, self.pad)
            col = col.reshape(-1, FH * FW)

            arg_max = np.argmax(col, axis=1)
            out = np.max(col, axis=1)
            out = out.reshape(N, out_h, out_w, C).transpose(0, 3, 1, 2)

            self.arg_max = arg_max
            return out