poseigen-mimic 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- poseigen_mimic-0.1.0/LICENSE.txt +21 -0
- poseigen_mimic-0.1.0/PKG-INFO +57 -0
- poseigen_mimic-0.1.0/README.md +28 -0
- poseigen_mimic-0.1.0/pyproject.toml +46 -0
- poseigen_mimic-0.1.0/setup.cfg +4 -0
- poseigen_mimic-0.1.0/src/poseigen_mimic.egg-info/PKG-INFO +57 -0
- poseigen_mimic-0.1.0/src/poseigen_mimic.egg-info/SOURCES.txt +9 -0
- poseigen_mimic-0.1.0/src/poseigen_mimic.egg-info/dependency_links.txt +1 -0
- poseigen_mimic-0.1.0/src/poseigen_mimic.egg-info/requires.txt +8 -0
- poseigen_mimic-0.1.0/src/poseigen_mimic.egg-info/top_level.txt +1 -0
- poseigen_mimic-0.1.0/src/poseigen_mimic.py +382 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Husam Abdulnabi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: poseigen_mimic
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unified sequence-embedding architectures for the Poseigen family
|
|
5
|
+
Author-email: Husam Abdulnabi <husam.abdulnabi@gmail.com>
|
|
6
|
+
Maintainer-email: Husam Abdulnabi <husam.abdulnabi@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/husam94/poseigen
|
|
9
|
+
Project-URL: Repository, https://github.com/husam94/poseigen
|
|
10
|
+
Project-URL: Issues, https://github.com/husam94/poseigen/issues
|
|
11
|
+
Keywords: poseigen,bioinformatics,machine-learning,neural-networks
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering
|
|
15
|
+
Classifier: Topic :: Software Development
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE.txt
|
|
21
|
+
Requires-Dist: numpy
|
|
22
|
+
Requires-Dist: torch
|
|
23
|
+
Requires-Dist: poseigen_trident
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build; extra == "dev"
|
|
26
|
+
Requires-Dist: twine; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# Mimic
|
|
31
|
+
|
|
32
|
+
Mimic is the sequence-embedding architecture package in the Poseigen family.
|
|
33
|
+
It provides unified single- and dual-input models built from Trident's neural
|
|
34
|
+
network components.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install poseigen_mimic
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For local development, install from source using your preferred editable-install
|
|
43
|
+
workflow.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from poseigen_mimic import Mimic, Dual_Mimic
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Related Projects
|
|
52
|
+
|
|
53
|
+
- `poseigen_trident`: neural-network building blocks used by Mimic.
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
This project is released under the MIT License.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Mimic
|
|
2
|
+
|
|
3
|
+
Mimic is the sequence-embedding architecture package in the Poseigen family.
|
|
4
|
+
It provides unified single- and dual-input models built from Trident's neural
|
|
5
|
+
network components.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install poseigen_mimic
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For local development, install from source using your preferred editable-install
|
|
14
|
+
workflow.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from poseigen_mimic import Mimic, Dual_Mimic
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Related Projects
|
|
23
|
+
|
|
24
|
+
- `poseigen_trident`: neural-network building blocks used by Mimic.
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
This project is released under the MIT License.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "poseigen_mimic"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Unified sequence-embedding architectures for the Poseigen family"
|
|
9
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE.txt"]
|
|
13
|
+
authors = [{ name = "Husam Abdulnabi", email = "husam.abdulnabi@gmail.com" }]
|
|
14
|
+
maintainers = [{ name = "Husam Abdulnabi", email = "husam.abdulnabi@gmail.com" }]
|
|
15
|
+
keywords = ["poseigen", "bioinformatics", "machine-learning", "neural-networks"]
|
|
16
|
+
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Topic :: Scientific/Engineering",
|
|
21
|
+
"Topic :: Software Development",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
dependencies = [
|
|
27
|
+
"numpy",
|
|
28
|
+
"torch",
|
|
29
|
+
"poseigen_trident",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"build",
|
|
35
|
+
"twine",
|
|
36
|
+
"pytest",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/husam94/poseigen"
|
|
41
|
+
Repository = "https://github.com/husam94/poseigen"
|
|
42
|
+
Issues = "https://github.com/husam94/poseigen/issues"
|
|
43
|
+
|
|
44
|
+
[tool.setuptools]
|
|
45
|
+
package-dir = {"" = "src"}
|
|
46
|
+
py-modules = ["poseigen_mimic"]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: poseigen_mimic
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unified sequence-embedding architectures for the Poseigen family
|
|
5
|
+
Author-email: Husam Abdulnabi <husam.abdulnabi@gmail.com>
|
|
6
|
+
Maintainer-email: Husam Abdulnabi <husam.abdulnabi@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/husam94/poseigen
|
|
9
|
+
Project-URL: Repository, https://github.com/husam94/poseigen
|
|
10
|
+
Project-URL: Issues, https://github.com/husam94/poseigen/issues
|
|
11
|
+
Keywords: poseigen,bioinformatics,machine-learning,neural-networks
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering
|
|
15
|
+
Classifier: Topic :: Software Development
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE.txt
|
|
21
|
+
Requires-Dist: numpy
|
|
22
|
+
Requires-Dist: torch
|
|
23
|
+
Requires-Dist: poseigen_trident
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build; extra == "dev"
|
|
26
|
+
Requires-Dist: twine; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# Mimic
|
|
31
|
+
|
|
32
|
+
Mimic is the sequence-embedding architecture package in the Poseigen family.
|
|
33
|
+
It provides unified single- and dual-input models built from Trident's neural
|
|
34
|
+
network components.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install poseigen_mimic
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For local development, install from source using your preferred editable-install
|
|
43
|
+
workflow.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from poseigen_mimic import Mimic, Dual_Mimic
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Related Projects
|
|
52
|
+
|
|
53
|
+
- `poseigen_trident`: neural-network building blocks used by Mimic.
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
This project is released under the MIT License.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/poseigen_mimic.py
|
|
5
|
+
src/poseigen_mimic.egg-info/PKG-INFO
|
|
6
|
+
src/poseigen_mimic.egg-info/SOURCES.txt
|
|
7
|
+
src/poseigen_mimic.egg-info/dependency_links.txt
|
|
8
|
+
src/poseigen_mimic.egg-info/requires.txt
|
|
9
|
+
src/poseigen_mimic.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
poseigen_mimic
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"""Unified sequence-embedding architectures for the Poseigen suite."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
import torch
|
|
6
|
+
import torch.nn as nn
|
|
7
|
+
|
|
8
|
+
import poseigen_trident.prongs as tp
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Mimic(nn.Module):
|
|
12
|
+
"""Combines sequence embedding types into one architecture."""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
dim_i=(1, 249, 4),
|
|
17
|
+
dim_f=(1, 1, 1),
|
|
18
|
+
trunc=False,
|
|
19
|
+
kE_k=15,
|
|
20
|
+
kE_cf_m=100,
|
|
21
|
+
kE_ck_base=4,
|
|
22
|
+
kE_OneByOne=False,
|
|
23
|
+
kE_ck_grouped=False,
|
|
24
|
+
kE_freeze=False,
|
|
25
|
+
PR_cf_m=2,
|
|
26
|
+
PR_ck_base=5,
|
|
27
|
+
PR_pool_func=nn.AvgPool2d,
|
|
28
|
+
PR_pk_base=2,
|
|
29
|
+
PR_pk_s=2,
|
|
30
|
+
P_ck=50,
|
|
31
|
+
PR_layer=None,
|
|
32
|
+
PR_num_layers=1,
|
|
33
|
+
PR_bi=True,
|
|
34
|
+
O_mods=3,
|
|
35
|
+
O_cf_pu_m=1,
|
|
36
|
+
O_dropout=0.2,
|
|
37
|
+
cf_ns=1,
|
|
38
|
+
activations=nn.ReLU(),
|
|
39
|
+
activation_f=None,
|
|
40
|
+
batchnorm="before",
|
|
41
|
+
):
|
|
42
|
+
super(Mimic, self).__init__()
|
|
43
|
+
|
|
44
|
+
self.trunc = trunc
|
|
45
|
+
|
|
46
|
+
kE_cf_f = kE_cf_m * dim_i[0]
|
|
47
|
+
|
|
48
|
+
if (dim_i[1] - kE_k + 1) < dim_f[1]:
|
|
49
|
+
kE_k = dim_i[1] - dim_f[1] + 1
|
|
50
|
+
|
|
51
|
+
dim_i_ref = dim_i
|
|
52
|
+
dim_kE_width = 1
|
|
53
|
+
dim_kE_length = dim_i[1] - kE_k + 1
|
|
54
|
+
dim_kE = (kE_cf_f, dim_kE_length, dim_kE_width)
|
|
55
|
+
|
|
56
|
+
kE_Prong_args = {
|
|
57
|
+
"dim_i": dim_i_ref,
|
|
58
|
+
"dim_f": dim_kE,
|
|
59
|
+
"mods": 0,
|
|
60
|
+
"mods_ns": 0,
|
|
61
|
+
"cf_i": None,
|
|
62
|
+
"cf_ns": cf_ns,
|
|
63
|
+
"ck_base": kE_ck_base,
|
|
64
|
+
"doublestranded": False,
|
|
65
|
+
"OneByOne": kE_OneByOne,
|
|
66
|
+
"ck_grouped": kE_ck_grouped,
|
|
67
|
+
"activations": activations,
|
|
68
|
+
"activation_f": None,
|
|
69
|
+
"batchnorm": batchnorm,
|
|
70
|
+
"dropout": None,
|
|
71
|
+
"bias": True,
|
|
72
|
+
"out": False,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
self.kE = nn.Sequential(*tp.Prong_X(**kE_Prong_args))
|
|
76
|
+
|
|
77
|
+
if kE_freeze:
|
|
78
|
+
for param in self.kE.parameters():
|
|
79
|
+
param.requires_grad = False
|
|
80
|
+
|
|
81
|
+
P_func = PR_pool_func
|
|
82
|
+
|
|
83
|
+
if P_ck is None:
|
|
84
|
+
P_ck = 0
|
|
85
|
+
if P_ck == 0:
|
|
86
|
+
self.P, P_length = (nn.Identity(), dim_kE_length)
|
|
87
|
+
elif P_ck > 1:
|
|
88
|
+
pad2add = 0
|
|
89
|
+
self.P = P_func(
|
|
90
|
+
(P_ck, 1),
|
|
91
|
+
stride=(P_ck, 1),
|
|
92
|
+
padding=(pad2add, 0),
|
|
93
|
+
ceil_mode=True,
|
|
94
|
+
)
|
|
95
|
+
P_length = int(np.ceil(dim_kE_length / P_ck))
|
|
96
|
+
else:
|
|
97
|
+
self.P = P_func(
|
|
98
|
+
(dim_kE_length, 1),
|
|
99
|
+
stride=(1, 1),
|
|
100
|
+
padding=(0, 0),
|
|
101
|
+
ceil_mode=True,
|
|
102
|
+
)
|
|
103
|
+
P_length = 1
|
|
104
|
+
|
|
105
|
+
self.rnn = False
|
|
106
|
+
|
|
107
|
+
mid_f = int(PR_cf_m * dim_kE[0])
|
|
108
|
+
dim_mid = (mid_f, 1, 1)
|
|
109
|
+
|
|
110
|
+
if O_mods == 0:
|
|
111
|
+
self.PR = nn.Identity()
|
|
112
|
+
dim_mid = (dim_kE[0], P_length, 1)
|
|
113
|
+
mid_f = dim_kE[0]
|
|
114
|
+
|
|
115
|
+
elif PR_layer is None:
|
|
116
|
+
skip_first_conv = P_length == dim_kE[1]
|
|
117
|
+
dim_kE = (dim_kE[0], P_length, 1)
|
|
118
|
+
|
|
119
|
+
PR_args = {
|
|
120
|
+
"dim_i": dim_kE,
|
|
121
|
+
"dim_f": dim_mid,
|
|
122
|
+
"cf_ns": cf_ns,
|
|
123
|
+
"ck_i": None,
|
|
124
|
+
"skip_first_conv": skip_first_conv,
|
|
125
|
+
"ck_base": PR_ck_base,
|
|
126
|
+
"pk_base": PR_pk_base,
|
|
127
|
+
"pk_s": PR_pk_s,
|
|
128
|
+
"activations": activations,
|
|
129
|
+
"batchnorm": batchnorm,
|
|
130
|
+
}
|
|
131
|
+
self.PR = nn.Sequential(*tp.Prong_W(**PR_args))
|
|
132
|
+
|
|
133
|
+
elif PR_layer in [nn.GRU, nn.LSTM]:
|
|
134
|
+
self.rnn = True
|
|
135
|
+
hid_f = mid_f
|
|
136
|
+
if PR_bi:
|
|
137
|
+
hid_f = mid_f // 2
|
|
138
|
+
mid_f = hid_f * 2
|
|
139
|
+
dim_mid = (mid_f, 1, 1)
|
|
140
|
+
self.PR_bi = PR_bi
|
|
141
|
+
self.PR = PR_layer(
|
|
142
|
+
input_size=dim_kE[0],
|
|
143
|
+
hidden_size=int(hid_f),
|
|
144
|
+
num_layers=PR_num_layers,
|
|
145
|
+
bidirectional=PR_bi,
|
|
146
|
+
batch_first=True,
|
|
147
|
+
)
|
|
148
|
+
elif PR_layer in [nn.Conv2d]:
|
|
149
|
+
self.PR = nn.Conv2d(
|
|
150
|
+
dim_kE[0],
|
|
151
|
+
mid_f,
|
|
152
|
+
kernel_size=(P_length, 1),
|
|
153
|
+
bias=True,
|
|
154
|
+
stride=(1, 1),
|
|
155
|
+
padding=0,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
else:
|
|
159
|
+
dim_mid = (dim_kE[0], 1, 1)
|
|
160
|
+
self.PR = PR_layer(embed_dim=dim_kE[0])
|
|
161
|
+
mid_f = dim_kE[0]
|
|
162
|
+
|
|
163
|
+
if trunc:
|
|
164
|
+
self.O = nn.Identity()
|
|
165
|
+
else:
|
|
166
|
+
O_args = {
|
|
167
|
+
"dim_i": dim_mid,
|
|
168
|
+
"dim_f": dim_f,
|
|
169
|
+
"mods": O_mods,
|
|
170
|
+
"cf_ns": cf_ns,
|
|
171
|
+
"cf_pu": O_cf_pu_m * mid_f,
|
|
172
|
+
"activations": activations,
|
|
173
|
+
"activation_f": activation_f,
|
|
174
|
+
"batchnorm": batchnorm,
|
|
175
|
+
"dropout": O_dropout,
|
|
176
|
+
"out": True,
|
|
177
|
+
}
|
|
178
|
+
self.O = nn.Sequential(*tp.Prong_X(**O_args))
|
|
179
|
+
|
|
180
|
+
def forward(self, x):
|
|
181
|
+
x = self.kE(x)
|
|
182
|
+
x = self.P(x)
|
|
183
|
+
|
|
184
|
+
if self.rnn:
|
|
185
|
+
x = x.squeeze(-1)
|
|
186
|
+
x = x.permute(0, 2, 1)
|
|
187
|
+
|
|
188
|
+
rnn = self.PR
|
|
189
|
+
if isinstance(rnn, nn.LSTM):
|
|
190
|
+
_, (h_n, _) = rnn(x)
|
|
191
|
+
elif isinstance(rnn, nn.GRU):
|
|
192
|
+
_, h_n = rnn(x)
|
|
193
|
+
|
|
194
|
+
num_directions = 2 if self.PR_bi else 1
|
|
195
|
+
if num_directions == 1:
|
|
196
|
+
x = h_n[-1]
|
|
197
|
+
else:
|
|
198
|
+
x = torch.cat([h_n[-2], h_n[-1]], dim=1)
|
|
199
|
+
x = x.unsqueeze(-1).unsqueeze(-1)
|
|
200
|
+
else:
|
|
201
|
+
x = self.PR(x)
|
|
202
|
+
|
|
203
|
+
return self.O(x)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def Reset_Mimic(mimic):
|
|
207
|
+
lconvs, lprs, ldens = len(mimic.kE), len(mimic.PR), len(mimic.O)
|
|
208
|
+
|
|
209
|
+
for i in np.arange(lconvs):
|
|
210
|
+
if isinstance(mimic.kE[i], nn.Conv2d):
|
|
211
|
+
mimic.kE[i].reset_parameters()
|
|
212
|
+
|
|
213
|
+
if ldens > 1:
|
|
214
|
+
for i in np.arange(ldens):
|
|
215
|
+
if isinstance(mimic.O[i], nn.Conv2d):
|
|
216
|
+
mimic.O[i].reset_parameters()
|
|
217
|
+
|
|
218
|
+
if lprs > 1:
|
|
219
|
+
for i in np.arange(lprs):
|
|
220
|
+
if isinstance(mimic.PR[i], nn.Conv2d):
|
|
221
|
+
mimic.PR[i].reset_parameters()
|
|
222
|
+
elif lprs == 1:
|
|
223
|
+
mimic.PR.reset_parameters()
|
|
224
|
+
|
|
225
|
+
return mimic
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class Dual_Mimic(nn.Module):
|
|
229
|
+
def __init__(
|
|
230
|
+
self,
|
|
231
|
+
dim_f=(1, 1, 1),
|
|
232
|
+
late_comb=True,
|
|
233
|
+
A_dim_i=(1, 249, 4),
|
|
234
|
+
A_kE_k=15,
|
|
235
|
+
A_kE_cf_m=100,
|
|
236
|
+
A_kE_ck_base=4,
|
|
237
|
+
A_PR_ck_base=5,
|
|
238
|
+
A_PR_pk_base=2,
|
|
239
|
+
A_PR_pk_s=2,
|
|
240
|
+
A_P_ck=None,
|
|
241
|
+
B_dim_i=(1, 249, 4),
|
|
242
|
+
B_kE_k=15,
|
|
243
|
+
B_kE_cf_m=100,
|
|
244
|
+
B_kE_ck_base=4,
|
|
245
|
+
B_PR_ck_base=5,
|
|
246
|
+
B_PR_pk_base=2,
|
|
247
|
+
B_PR_pk_s=2,
|
|
248
|
+
B_P_ck=None,
|
|
249
|
+
PR_layer=None,
|
|
250
|
+
PR_num_layers=1,
|
|
251
|
+
PR_bi=True,
|
|
252
|
+
cf_ns=1,
|
|
253
|
+
kE_freeze=False,
|
|
254
|
+
kE_OneByOne=False,
|
|
255
|
+
PR_pool_func=nn.MaxPool2d,
|
|
256
|
+
PR_cf_m=2,
|
|
257
|
+
O_mods=3,
|
|
258
|
+
O_cf_pu_m=2,
|
|
259
|
+
O_dropout=0,
|
|
260
|
+
activations=nn.ReLU(),
|
|
261
|
+
activation_f=None,
|
|
262
|
+
batchnorm="before",
|
|
263
|
+
):
|
|
264
|
+
super(Dual_Mimic, self).__init__()
|
|
265
|
+
|
|
266
|
+
trunc = not late_comb
|
|
267
|
+
kE_ck_grouped = False
|
|
268
|
+
|
|
269
|
+
mimic_shared_args = {
|
|
270
|
+
"dim_f": dim_f,
|
|
271
|
+
"trunc": trunc,
|
|
272
|
+
"PR_layer": PR_layer,
|
|
273
|
+
"PR_num_layers": PR_num_layers,
|
|
274
|
+
"PR_bi": PR_bi,
|
|
275
|
+
"cf_ns": cf_ns,
|
|
276
|
+
"kE_freeze": kE_freeze,
|
|
277
|
+
"kE_ck_grouped": kE_ck_grouped,
|
|
278
|
+
"kE_OneByOne": kE_OneByOne,
|
|
279
|
+
"PR_pool_func": PR_pool_func,
|
|
280
|
+
"PR_cf_m": PR_cf_m,
|
|
281
|
+
"O_mods": O_mods,
|
|
282
|
+
"O_cf_pu_m": O_cf_pu_m,
|
|
283
|
+
"O_dropout": O_dropout,
|
|
284
|
+
"activations": activations,
|
|
285
|
+
"batchnorm": batchnorm,
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
mimic_A_args = {
|
|
289
|
+
"dim_i": A_dim_i,
|
|
290
|
+
"kE_k": A_kE_k,
|
|
291
|
+
"kE_cf_m": A_kE_cf_m,
|
|
292
|
+
"kE_ck_base": A_kE_ck_base,
|
|
293
|
+
"P_ck": A_P_ck,
|
|
294
|
+
"PR_ck_base": A_PR_ck_base,
|
|
295
|
+
"PR_pk_base": A_PR_pk_base,
|
|
296
|
+
"PR_pk_s": A_PR_pk_s,
|
|
297
|
+
**mimic_shared_args,
|
|
298
|
+
}
|
|
299
|
+
mimic_B_args = {
|
|
300
|
+
"dim_i": B_dim_i,
|
|
301
|
+
"kE_k": B_kE_k,
|
|
302
|
+
"kE_cf_m": B_kE_cf_m,
|
|
303
|
+
"kE_ck_base": B_kE_ck_base,
|
|
304
|
+
"P_ck": B_P_ck,
|
|
305
|
+
"PR_ck_base": B_PR_ck_base,
|
|
306
|
+
"PR_pk_base": B_PR_pk_base,
|
|
307
|
+
"PR_pk_s": B_PR_pk_s,
|
|
308
|
+
**mimic_shared_args,
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
self.late_comb = late_comb
|
|
312
|
+
|
|
313
|
+
if late_comb:
|
|
314
|
+
self.ultraA = Mimic(**mimic_A_args)
|
|
315
|
+
self.ultraB = Mimic(**mimic_B_args)
|
|
316
|
+
self.O = nn.Identity()
|
|
317
|
+
else:
|
|
318
|
+
self.ultraA = Mimic(**mimic_A_args)
|
|
319
|
+
self.ultraB = Mimic(**mimic_B_args)
|
|
320
|
+
|
|
321
|
+
if PR_layer is not None:
|
|
322
|
+
if PR_layer not in [nn.GRU, nn.LSTM, nn.Conv2d]:
|
|
323
|
+
PR_cf_m = 1
|
|
324
|
+
|
|
325
|
+
A_kE_f = A_kE_cf_m * A_dim_i[0]
|
|
326
|
+
A_mid_f = PR_cf_m * A_kE_f
|
|
327
|
+
|
|
328
|
+
B_kE_f = B_kE_cf_m * B_dim_i[0]
|
|
329
|
+
B_mid_f = PR_cf_m * B_kE_f
|
|
330
|
+
|
|
331
|
+
if PR_layer in [nn.GRU, nn.LSTM] and PR_bi:
|
|
332
|
+
hid_f = A_mid_f // 2
|
|
333
|
+
A_mid_f = hid_f * 2
|
|
334
|
+
|
|
335
|
+
hid_f = B_mid_f // 2
|
|
336
|
+
B_mid_f = hid_f * 2
|
|
337
|
+
|
|
338
|
+
AB_mid_f = int(A_mid_f + B_mid_f)
|
|
339
|
+
dim_mid = (AB_mid_f, 1, 1)
|
|
340
|
+
|
|
341
|
+
O_args = {
|
|
342
|
+
"dim_i": dim_mid,
|
|
343
|
+
"dim_f": dim_f,
|
|
344
|
+
"mods": O_mods,
|
|
345
|
+
"cf_ns": cf_ns,
|
|
346
|
+
"cf_pu": int(O_cf_pu_m * AB_mid_f),
|
|
347
|
+
"activations": activations,
|
|
348
|
+
"batchnorm": batchnorm,
|
|
349
|
+
"dropout": O_dropout,
|
|
350
|
+
"out": True,
|
|
351
|
+
}
|
|
352
|
+
self.O = nn.Sequential(*tp.Prong_X(**O_args))
|
|
353
|
+
|
|
354
|
+
self.FA = activation_f if activation_f is not None else nn.Identity()
|
|
355
|
+
|
|
356
|
+
def forward(self, x1, x2):
|
|
357
|
+
x1 = self.ultraA(x1)
|
|
358
|
+
x2 = self.ultraB(x2)
|
|
359
|
+
|
|
360
|
+
if self.late_comb:
|
|
361
|
+
xcomb = x1 + x2
|
|
362
|
+
else:
|
|
363
|
+
xcomb = torch.cat([x1, x2], dim=1)
|
|
364
|
+
|
|
365
|
+
xcomb = self.O(xcomb)
|
|
366
|
+
return self.FA(xcomb)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def Reset_Dual_Mimic(dual_mimic):
|
|
370
|
+
for mimic in [dual_mimic.ultraA, dual_mimic.ultraB]:
|
|
371
|
+
Reset_Mimic(mimic)
|
|
372
|
+
|
|
373
|
+
lex = len(dual_mimic.O)
|
|
374
|
+
|
|
375
|
+
if lex > 1:
|
|
376
|
+
for i in np.arange(lex):
|
|
377
|
+
if isinstance(dual_mimic.O[i], nn.Conv2d):
|
|
378
|
+
dual_mimic.O[i].reset_parameters()
|
|
379
|
+
|
|
380
|
+
print("done reset mod")
|
|
381
|
+
|
|
382
|
+
return dual_mimic
|