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

Function EmbossKernel

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

Source from the content-addressed store, hash-verified

263 "EmbossKernel", dtype=dtype, device=device, nr_inputs=2, gopt_level=None,
264 )
265 def EmbossKernel(input, f, c):
266 inp_e, inp_n = input[0:2]
267 c_alp = c(alpha, dtype="float32")
268 c_sub_alp = c(1 - alpha, dtype="float32")
269 c_stg = c(strength, dtype="float32")
270 c_1 = c(1, dtype="int32")
271 c_2 = c(2, dtype="int32")
272 c_3 = c(3, dtype="int32")
273
274 def _subtensor(src, axis, begin, end):
275 items = ((axis, (begin is not None), (end is not None), False, False),)
276 args = ()
277 if begin is not None:
278 args += (begin,)
279 if end is not None:
280 args += (end,)
281 return f(builtin.Subtensor(items=items), src, *args)
282
283 def _kernel_init(x):
284 k_1 = _subtensor(x, 0, None, c_1)
285 k_2 = _subtensor(x, 0, c_1, c_2)
286 k_3 = _subtensor(x, 0, c_2, c_3)
287 k_11 = f("-", _subtensor(k_1, 1, None, c_1), c_stg)
288 k_12_21 = f("-", _subtensor(k_1, 1, c_1, c_2), c_stg)
289 k_23_32 = f("+", _subtensor(k_2, 1, c_2, c_3), c_stg)
290 k_33 = f("+", _subtensor(k_3, 1, c_2, c_3), c_stg)
291 k_13 = _subtensor(k_1, 1, c_2, c_3)
292 k_22 = _subtensor(k_2, 1, c_1, c_2)
293 k_31 = _subtensor(k_3, 1, None, c_1)
294 nk_1 = f(builtin.Concat(axis=1), k_11, k_12_21, k_13,)
295 nk_2 = f(builtin.Concat(axis=1), k_12_21, k_22, k_23_32,)
296 nk_3 = f(builtin.Concat(axis=1), k_31, k_23_32, k_33,)
297 return f(builtin.Concat(axis=0), nk_1, nk_2, nk_3,)
298
299 def _kernel_calc(k_e, k_n):
300 k1 = f("*", k_n, c_sub_alp)
301 k2 = f("*", k_e, c_alp)
302 return f("+", k1, k2)
303
304 kernel_effect = _kernel_init(inp_e)
305 kernel = _kernel_calc(kernel_effect, inp_n)
306 return (kernel,), (False,)
307
308 return EmbossKernel
309

Callers

nothing calls this directly

Calls 2

_kernel_initFunction · 0.85
_kernel_calcFunction · 0.85

Tested by

no test coverage detected