Exemplo n.º 1
0
 def hybrid_forward(self, F, x):
     x = x.transpose(axes=(0, 2, 1, 3))
     x = F.pad(x,
               mode="constant",
               pad_width=(0, 0, 0, 0, 0, self.padding, 0, 0),
               constant_value=0)
     x = x.transpose(axes=(0, 2, 1, 3))
     return x
Exemplo n.º 2
0
def get_subwindow_tracking(z, pos_x, pos_y, model_sz, original_sz, avgChans, ctx=mx.cpu()):
    if original_sz is None:
        original_sz = model_sz
    sz = original_sz
    im_sz = np.shape(z)
    cen = (sz - 1) / 2
    
    context_xmin = np.floor(pos_x - cen)
    context_xmax = context_xmin + sz - 1
    context_ymin = np.floor(pos_y - cen)
    context_ymax = context_ymin + sz - 1
    
    left_pad = nd.maximum(0, 1 - context_xmin)
    top_pad = nd.maximum(0, 1 - context_ymin)
    right_pad = nd.maximum(0, context_xmax - im_sz[1])
    bottom_pad = nd.maximum(0, context_ymax - im_sz[0])

    context_xmin = context_xmin + left_pad;
    context_xmax = context_xmax + left_pad;
    context_ymin = context_ymin + top_pad;
    context_ymax = context_ymax + top_pad;
    
    paddings = [0, 0, 0, 0, int(top_pad), int(bottom_pad), int(left_pad), int(right_pad)]
    if avgChans is not None:
        im_padded_ = z - avgChans
    im_padded_ = nd.expand_dims(im_padded_, axis = 0) # B H W C
    im_padded_ = nd.transpose(im_padded_, axes=(0,3,1,2)) # B C H W
    im_padded_ = nd.pad(im_padded_, pad_width=paddings, mode='constant')
    im_padded_ = nd.transpose(im_padded_, axes=(0,2,3,1)) # B H W C
    if avgChans is not None:
        im_padded_ = im_padded_ + avgChans
    im_padded = im_padded_[0]
    im_patch_original = im_padded[int(context_ymin - 1) : int(context_ymax), int(context_xmin - 1) : int(context_xmax), :]
    if int(model_sz) != int(original_sz):
        sz_dst_w = np.round(im_patch_original.shape[1] / original_sz * model_sz)
        sz_dst_h = np.round(im_patch_original.shape[0] / original_sz * model_sz)
        im_patch = image.fixed_crop(im_patch_original,
                                    x0 = 0,
                                    y0 = 0,
                                    w = im_patch_original.shape[1],
                                    h = im_patch_original.shape[0],
                                    size = [int(sz_dst_w), int(sz_dst_h)],
                                    interp = 1
                                    )
        if im_patch.shape[0] != model_sz:
            im_patch = image.fixed_crop(im_patch_original,
                                        x0 = 0,
                                        y0 = 0,
                                        w = im_patch_original.shape[1],
                                        h = im_patch_original.shape[0],
                                        size = [int(model_sz), int(model_sz)],
                                        interp = 1
                                        )
    else:
        im_patch = im_patch_original
    return im_patch, im_patch_original
Exemplo n.º 3
0
 def forward(self, x):
     return F.pad(x, mode='reflect', pad_width=self.pad_width)
Exemplo n.º 4
0
 def forward(self, x):
     return F.pad(x, mode='reflect', pad_width=self.pad_width)
Exemplo n.º 5
0
 def hybrid_forward(self, F, x):
     return F.pad(x, mode='reflect', pad_width=self.pad_width)