MCPcopy Create free account
hub / github.com/drinkingcoder/NeuralMarker / __call__

Method __call__

core/utils/transformation.py:105–144  ·  view source on GitHub ↗
(self, image_batch, theta_batch=None, out_h=None, out_w=None, return_warped_image=True,
                 return_sampling_grid=False, padding_factor=1.0, crop_factor=1.0)

Source from the content-addressed store, hash-verified

103 self.theta_identity = self.theta_identity.cuda()
104
105 def __call__(self, image_batch, theta_batch=None, out_h=None, out_w=None, return_warped_image=True,
106 return_sampling_grid=False, padding_factor=1.0, crop_factor=1.0):
107
108 crop_factor = random.uniform(0.5, 5)
109 if image_batch is None:
110 b = 1
111 else:
112 b = image_batch.size(0)
113 if theta_batch is None:
114 theta_batch = self.theta_identity
115 theta_batch = theta_batch.expand(b, 2, 3).contiguous()
116 theta_batch = Variable(theta_batch, requires_grad=False)
117 # check if output dimensions have been specified at call time and have changed
118 if (out_h is not None and out_w is not None) and (out_h != self.out_h or out_w != self.out_w):
119 if self.geometric_model == 'affine':
120 gridGen = AffineGridGen(out_h, out_w, use_cuda=self.use_cuda)
121 elif self.geometric_model == 'hom':
122 gridGen = HomographyGridGen(out_h, out_w, use_cuda=self.use_cuda)
123 elif self.geometric_model == 'tps':
124 gridGen = TpsGridGen(out_h, out_w, use_cuda=self.use_cuda)
125 else:
126 gridGen = self.gridGen
127 sampling_grid = gridGen(theta_batch)
128
129 # rescale grid according to crop_factor and padding_factor
130 if padding_factor != 1 or crop_factor != 1:
131 sampling_grid = sampling_grid * (padding_factor * crop_factor)
132 # rescale grid according to offset_factor
133 if self.offset_factor is not None:
134 sampling_grid = sampling_grid * self.offset_factor
135
136 if return_sampling_grid and not return_warped_image:
137 return sampling_grid
138 # sample transformed image
139 warped_image_batch = F.grid_sample(image_batch, sampling_grid, align_corners=True)
140
141 if return_sampling_grid and return_warped_image:
142 return (warped_image_batch, sampling_grid)
143
144 return warped_image_batch
145
146
147class SynthPairTnf(object):

Callers

nothing calls this directly

Calls 3

AffineGridGenClass · 0.85
HomographyGridGenClass · 0.85
TpsGridGenClass · 0.85

Tested by

no test coverage detected