refactor: add concrete.onnx mod with previous conv2d

the module is meant to contain machine learning operations as defined by
ONNX
This commit is contained in:
youben11
2022-04-13 06:47:26 +01:00
committed by Ayoub Benaissa
parent 09d8aa5aeb
commit 824e034084
6 changed files with 16 additions and 10 deletions

View File

@@ -10,6 +10,6 @@ from .compilation import (
EncryptionStatus,
compiler,
)
from .extensions import LookupTable, conv2d
from .extensions import LookupTable
from .mlir.utils import MAXIMUM_BIT_WIDTH
from .representation import Graph

View File

@@ -2,5 +2,4 @@
Provide additional features that are not present in numpy.
"""
from .convolution import conv2d
from .table import LookupTable

View File

@@ -0,0 +1,5 @@
"""
Implement machine learning operations as specified by ONNX.
"""
from .convolution import conv2d

View File

@@ -8,9 +8,9 @@ from typing import List, Optional, Tuple, Union
import numpy as np
import torch
from ..representation import Node
from ..tracing import Tracer
from ..values import EncryptedTensor
from ..numpy.representation import Node
from ..numpy.tracing import Tracer
from ..numpy.values import EncryptedTensor
SUPPORTED_AUTO_PAD = {
"NOTSET",

View File

@@ -6,6 +6,7 @@ import numpy as np
import pytest
import concrete.numpy as cnp
import concrete.onnx as connx
@pytest.mark.parametrize(
@@ -56,7 +57,7 @@ def test_conv2d(input_shape, weight_shape, strides, dilations, has_bias, helpers
@cnp.compiler({"x": "encrypted"}, configuration=configuration)
def function(x):
return cnp.conv2d(x, weight, bias, strides=strides, dilations=dilations)
return connx.conv2d(x, weight, bias, strides=strides, dilations=dilations)
inputset = [np.random.randint(0, 4, size=input_shape) for i in range(100)]
circuit = function.compile(inputset)
@@ -177,7 +178,7 @@ def test_bad_conv2d_tracing(
@cnp.compiler({"x": "encrypted"}, configuration=configuration)
def function(x):
return cnp.conv2d(x, weight, bias, pads, strides, dilations, auto_pad)
return connx.conv2d(x, weight, bias, pads, strides, dilations, auto_pad)
inputset = [np.random.randint(0, 4, size=input_shape) for i in range(100)]
with pytest.raises(expected_error) as excinfo:
@@ -194,13 +195,13 @@ def test_bad_conv2d_evaluation():
x = np.random.randint(0, 4, size=(1, 1, 4, 4))
with pytest.raises(ValueError) as excinfo:
cnp.conv2d(x, "abc")
connx.conv2d(x, "abc")
assert str(excinfo.value) == "Weight should be of type np.ndarray for evaluation"
weight = np.random.randint(0, 4, size=(1, 1, 2, 2))
with pytest.raises(ValueError) as excinfo:
cnp.conv2d(x, weight, "abc")
connx.conv2d(x, weight, "abc")
assert str(excinfo.value) == "Bias should be of type np.ndarray for evaluation"

View File

@@ -6,6 +6,7 @@ import numpy as np
import pytest
import concrete.numpy as cnp
import concrete.onnx as connx
# pylint: disable=line-too-long
@@ -91,7 +92,7 @@ return %2
""", # noqa: E501
),
pytest.param(
lambda x, w: cnp.conv2d(x, w),
lambda x, w: connx.conv2d(x, w),
{"x": "encrypted", "w": "encrypted"},
[
(