-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlayers.go
72 lines (56 loc) · 1.64 KB
/
layers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package henn
import (
"github.com/tuneinsight/lattigo/v4/ckks"
"github.com/tuneinsight/lattigo/v4/rlwe"
)
// Layer is a dummy interface for Convolution, Linear, and Activation layers.
type Layer interface {
isLayer()
}
// ConvLayer represents the convolution layer.
type ConvLayer struct {
InputX int
InputY int
Kernel [][][]float64
Bias []float64
Stride int
}
// isLayer implements Layer interface.
func (ConvLayer) isLayer() {}
// LinearLayer represents the linear layer.
type LinearLayer struct {
Weights [][]float64
Bias []float64
}
// isLayer implements Layer interface.
func (LinearLayer) isLayer() {}
// ActivationLayer represents the activation layer.
type ActivationLayer struct {
ActivationFn func(*HENeuralNet, *rlwe.Ciphertext)
}
// isLayer implements Layer interface.
func (ActivationLayer) isLayer() {}
// isEncodedLayer implements EncodedLayer interface.
func (ActivationLayer) isEncodedLayer() {}
// EncodedLayer represents the encoded layers that can be directly used in HENeuralNets.
type EncodedLayer interface {
isEncodedLayer()
}
// EncodedConvLayer represents the encoded convolution layer.
type EncodedConvLayer struct {
Im2ColX int // Same as kernel size
Im2ColY int // Same as repeats
mask *rlwe.Plaintext
Kernel []*rlwe.Plaintext
Bias []*rlwe.Plaintext
Stride int
}
// isEncodedLayer implements EncodedLayer interface.
func (EncodedConvLayer) isEncodedLayer() {}
// EncodedLinearLayer represents the encoded linear layer.
type EncodedLinearLayer struct {
Weights ckks.LinearTransform
Bias *rlwe.Plaintext
}
// isEncodedLayer implements EncodedLayer interface.
func (EncodedLinearLayer) isEncodedLayer() {}