-
Notifications
You must be signed in to change notification settings - Fork 3
/
regressor.py
54 lines (42 loc) · 1.09 KB
/
regressor.py
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
#
#Copyright (C) 2023 ISTI-CNR
#Licensed under the BSD 3-Clause Clear License (see license.txt)
#
import torch
import torch.nn as nn
#
#
#
class Regressor(nn.Module):
#
#
#
def __init__(self, in_size=1, out_size=1, params_size = None):
super(Regressor, self).__init__()
if params_size == None:
params_size = 0
self.params_size = params_size
self.regressor = nn.Sequential(
nn.Linear(in_size + params_size, 256),
nn.ReLU(),
nn.Linear(256, out_size),
nn.Sigmoid()
)
#
#
#
def forward(self, features, params = None):
if len(features.shape) == 4:
features = features.mean(-1).mean(-1)
if (self.params_size != 0) and (params != None):
features = torch.cat((features, params), dim = 1)
q = self.regressor(features)
#if not self.training:
# q = q.clamp(0,1)
return q
#
#
#
if __name__ == '__main__':
model = Regressor()
print(model)