xttmp 2.3.0__py3-none-any.whl
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.
- xttmp/__init__.py +1 -0
- xttmp/api/__init__.py +5 -0
- xttmp/api/evaluate.py +163 -0
- xttmp/api/get_visualize_handle.py +29 -0
- xttmp/api/instancing_model.py +35 -0
- xttmp/core/__init__.py +0 -0
- xttmp/core/apgstmd_core.py +188 -0
- xttmp/core/apgstmdv2_core.py +79 -0
- xttmp/core/base_core.py +36 -0
- xttmp/core/dstmd_core.py +213 -0
- xttmp/core/estmd_backbone.py +110 -0
- xttmp/core/estmd_core.py +356 -0
- xttmp/core/feedbackstmd_core.py +61 -0
- xttmp/core/fracstmd_core.py +98 -0
- xttmp/core/fstmd_core.py +15 -0
- xttmp/core/fstmdv2_core.py +42 -0
- xttmp/core/haarstmd_core.py +140 -0
- xttmp/core/math_operator.py +307 -0
- xttmp/core/stfeedbackstmd_core.py +233 -0
- xttmp/core/stmdplus_core.py +187 -0
- xttmp/core/stmdplusv2_core.py +82 -0
- xttmp/core/vstmd_core.py +420 -0
- xttmp/demo/evaluate_model.py +92 -0
- xttmp/demo/inference_gui.py +148 -0
- xttmp/demo/inference_gui_single_process.py +134 -0
- xttmp/demo/inference_image_stream.py +67 -0
- xttmp/demo/inference_video.py +66 -0
- xttmp/main.py +14 -0
- xttmp/model/__init__.py +13 -0
- xttmp/model/backbone.py +514 -0
- xttmp/model/facilitated_model.py +230 -0
- xttmp/model/feedback_model.py +271 -0
- xttmp/model/haarstmd.py +61 -0
- xttmp/model/vstmd.py +457 -0
- xttmp/util/__init__.py +0 -0
- xttmp/util/compute_module.py +402 -0
- xttmp/util/create_kernel.py +363 -0
- xttmp/util/evaluate_module.py +697 -0
- xttmp/util/iostream.py +660 -0
- xttmp-2.3.0.dist-info/METADATA +85 -0
- xttmp-2.3.0.dist-info/RECORD +45 -0
- xttmp-2.3.0.dist-info/WHEEL +5 -0
- xttmp-2.3.0.dist-info/entry_points.txt +2 -0
- xttmp-2.3.0.dist-info/licenses/LICENSE +201 -0
- xttmp-2.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from .backbone import DSTMDBackbone
|
|
4
|
+
from ..core import stmdplus_core, apgstmd_core
|
|
5
|
+
from ..util.compute_module import compute_response, compute_direction
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class STMDPlus(DSTMDBackbone):
|
|
9
|
+
""" STMDPlus: A facilitated model based on DSTMD with an additional contrast pathway.
|
|
10
|
+
|
|
11
|
+
Ref:
|
|
12
|
+
* Wang H, Peng J, Zheng X, et al. "A robust visual system for small target motion detection against cluttered moving backgrounds." IEEE Transactions on Neural Networks and Learning Systems, 2019, 31(3): 839-853.
|
|
13
|
+
|
|
14
|
+
Description:
|
|
15
|
+
The STMDPlus model builds upon the DSTMD architecture, enhancing target detection accuracy in cluttered moving backgrounds by introducing a contrast pathway. This pathway provides a complementary processing mechanism to improve robustness against dynamic noise and varying background contrasts. The model parameters align with those specified in the reference.
|
|
16
|
+
|
|
17
|
+
Parameters:
|
|
18
|
+
Retina:
|
|
19
|
+
- sigma1: Controls the standard deviation for Gaussian blur applied in the retina layer, reducing noise and emphasizing potential targets. (Eq. 1)
|
|
20
|
+
|
|
21
|
+
Lamina:
|
|
22
|
+
- n1, tau1: Order and time constant of the first gamma bandpass filter in the lamina. (Eq. 3)
|
|
23
|
+
- n2, tau2: Order and time constant of the second gamma bandpass filter.
|
|
24
|
+
|
|
25
|
+
Medulla:
|
|
26
|
+
- n3, tau3: Order and time constant of gamma delay in the Mi1 pathway. (Eq. 11)
|
|
27
|
+
- n4, tau4: Order and time constant of gamma delay in the Tm1 pathway. (Eq. 11)
|
|
28
|
+
- n5, tau5: Order and time constant for another gamma delay variant in the Tm1 pathway. (Eq. 11)
|
|
29
|
+
|
|
30
|
+
Lobula:
|
|
31
|
+
- alpha1: Parameter modulating signal strength for the lobula, contributing to directional selectivity. (Eq. 10)
|
|
32
|
+
- A, B: Lateral inhibition coefficients. (Eq. 13)
|
|
33
|
+
- e, rho, sigma4, sigma5: Lateral inhibition coefficients. (Eq. 14)
|
|
34
|
+
|
|
35
|
+
Contrast Pathway:
|
|
36
|
+
- eta: Parameter adjusting the contrast pathway’s influence. (Eq. 15)
|
|
37
|
+
- alpha2: Signal modulation factor within the contrast pathway. (Eq. 17)
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# Bind model parameters and their corresponding parameter pointers.
|
|
42
|
+
__paraMappingList = {
|
|
43
|
+
# retina
|
|
44
|
+
'sigma1' : 'retina.sigma', # Eq. (1)
|
|
45
|
+
# lamina
|
|
46
|
+
'n1' : 'lamina.order1', # Eq. (3)
|
|
47
|
+
'tau1' : 'lamina.tau1',
|
|
48
|
+
'n2' : 'lamina.order2',
|
|
49
|
+
'tau2' : 'lamina.tau2',
|
|
50
|
+
# medulla
|
|
51
|
+
'n3' : 'medulla.mi1_para4.order', # Eq. (11)
|
|
52
|
+
'tau3' : 'medulla.mi1_para4.tau',
|
|
53
|
+
'n4' : 'medulla.tm1_para5.order',
|
|
54
|
+
'tau4' : 'medulla.tm1_para5.tau',
|
|
55
|
+
'n5' : 'medulla.tm1_para6.order',
|
|
56
|
+
'tau5' : 'medulla.tm1_para6.tau',
|
|
57
|
+
# lobula
|
|
58
|
+
'alpha1' : 'lobula.alpha1', # Eq. (10)
|
|
59
|
+
'A' : 'lobula.hLateralInhi.A', # Eq. (13)
|
|
60
|
+
'B' : 'lobula.hLateralInhi.B',
|
|
61
|
+
'e' : 'lobula.hLateralInhi.e', # Eq. (14)
|
|
62
|
+
'rho' : 'lobula.hLateralInhi.rho',
|
|
63
|
+
'sigma4' : 'lobula.hLateralInhi.sigma1',
|
|
64
|
+
'sigma5' : 'lobula.hLateralInhi.sigma2',
|
|
65
|
+
# Contrast pathway
|
|
66
|
+
'eta' : 'contrast_pathway.eta', # Eq. (15)
|
|
67
|
+
'alpha2' : 'contrast_pathway.alpha2', # Eq. (17)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
def __init__(self):
|
|
71
|
+
""" Constructor method """
|
|
72
|
+
super().__init__()
|
|
73
|
+
|
|
74
|
+
# Initialize contrast pathway and mushroom body components
|
|
75
|
+
self.contrast_pathway = stmdplus_core.ContrastPathway()
|
|
76
|
+
self.mushroom_body = stmdplus_core.MushroomBody()
|
|
77
|
+
|
|
78
|
+
def forward(self, iptMatrix):
|
|
79
|
+
""" Defines the structure of the STMDPlus model. """
|
|
80
|
+
|
|
81
|
+
# A. Ommatidia (Retina)
|
|
82
|
+
retina_output = self.retina.forward(iptMatrix)
|
|
83
|
+
|
|
84
|
+
# B. Motion Pathway (Lamina, Medulla, Lobula)
|
|
85
|
+
lamina_output = self.lamina.forward(retina_output)
|
|
86
|
+
medulla_tm3_output, medulla_mi1_p4_output, medulla_tm1_p5_output, medulla_tm1_p6_output = \
|
|
87
|
+
self.medulla.forward(lamina_output)
|
|
88
|
+
lobula_output = self.lobula.forward(medulla_tm3_output, medulla_mi1_p4_output,
|
|
89
|
+
medulla_tm1_p5_output, medulla_tm1_p6_output)
|
|
90
|
+
|
|
91
|
+
# C. Contrast Pathway
|
|
92
|
+
contrast_output = self.contrast_pathway.forward(retina_output)
|
|
93
|
+
|
|
94
|
+
# D. Mushroom Body
|
|
95
|
+
mushroom_body_output = self.mushroom_body.forward(
|
|
96
|
+
lobula_output, contrast_output)
|
|
97
|
+
|
|
98
|
+
# Compute response and direction
|
|
99
|
+
self.model_output['response'] = compute_response(mushroom_body_output)
|
|
100
|
+
self.model_output['direction'] = compute_direction(mushroom_body_output)
|
|
101
|
+
|
|
102
|
+
return self.model_output
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class ApgSTMD(STMDPlus):
|
|
106
|
+
""" ApgSTMD: Attention-Prediction-guided Small Target Motion Detector
|
|
107
|
+
|
|
108
|
+
Ref:
|
|
109
|
+
* Wang H, Zhao J, Wang H, et al. Attention and prediction-guided motion detection for low-contrast small moving targets[J]. IEEE Transactions on Cybernetics, 2022, 53(10): 6340-6352.
|
|
110
|
+
|
|
111
|
+
Description:
|
|
112
|
+
The ApgSTMD model extends the STMDPlus model by introducing attention and prediction pathways to improve target detection.
|
|
113
|
+
|
|
114
|
+
Parameters:
|
|
115
|
+
Retina:
|
|
116
|
+
- sigma1: Standard deviation of the Gaussian blur applied in the retina layer to pre-forward input images by smoothing, reducing background noise. (Eq. 2)
|
|
117
|
+
|
|
118
|
+
Lamina:
|
|
119
|
+
- n1, tau1: Order and time constant of the first gamma bandpass filter in the lamina. (Eq. 6)
|
|
120
|
+
- n2, tau2: Order and time constant of the second gamma bandpass filter. (Eq. 6)
|
|
121
|
+
|
|
122
|
+
Medulla:
|
|
123
|
+
- n3, tau3: Order and time constant in the Mi1 pathway. (Eq. 14)
|
|
124
|
+
- n4, tau4: Order and time constant in the Tm1 pathway. (Eq. 14)
|
|
125
|
+
- n5, tau5: Additional delay component in Tm1. (Eq. 14)
|
|
126
|
+
|
|
127
|
+
Lobula:
|
|
128
|
+
- gamma: Signal modulation parameter in the lobula, aiding in selective attention towards targets by enhancing certain spatial patterns. (Eq. 13)
|
|
129
|
+
- A, B: Coefficients for lateral inhibition, reducing background clutter through inhibition of surrounding non-target signals. (Eq. 15)
|
|
130
|
+
- e, rho, sigma4, sigma5: Parameters controlling non-linear inhibition effects. (Eq. 16)
|
|
131
|
+
|
|
132
|
+
Attention Pathway:
|
|
133
|
+
- eta_list: A list of attentional weights adjusting model responsiveness to spatial regions with potential target information. (Eq. 3)
|
|
134
|
+
- theta_list: (Eq. 3)
|
|
135
|
+
|
|
136
|
+
Prediction Pathway:
|
|
137
|
+
- zeta, eta: Parameters for prediction kernels. (Eq. 20)
|
|
138
|
+
- kappa: Parameter adjusting the weighting for predicted versus observed signals, balancing real-time data with anticipated target trajectories. (Eq. 23)
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
# Bind model parameters and their corresponding parameter pointers.
|
|
142
|
+
__paraMappingList = {
|
|
143
|
+
# retina
|
|
144
|
+
'sigma1' : 'retina.sigma', # Eq. (2)
|
|
145
|
+
# lamina
|
|
146
|
+
'n1' : 'lamina.order1', # Eq. (6)
|
|
147
|
+
'tau1' : 'lamina.tau1',
|
|
148
|
+
'n2' : 'lamina.order2',
|
|
149
|
+
'tau2' : 'lamina.tau2',
|
|
150
|
+
# medulla
|
|
151
|
+
'n3' : 'medulla.mi1_para4.order', # Eq. (14)
|
|
152
|
+
'tau3' : 'medulla.mi1_para4.tau',
|
|
153
|
+
'n4' : 'medulla.tm1_para5.order',
|
|
154
|
+
'tau4' : 'medulla.tm1_para5.tau',
|
|
155
|
+
'n5' : 'medulla.tm1_para6.order',
|
|
156
|
+
'tau5' : 'medulla.tm1_para6.tau',
|
|
157
|
+
# lobula
|
|
158
|
+
'gamma' : 'lobula.alpha1', # Eq. (13)
|
|
159
|
+
'A' : 'lobula.hLateralInhi.A', # Eq. (15)
|
|
160
|
+
'B' : 'lobula.hLateralInhi.B',
|
|
161
|
+
'e' : 'lobula.hLateralInhi.e', # Eq. (16)
|
|
162
|
+
'rho' : 'lobula.hLateralInhi.rho',
|
|
163
|
+
'sigma4' : 'lobula.hLateralInhi.sigma1',
|
|
164
|
+
'sigma5' : 'lobula.hLateralInhi.sigma2',
|
|
165
|
+
# Attention Pathway
|
|
166
|
+
'zeta_list' : 'attention_pathway.zeta_list', # Eq. (3)
|
|
167
|
+
'theta_list': 'attention_pathway.theta_list',
|
|
168
|
+
# Prediction Pathway
|
|
169
|
+
'zeta' : 'prediction_pathway.zeta', # Eq. (20)
|
|
170
|
+
'eta' : 'prediction_pathway.eta', # Eq. (20)
|
|
171
|
+
'kappa' : 'prediction_pathway.kappa', # Eq. (23)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
def __init__(self):
|
|
175
|
+
"""
|
|
176
|
+
Constructor method
|
|
177
|
+
"""
|
|
178
|
+
super().__init__()
|
|
179
|
+
|
|
180
|
+
# Initialize attention pathway and prediction pathway components
|
|
181
|
+
self.attention_pathway = apgstmd_core.AttentionModule()
|
|
182
|
+
self.prediction_pathway = apgstmd_core.PredictionModule()
|
|
183
|
+
|
|
184
|
+
# Set properties of Lobula's LateralInhibition module
|
|
185
|
+
self.lobula.hLateralInhi.B = 3.5
|
|
186
|
+
self.lobula.hLateralInhi.sigma1 = 1.25
|
|
187
|
+
self.lobula.hLateralInhi.sigma2 = 2.5
|
|
188
|
+
self.lobula.hLateralInhi.e = 1.2
|
|
189
|
+
|
|
190
|
+
self.predictionMap = None
|
|
191
|
+
|
|
192
|
+
def forward(self, x):
|
|
193
|
+
""" Defines the structure of the ApgSTMD model. """
|
|
194
|
+
|
|
195
|
+
# Preprocessing Module
|
|
196
|
+
retina_output = self.retina(x)
|
|
197
|
+
|
|
198
|
+
# Attention Module
|
|
199
|
+
attention_output = self.attention_pathway(
|
|
200
|
+
retina_output, self.predictionMap)
|
|
201
|
+
|
|
202
|
+
# STMD-based Neural Network
|
|
203
|
+
lamina_output = self.lamina(attention_output)
|
|
204
|
+
medulla_tm3_output, medulla_mi1_p4_output, medulla_tm1_p5_output, medulla_tm1_p6_output = \
|
|
205
|
+
self.medulla(lamina_output)
|
|
206
|
+
|
|
207
|
+
lobula_output = self.lobula(medulla_tm3_output, medulla_mi1_p4_output,
|
|
208
|
+
medulla_tm1_p5_output, medulla_tm1_p6_output)
|
|
209
|
+
|
|
210
|
+
# STMDPlus
|
|
211
|
+
contrast_output = self.contrast_pathway(retina_output)
|
|
212
|
+
mushroom_body_output = self.mushroom_body(
|
|
213
|
+
lobula_output, contrast_output)
|
|
214
|
+
|
|
215
|
+
# Prediction Module
|
|
216
|
+
# prediction_output is the facilitated STMD output Q(x; y; t; theta) in Eq. (23)
|
|
217
|
+
prediction_output, self.predictionMap = self.prediction_pathway(mushroom_body_output)
|
|
218
|
+
|
|
219
|
+
# Compute response and direction
|
|
220
|
+
self.model_output['response'] = compute_response(prediction_output)
|
|
221
|
+
self.model_output['direction'] = compute_direction(prediction_output)
|
|
222
|
+
|
|
223
|
+
return self.model_output
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
from copy import deepcopy
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
|
|
5
|
+
from .backbone import ESTMDBackbone, FracSTMD
|
|
6
|
+
from ..core import feedbackstmd_core, fstmd_core, stfeedbackstmd_core
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FeedbackSTMD(ESTMDBackbone):
|
|
10
|
+
""" FeedbackSTMD: Small Target Motion Detector with feedback pathway in lobula
|
|
11
|
+
|
|
12
|
+
Ref:
|
|
13
|
+
* Wang H, Wang H, Zhao J, et al. A time-delay feedback neural network for discriminating small, fast-moving targets in complex dynamic environments[J]. IEEE Transactions on Neural Networks and Learning Systems, 2021, 34(1): 316-330.
|
|
14
|
+
|
|
15
|
+
Description:
|
|
16
|
+
The FeedbackSTMD model is an enhancement of the ESTMD backbone with a feedback pathway integrated in the lobula.
|
|
17
|
+
|
|
18
|
+
Parameters:
|
|
19
|
+
Retina:
|
|
20
|
+
- sigma1: Standard deviation of the Gaussian blur in the retina. (Eq. 2)
|
|
21
|
+
|
|
22
|
+
Lamina:
|
|
23
|
+
- n1, tau1: Order and time constant for the first gamma bandpass filter in the lamina. (Eq. 3)
|
|
24
|
+
- n2, tau2: Order and time constant for the second gamma filter.
|
|
25
|
+
|
|
26
|
+
Medulla:
|
|
27
|
+
- n3, tau3: Tuple containing orders and time constants for Tm1 and Mi1 pathways, both crucial in delaying signals to provide temporal integration for motion detection. (Eq. 7)
|
|
28
|
+
|
|
29
|
+
Lobula:
|
|
30
|
+
- alpha: Feedback constant in the lobula. (Eq. 9)
|
|
31
|
+
- n4, tau4: Order and time constant in the lobula’s gamma delay, supporting time-delay feedback that strengthens temporal coherence in target tracking.
|
|
32
|
+
- eta: Parameter in the Gaussian kernel. (Eq. 10)
|
|
33
|
+
- A, B: Lateral inhibition coefficients. (Eq. 15)
|
|
34
|
+
- e, rho, sigma2, sigma3: Parameters that modulate nonlinear inhibition. (Eq. 16)
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
# Bind model parameters and their corresponding parameter pointers.
|
|
38
|
+
__paraMappingList = {
|
|
39
|
+
# retina
|
|
40
|
+
'sigma1' : 'retina.sigma', # Eq. (2)
|
|
41
|
+
# lamina
|
|
42
|
+
'n1' : 'lamina.order1', # Eq. (3)
|
|
43
|
+
'tau1' : 'lamina.tau1',
|
|
44
|
+
'n2' : 'lamina.order1',
|
|
45
|
+
'tau2' : 'lamina.tau1',
|
|
46
|
+
# medulla
|
|
47
|
+
'n3' : ('medulla.tm1.order', 'medulla.mi1.order'), # Eq. (7)
|
|
48
|
+
'tau3' : ('medulla.tm1.tau', 'medulla.mi1.tau'),
|
|
49
|
+
# lobula
|
|
50
|
+
'alpha' : 'lobula.alpha', # Eq. (9)
|
|
51
|
+
'n4' : 'lobula.gamma_delay.order',
|
|
52
|
+
'tau4' : 'lobula.gamma_delay.tau',
|
|
53
|
+
'eta' : 'lobula.sigma', # Eq. (10)
|
|
54
|
+
'A' : 'lobula.spatial_inhibition.A', # Eq. (15)
|
|
55
|
+
'B' : 'lobula.spatial_inhibition.B',
|
|
56
|
+
'e' : 'lobula.spatial_inhibition.e', # Eq. (16)
|
|
57
|
+
'rho' : 'lobula.spatial_inhibition.rho',
|
|
58
|
+
'sigma2' : 'lobula.spatial_inhibition.sigma1',
|
|
59
|
+
'sigma3' : 'lobula.spatial_inhibition.sigma2',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
def __init__(self):
|
|
63
|
+
"""
|
|
64
|
+
FeedbackSTMD Constructor method
|
|
65
|
+
Initializes an instance of the FeedbackSTMD class.
|
|
66
|
+
"""
|
|
67
|
+
# Call superclass constructor
|
|
68
|
+
super().__init__()
|
|
69
|
+
|
|
70
|
+
# Customize Lobula component
|
|
71
|
+
self.lobula = feedbackstmd_core.Lobula()
|
|
72
|
+
|
|
73
|
+
# Customize Lamina's GammaBankPassFilter properties
|
|
74
|
+
self.lamina.order1 = 4
|
|
75
|
+
self.lamina.tau1 = 8
|
|
76
|
+
self.lamina.order2 = 16
|
|
77
|
+
self.lamina.tau2 = 32
|
|
78
|
+
|
|
79
|
+
# Customize Medulla's Tm1 component properties
|
|
80
|
+
self.medulla.tm1.order = 9
|
|
81
|
+
self.medulla.tm1.tau = 45
|
|
82
|
+
|
|
83
|
+
def forward(self, x):
|
|
84
|
+
""" MODEL_STRUCTURE Method
|
|
85
|
+
|
|
86
|
+
Defines the structure of the FeedbackSTMD model.
|
|
87
|
+
"""
|
|
88
|
+
# Process input matrix through model components
|
|
89
|
+
retina_output = self.retina(x)
|
|
90
|
+
lamina_output = self.lamina(retina_output)
|
|
91
|
+
medulla_ON, medulla_OFF = self.medulla(lamina_output)
|
|
92
|
+
self.model_output['response'] = self.lobula(medulla_ON, medulla_OFF)
|
|
93
|
+
|
|
94
|
+
return self.model_output
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class FSTMD(ESTMDBackbone):
|
|
98
|
+
""" FSTMD: Small Target Motion Detector with feedback loop between lobula and lamina
|
|
99
|
+
|
|
100
|
+
Ref:
|
|
101
|
+
* Ling J, Wang H, Xu M, et al. Mathematical study of neural feedback roles in small target motion detection[J]. Frontiers in Neurorobotics, 2022, 16: 984430.
|
|
102
|
+
|
|
103
|
+
Description:
|
|
104
|
+
The FSTMD model introduces a feedback loop between the lobula and lamina layers.
|
|
105
|
+
|
|
106
|
+
Parameters:
|
|
107
|
+
Retina:
|
|
108
|
+
- sigma1: Standard deviation of the Gaussian blur in the retina, pre-processing the visual input by smoothing noise and high-frequency signals. (Eq. 1)
|
|
109
|
+
|
|
110
|
+
Lamina:
|
|
111
|
+
- n1, tau1: Order and time constant for the first gamma bandpass filter in the lamina. (Eq. 6)
|
|
112
|
+
- n2, tau2: Order and time constant for the second gamma filter.
|
|
113
|
+
|
|
114
|
+
Medulla:
|
|
115
|
+
- n3, tau3: Tuple containing the order and time constants for the gamma delay functions in Tm1 and Mi1 pathways, which provide temporal integration critical for target motion analysis. (Eq. 9)
|
|
116
|
+
|
|
117
|
+
Lobula:
|
|
118
|
+
- e, rho, sigma2, sigma3: Parameter controlling the strength of lateral inhibition in the lobula. (Eq. 13)
|
|
119
|
+
|
|
120
|
+
Feedback Pathway:
|
|
121
|
+
- n4, tau4: Order and time constant for the gamma delay in the feedback pathway, adjusting temporal coherence to align with the dynamics of target motion. (Eq. 4)
|
|
122
|
+
- a: Feedback constant, regulating the strength of the feedback signal from the lobula to the lamina, balancing sensitivity and stability in target detection by dynamically adjusting the lamina’s response to target motion. (Eq. 4)
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
# Bind model parameters and their corresponding parameter pointers.
|
|
126
|
+
__paraMappingList = {
|
|
127
|
+
# retina
|
|
128
|
+
'sigma1' : 'retina.sigma', # Eq. (1)
|
|
129
|
+
# lamina
|
|
130
|
+
'n1' : 'lamina.order1', # Eq. (6)
|
|
131
|
+
'tau1' : 'lamina.tau1',
|
|
132
|
+
'n2' : 'lamina.order2',
|
|
133
|
+
'tau2' : 'lamina.tau2',
|
|
134
|
+
# medulla
|
|
135
|
+
'n3' : ('medulla.tm1.order', 'medulla.mi1.order'), # Eq. (9)
|
|
136
|
+
'tau3' : ('medulla.tm1.tau', 'medulla.mi1.tau'),
|
|
137
|
+
# lobula
|
|
138
|
+
'e' : 'lobula.spatial_inhibition.e', # Eq. (13)
|
|
139
|
+
'rho' : 'lobula.spatial_inhibition.rho',
|
|
140
|
+
'sigma2' : 'lobula.spatial_inhibition.sigma1',
|
|
141
|
+
'sigma3' : 'lobula.spatial_inhibition.sigma2',
|
|
142
|
+
# feedback pathway
|
|
143
|
+
'n4' : 'feedback_pathway.order', # Eq. (4)
|
|
144
|
+
'tau4' : 'feedback_pathway.tau',
|
|
145
|
+
'a' : 'feedback_pathway.feedback_coefficient', # Eq. (4)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
def __init__(self):
|
|
149
|
+
""" FSTMD Constructor method
|
|
150
|
+
|
|
151
|
+
Initializes an instance of the FSTMD class.
|
|
152
|
+
"""
|
|
153
|
+
# Call superclass constructor
|
|
154
|
+
super().__init__()
|
|
155
|
+
|
|
156
|
+
# Initialize feedback pathway component
|
|
157
|
+
self.feedback_pathway = fstmd_core.FeedbackPathway()
|
|
158
|
+
|
|
159
|
+
self.maxIterationNum = 10
|
|
160
|
+
self.iterationThreshold = 1e-3
|
|
161
|
+
|
|
162
|
+
# Customize Medulla's Tm1 component properties
|
|
163
|
+
self.medulla.tm1.order = 5
|
|
164
|
+
|
|
165
|
+
def forward(self, x):
|
|
166
|
+
""" MODEL_STRUCTURE Method
|
|
167
|
+
|
|
168
|
+
Defines the structure of the FSTMD model.
|
|
169
|
+
"""
|
|
170
|
+
last_feedback_output = torch.ones_like(x)
|
|
171
|
+
self.feedback_output = torch.zeros_like(x)
|
|
172
|
+
|
|
173
|
+
# Retina layer
|
|
174
|
+
retina_output = self.retina(x)
|
|
175
|
+
|
|
176
|
+
# Feedback loop
|
|
177
|
+
iteration_count = 1
|
|
178
|
+
self.set_loop_state(False)
|
|
179
|
+
while iteration_count < self.maxIterationNum and torch.max(
|
|
180
|
+
torch.abs(self.feedback_output - last_feedback_output)) > self.iterationThreshold:
|
|
181
|
+
last_feedback_output = self.feedback_output.clone()
|
|
182
|
+
|
|
183
|
+
# Execute feedback loop
|
|
184
|
+
lamina_output = self.lamina(retina_output + self.feedback_output)
|
|
185
|
+
medulla_ON, medulla_OFF = self.medulla(lamina_output)
|
|
186
|
+
lobula_output, correlation_output = self.lobula(medulla_ON, medulla_OFF)
|
|
187
|
+
self.feedback_output = self.feedback_pathway(correlation_output)
|
|
188
|
+
|
|
189
|
+
iteration_count += 1
|
|
190
|
+
self.set_loop_state(True)
|
|
191
|
+
|
|
192
|
+
# Set model response
|
|
193
|
+
self.model_output['response'] = lobula_output
|
|
194
|
+
|
|
195
|
+
return self.model_output
|
|
196
|
+
|
|
197
|
+
def set_loop_state(self, state):
|
|
198
|
+
""" Sets the loop state of certain components. """
|
|
199
|
+
# Disable circshift for certain components
|
|
200
|
+
self.lamina.in_loop = state
|
|
201
|
+
self.medulla.tm1.in_loop = state
|
|
202
|
+
self.feedback_pathway.in_loop = state
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class STFeedbackSTMD(ESTMDBackbone):
|
|
206
|
+
""" STFeedbackSTMD - Small Target Motion Detection With Spatio-Temporal Feedback
|
|
207
|
+
|
|
208
|
+
# !!! Notice: This model has not been reproduced yet
|
|
209
|
+
|
|
210
|
+
Ref:
|
|
211
|
+
[1] Wang H, Zhong Z, Lei F, et al. Bio-Inspired Small Target Motion Detection With Spatio-Temporal Feedback in Natural Scenes[J]. IEEE Transactions on Image Processing, 2023.
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
"""
|
|
215
|
+
|
|
216
|
+
# Bind model parameters and their corresponding parameter pointers.
|
|
217
|
+
__paraMappingList = {}
|
|
218
|
+
|
|
219
|
+
def __init__(self):
|
|
220
|
+
"""
|
|
221
|
+
Constructor method
|
|
222
|
+
"""
|
|
223
|
+
super().__init__()
|
|
224
|
+
|
|
225
|
+
# Customize Medulla and Lobula component
|
|
226
|
+
self.medulla = stfeedbackstmd_core.Medulla()
|
|
227
|
+
self.lobula = stfeedbackstmd_core.Lobula()
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class FracSTMD_F(FracSTMD):
|
|
231
|
+
|
|
232
|
+
# Bind model parameters and their corresponding parameter pointers.
|
|
233
|
+
__paraMappingList = deepcopy(FracSTMD._FracSTMD__paraMappingList)
|
|
234
|
+
__paraMappingList.update({
|
|
235
|
+
# lobula
|
|
236
|
+
'beta' : 'lobula.alpha', # Eq. (9)
|
|
237
|
+
'n4' : 'lobula.hGammaDelay.order',
|
|
238
|
+
'tau4' : 'lobula.hGammaDelay.tau',
|
|
239
|
+
'eta' : 'lobula.paraGaussKernel[\'eta\']', # Eq. (10)
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
def __init__(self):
|
|
243
|
+
"""
|
|
244
|
+
Constructor method
|
|
245
|
+
"""
|
|
246
|
+
super().__init__()
|
|
247
|
+
|
|
248
|
+
# Customize Lamina component to include fractional differentiation
|
|
249
|
+
self.lobula = feedbackstmd_core.Lobula()
|
|
250
|
+
|
|
251
|
+
def forward(self, iptMatrix):
|
|
252
|
+
""" MODEL_STRUCTURE Method
|
|
253
|
+
|
|
254
|
+
Defines the structure of the FeedbackSTMD model.
|
|
255
|
+
"""
|
|
256
|
+
# Process input matrix through model components
|
|
257
|
+
self.retinaOpt = self.retina.forward(iptMatrix)
|
|
258
|
+
lamina_output = self.lamina.forward(self.retinaOpt)
|
|
259
|
+
self.medulla.forward(lamina_output)
|
|
260
|
+
self.medullaOpt = self.medulla.Opt
|
|
261
|
+
lobula_output = self.lobula.forward(self.medullaOpt[0], self.medullaOpt[1])
|
|
262
|
+
|
|
263
|
+
# Set model response
|
|
264
|
+
self.model_output['response'] = lobula_output
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
xttmp/model/haarstmd.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from ..core import haarstmd_core
|
|
4
|
+
from .backbone import ESTMDBackbone
|
|
5
|
+
from ..util.compute_module import compute_response, compute_direction
|
|
6
|
+
|
|
7
|
+
class HaarSTMD(ESTMDBackbone):
|
|
8
|
+
''' HaarSTMD: Advancing small target motion detection in dim light
|
|
9
|
+
|
|
10
|
+
Ref:
|
|
11
|
+
[1] Chen H, Sun X, Hu C, et al. Unveiling the power of Haar frequency domain: Advancing small target motion detection in dim light[J]. Applied Soft Computing, 2024, 167: 112281.
|
|
12
|
+
'''
|
|
13
|
+
|
|
14
|
+
# Bind model parameters and their corresponding parameter pointers.
|
|
15
|
+
__paraMappingList = {
|
|
16
|
+
'sigma1' : 'retina.sigma',
|
|
17
|
+
'n1' : 'lamina.order1',
|
|
18
|
+
'tau1' : 'lamina.tau1',
|
|
19
|
+
'n2' : 'lamina.order2',
|
|
20
|
+
'tau2' : 'lamina.tau2',
|
|
21
|
+
'a' : 'medulla.temporal_kernel_len',
|
|
22
|
+
'r' : 'medulla.spatial_kernel_size',
|
|
23
|
+
'n3' : 'medulla.delay_on.order',
|
|
24
|
+
'tau3' : 'medulla.delay_on.tau',
|
|
25
|
+
'n4' : 'medulla.delay_off.order',
|
|
26
|
+
'tau4' : 'medulla.delay_off.tau',
|
|
27
|
+
'sigma2' : 'lobula.spatial_inhibition.sigma1',
|
|
28
|
+
'sigma3' : 'lobula.spatial_inhibition.sigma2',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def __init__(self):
|
|
32
|
+
''' Constructor method '''
|
|
33
|
+
super().__init__()
|
|
34
|
+
|
|
35
|
+
self.medulla = haarstmd_core.Medulla()
|
|
36
|
+
self.lobula = haarstmd_core.Lobula()
|
|
37
|
+
|
|
38
|
+
# init parameter
|
|
39
|
+
self.retina.sigma = 1
|
|
40
|
+
self.lamina.order1 = 10
|
|
41
|
+
self.lamina.tau1 = 3
|
|
42
|
+
self.lamina.order2 = 10
|
|
43
|
+
self.lamina.tau2 = 9
|
|
44
|
+
self.lobula.spatial_inhibition.sigma1 = 1.5
|
|
45
|
+
self.lobula.spatial_inhibition.sigma2 = 3
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def forward(self, x):
|
|
49
|
+
|
|
50
|
+
retina_output = self.retina(x)
|
|
51
|
+
lamina_output = self.lamina(retina_output)
|
|
52
|
+
correlated_spatial_output, correlated_temporal_output = self.medulla(lamina_output)
|
|
53
|
+
lobula_output = self.lobula(correlated_spatial_output,
|
|
54
|
+
correlated_temporal_output)
|
|
55
|
+
|
|
56
|
+
self.model_output['response'] = compute_response(lobula_output)
|
|
57
|
+
self.model_output['direction'] = compute_direction(lobula_output)
|
|
58
|
+
|
|
59
|
+
return self.model_output
|
|
60
|
+
|
|
61
|
+
|