def test_lrn(): input_image_shape = (2, 3, 2, 1) input_image = np.arange(int( np.prod(input_image_shape))).reshape(input_image_shape).astype('f') runtime = get_runtime() model = ng.lrn(ng.constant(input_image), alpha=1.0, beta=2.0, bias=1.0, size=3) computation = runtime.computation(model) result = computation() assert np.allclose( result, np.array([[[[0.0], [0.05325444]], [[0.03402646], [0.01869806]], [[0.06805293], [0.03287071]]], [[[0.00509002], [0.00356153]], [[0.00174719], [0.0012555]], [[0.00322708], [0.00235574]]]], dtype=np.float32)) # Test LRN default parameter values model = ng.lrn(ng.constant(input_image)) computation = runtime.computation(model) result = computation() assert np.allclose( result, np.array([[[[0.0], [0.35355338]], [[0.8944272], [1.0606602]], [[1.7888544], [1.767767]]], [[[0.93704253], [0.97827977]], [[1.2493901], [1.2577883]], [[1.5617375], [1.5372968]]]], dtype=np.float32))
def LRN(onnx_node, ng_inputs): # type: (NodeWrapper, List[NgraphNode]) -> NgraphNode """Carry out Local Region Normalization. :param onnx_node: The ONNX node representation of LRN. :param ng_inputs: The input data node. :return: LRN output node. """ data = ng_inputs[0] alpha = onnx_node.get_attribute_value('alpha', 1e-4) beta = onnx_node.get_attribute_value('beta', 0.75) bias = onnx_node.get_attribute_value('bias', 1.0) size = onnx_node.get_attribute_value('size') if size is None: raise ValueError('LRN node (%s): required `size` attribute is missing', onnx_node.name) return ng.lrn(data, alpha, beta, bias, size)