Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I build a convolutional layer using the BFV scheme? #497

Open
reaneling opened this issue Oct 4, 2024 · 0 comments
Open

How can I build a convolutional layer using the BFV scheme? #497

reaneling opened this issue Oct 4, 2024 · 0 comments
Labels
Type: Question ❔ Question about implementation or some technical aspect

Comments

@reaneling
Copy link

Question

Hello!

I am researching convolutional neural networks on various homomorphic encryption schemes. I noticed that you have support for the BFV scheme. However, I cannot build a convolutional layer and I can find a similar command "im2col_encoding" for BFV too.
Is it possible in principle to build CNN-BFV using your library and how to do it?

Further Information

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [36], [line 2](vscode-notebook-cell:?execution_count=36&line=2)
      [1](vscode-notebook-cell:?execution_count=36&line=1) enc_model = EncConvNet(model)
----> [2](vscode-notebook-cell:?execution_count=36&line=2) enc_test(context, enc_model, test_loader, criterion, kernel_shape, stride)

Cell In [32], [line 49](vscode-notebook-cell:?execution_count=32&line=49)
     [45](vscode-notebook-cell:?execution_count=32&line=45) class_total = list(0. for i in range(10))
     [47](vscode-notebook-cell:?execution_count=32&line=47) for data, target in test_loader:
     [48](vscode-notebook-cell:?execution_count=32&line=48)     # Encoding and encryption
---> [49](vscode-notebook-cell:?execution_count=32&line=49)     x_enc, windows_nb = ts.im2col_encoding(
     [50](vscode-notebook-cell:?execution_count=32&line=50)         context, data.view(28, 28).tolist(), kernel_shape[0],
     [51](vscode-notebook-cell:?execution_count=32&line=51)         kernel_shape[1], stride
     [52](vscode-notebook-cell:?execution_count=32&line=52)     )
     [53](vscode-notebook-cell:?execution_count=32&line=53)     # Encrypted evaluation
     [54](vscode-notebook-cell:?execution_count=32&line=54)     enc_output = enc_model(x_enc, windows_nb)

File ~/src/tenseal/tenseal/__init__.py:37, in im2col_encoding(context, tensor, kernel_n_rows, kernel_n_cols, stride)
     [34](https://file+.vscode-resource.vscode-cdn.net/Users/reaneling/BFV/~/src/tenseal/tenseal/__init__.py:34)         raise ValueError("tensor must be a matrix")
     [35](https://file+.vscode-resource.vscode-cdn.net/Users/reaneling/BFV/~/src/tenseal/tenseal/__init__.py:35)     matrix = tensor.tolist()
---> [37](https://file+.vscode-resource.vscode-cdn.net/Users/reaneling/BFV/~/src/tenseal/tenseal/__init__.py:37) ckks_vec, windows_nb = _ts_cpp.im2col_encoding(
     [38](https://file+.vscode-resource.vscode-cdn.net/Users/reaneling/BFV/~/src/tenseal/tenseal/__init__.py:38)     context.data, matrix, kernel_n_cols, kernel_n_rows, stride
     [39](https://file+.vscode-resource.vscode-cdn.net/Users/reaneling/BFV/~/src/tenseal/tenseal/__init__.py:39) )
     [40](https://file+.vscode-resource.vscode-cdn.net/Users/reaneling/BFV/~/src/tenseal/tenseal/__init__.py:40) return CKKSVector._wrap(ckks_vec), windows_nb

ValueError: no global scale

System Information

  • OS: MacOS
  • OS Version: 15.0
  • Language Version: Python 3.9.13
  • Package Manager Version: pip 24.2
@reaneling reaneling added the Type: Question ❔ Question about implementation or some technical aspect label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question ❔ Question about implementation or some technical aspect
Projects
None yet
Development

No branches or pull requests

1 participant