Esempio n. 1
0
    def transforms(self, cfg, img, coor):
        # resize
        if cfg.has_key('RESIZE'):
            img = resize(img, cfg.RESIZE, cfg.RESIZE)

        if self.is_train:

            # Color
            if cfg.COLOR_NORISE:
                img[0, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)
                img[1, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)
                img[2, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)

        return img, coor
Esempio n. 2
0
    def transforms(self, cfg, img, coor, project_coor, matrix):
        # resize
        if cfg.has_key('RESIZE'):

            project_coor[:, 0] = project_coor[:, 0] * cfg.RESIZE / img.size(1)
            project_coor[:, 1] = project_coor[:, 1] * cfg.RESIZE / img.size(2)

            img = resize(img, cfg.RESIZE, cfg.RESIZE)
            scale = [[1. * cfg.RESIZE / img.shape[0], 0, 0],
                     [0, 1. * cfg.RESIZE / img.shape[1], 0], [0, 0, 1]]
            matrix = np.matmul(scale, matrix)

        if self.is_train:
            # Color
            if cfg.COLOR_NORISE:
                img[0, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)
                img[1, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)
                img[2, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)

        return img, coor, project_coor, matrix
    def transforms(self, cfg, img, coor):
        # resize
        if cfg.has_key('RESIZE'):
            coor[:, 0] = coor[:, 0] / img.size(1) * cfg.RESIZE
            coor[:, 1] = coor[:, 1] / img.size(2) * cfg.RESIZE
            img = resize(img, cfg.RESIZE, cfg.RESIZE)

        if self.is_train:
            # Flip
            if cfg.FLIP and random.random() <= 0.5:
                img = torch.flip(img, dims=[1])
                coor[:, 1] = img.size(1) - coor[:, 1]

            # Color
            if cfg.COLOR_NORISE:
                img[0, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)
                img[1, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)
                img[2, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)

        return img, coor
Esempio n. 4
0
	def transforms(self, cfg, img, depth, coor2d, matrix):
		# resize
		if cfg.has_key('RESIZE'):
			xscale, yscale = 1. * cfg.RESIZE / img.size(1), 1. * cfg.RESIZE / img.size(2) 
			coor2d[:, 0] *= xscale
			coor2d[:, 1] *= yscale
			scale =[[xscale,    0,  0],
					[0,    yscale,  0],
					[0,         0,  1]]
			matrix = np.matmul(scale, matrix)

			img = resize(img, cfg.RESIZE, cfg.RESIZE)
			depth = depth.unsqueeze(0)
			depth = interpolate(depth, (128, 128), mode = 'bilinear', align_corners = True)[0,...]

		if cfg.COLOR_NORISE:
			img[0, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)
			img[1, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)
			img[2, :, :].mul_(random.uniform(0.8, 1.2)).clamp_(-0.5, 0.5)

		assert coor2d[:, :2].min() >= 0 and coor2d[:, :2].max() < 256
		return img, depth, coor2d, matrix