MCPcopy Create free account
hub / github.com/apple/ml-pointersect / Test_Sample_Patch

Class Test_Sample_Patch

tests/plib/test_utils.py:275–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273
274
275class Test_Sample_Patch(unittest.TestCase):
276
277 def test_1(self):
278 b, c, h, w = 2, 1, 5, 6
279 bchw = b * c * h * w
280 arr = torch.arange(bchw).reshape(b, c, h, w).float()
281
282 center = torch.tensor([
283 [1., 1.],
284 [1.5, 2.5,]
285 ])
286
287 out = utils.sample_patch(
288 arr=arr,
289 patch_center=center,
290 patch_width_px=3,
291 patch_width_pitch_scale=1,
292 )
293 assert out.shape == (b, c, 3, 3)
294 assert torch.allclose(out[1], arr[1, :, 1:4, 0:3])
295
296 def test_2(self):
297 b, c, h, w = 2, 1, 5, 6
298 bchw = b * c * h * w
299 arr = torch.arange(bchw).reshape(b, c, h, w).float()
300
301 center = torch.tensor([
302 [1., 1.],
303 [1.5, 2.5],
304 ])
305
306 out = utils.sample_patch(
307 arr=arr,
308 patch_center=center,
309 patch_width_px=3,
310 patch_width_pitch_scale=2,
311 )
312 assert out.shape == (b, c, 3, 3)
313 # print(arr)
314 # print(out)
315
316
317if __name__ == '__main__':

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected