MCPcopy
hub / github.com/PaddlePaddle/PaddleOCR / forward

Method forward

ppocr/modeling/transforms/tps.py:184–211  ·  view source on GitHub ↗

Generate the grid for the grid_sampler. Args: batch_C_prime: the matrix of the geometric transformation I_r_size: the shape of the input image Return: batch_P_prime: the grid for the grid_sampler

(self, batch_C_prime, I_r_size)

Source from the content-addressed store, hash-verified

182 )
183
184 def forward(self, batch_C_prime, I_r_size):
185 """
186 Generate the grid for the grid_sampler.
187 Args:
188 batch_C_prime: the matrix of the geometric transformation
189 I_r_size: the shape of the input image
190 Return:
191 batch_P_prime: the grid for the grid_sampler
192 """
193 C = self.build_C_paddle()
194 P = self.build_P_paddle(I_r_size)
195
196 inv_delta_C_tensor = self.build_inv_delta_C_paddle(C).astype("float32")
197 P_hat_tensor = self.build_P_hat_paddle(C, paddle.to_tensor(P)).astype("float32")
198
199 inv_delta_C_tensor.stop_gradient = True
200 P_hat_tensor.stop_gradient = True
201
202 batch_C_ex_part_tensor = self.get_expand_tensor(batch_C_prime)
203
204 batch_C_ex_part_tensor.stop_gradient = True
205
206 batch_C_prime_with_zeros = paddle.concat(
207 [batch_C_prime, batch_C_ex_part_tensor], axis=1
208 )
209 batch_T = paddle.matmul(inv_delta_C_tensor, batch_C_prime_with_zeros)
210 batch_P_prime = paddle.matmul(P_hat_tensor, batch_T)
211 return batch_P_prime
212
213 def build_C_paddle(self):
214 """Return coordinates of fiducial points in I_r; C"""

Callers

nothing calls this directly

Calls 5

build_C_paddleMethod · 0.95
build_P_paddleMethod · 0.95
build_P_hat_paddleMethod · 0.95
get_expand_tensorMethod · 0.95

Tested by

no test coverage detected