MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / SharpenKernel

Function SharpenKernel

imperative/python/megengine/module/vision.py:361–396  ·  view source on GitHub ↗
(input, f, c)

Source from the content-addressed store, hash-verified

359 "SharpenKernel", dtype=dtype, device=device, nr_inputs=2, gopt_level=None,
360 )
361 def SharpenKernel(input, f, c):
362 inp_e, inp_n = input[0:2]
363 c_alp = c(alpha, dtype="float32")
364 c_sub_alp = c(1 - alpha, dtype="float32")
365 c_lts = c(lightness, dtype="float32")
366 c_1 = c(1, dtype="int32")
367 c_2 = c(2, dtype="int32")
368 c_3 = c(3, dtype="int32")
369
370 def _subtensor(src, axis, begin, end):
371 items = ((axis, (begin is not None), (end is not None), False, False),)
372 args = ()
373 if begin is not None:
374 args += (begin,)
375 if end is not None:
376 args += (end,)
377 return f(builtin.Subtensor(items=items), src, *args)
378
379 def _kernel_init(x):
380 k_1 = _subtensor(x, 0, None, c_1)
381 k_2 = _subtensor(x, 0, c_1, c_2)
382 k_3 = _subtensor(x, 0, c_2, c_3)
383 k_21 = _subtensor(k_2, 1, None, c_1)
384 k_22 = f("+", _subtensor(k_2, 1, c_1, c_2), c_lts)
385 k_23 = _subtensor(k_2, 1, c_2, c_3)
386 nk_2 = f(builtin.Concat(axis=1), k_21, k_22, k_23,)
387 return f(builtin.Concat(axis=0), k_1, nk_2, k_3,)
388
389 def _kernel_calc(k_e, k_n):
390 k1 = f("*", k_n, c_sub_alp)
391 k2 = f("*", k_e, c_alp)
392 return f("+", k1, k2)
393
394 kernel_effect = _kernel_init(inp_e)
395 kernel = _kernel_calc(kernel_effect, inp_n)
396 return (kernel,), (False,)
397
398 return SharpenKernel
399

Callers

nothing calls this directly

Calls 2

_kernel_initFunction · 0.85
_kernel_calcFunction · 0.85

Tested by

no test coverage detected