def prepare_input(img, inp_dim): orig_im = img dim = orig_im.shape[1], orig_im.shape[0] img = (custom_resize(orig_im, (inp_dim, inp_dim))) img_ = img[:, :, ::-1].transpose((2, 0, 1)).copy() img_ = torch.from_numpy(img_).float().div(255.0).unsqueeze(0) return img_, orig_im, dim
def prepare_input(img, inp_dim): """ Prepare image for inputting to the neural network. Perform tranpose and return Tensor """ orig_im = img dim = orig_im.shape[1], orig_im.shape[0] img = (custom_resize(orig_im, (inp_dim, inp_dim))) img_ = img[:,:,::-1].transpose((2,0,1)).copy() img_ = torch.from_numpy(img_).float().div(255.0).unsqueeze(0) return img_, orig_im, dim
def prepare_input(img, inp_dim): """ Prepare image for inputting to the neural network. Perform tranpose and return Tensor """ orig_im = img dim = orig_im.shape[1], orig_im.shape[0] img = (custom_resize(orig_im, (inp_dim, inp_dim))) # Opencv image format,[Channels * Width * Height]. The opencv channles are BGR, # img[:,:,::-1] is convert to RGB. transpose(2,0,1) is to change them to [C * W * H]. # then creates a copy img_ = img[:, :, ::-1].transpose((2, 0, 1)).copy() # unsqueeze returns new tensor with a dimension of 0 img_ = torch.from_numpy(img_).float().div(255.0).unsqueeze(0) return img_, orig_im, dim