@@ -27,11 +27,7 @@ def train(H, model, str, lr=0.001):
2727
2828 cuda = torch .cuda .is_available ()
2929 os .makedirs (f"{ pathr } models" , exist_ok = True )
30- name = (
31- f"{ data [:- 4 ]} { H [:]} { lr :g} lr{ str } " .replace (", " , "." )
32- .replace ("[" , "_" )
33- .replace ("]" , "_" )
34- )
30+ name = f"{ data [:- 4 ]} { H [:]} { lr :g} lr{ str } " .replace (", " , "." ).replace ("[" , "_" ).replace ("]" , "_" )
3531 print (f"Running { name } " )
3632
3733 device = select_device ()
@@ -47,9 +43,7 @@ def train(H, model, str, lr=0.001):
4743 x , _ , _ = normalize (x , 1 ) # normalize each input row
4844 y , _ymu , ys = normalize (y , 0 ) # normalize each output column
4945 x , y = torch .Tensor (x ), torch .Tensor (y )
50- x , y , xv , yv , xt , yt = splitdata (
51- x , y , train = 0.70 , validate = 0.15 , test = 0.15 , shuffle = False
52- )
46+ x , y , xv , yv , xt , yt = splitdata (x , y , train = 0.70 , validate = 0.15 , test = 0.15 , shuffle = False )
5347
5448 # torch.nn.init.constant_(model.out.weight.data, ys.item(0))
5549 # torch.nn.init.constant_(model.out.bias.data, ymu.item(0))
@@ -160,24 +154,18 @@ def __init__(self, n_out=2):
160154 """Initializes the WAVE4 model with specified output layers and configurations for convolutional layers."""
161155 super ().__init__ ()
162156 self .layer1 = nn .Sequential (
163- nn .Conv2d (
164- 1 , 32 , kernel_size = (1 , 9 ), stride = (1 , 2 ), padding = (0 , 4 ), bias = False
165- ),
157+ nn .Conv2d (1 , 32 , kernel_size = (1 , 9 ), stride = (1 , 2 ), padding = (0 , 4 ), bias = False ),
166158 nn .BatchNorm2d (32 ),
167159 nn .LeakyReLU (0.1 ),
168160 )
169161 # nn.MaxPool2d(kernel_size=(1, 2), stride=1))
170162 self .layer2 = nn .Sequential (
171- nn .Conv2d (
172- 32 , 64 , kernel_size = (1 , 9 ), stride = (1 , 2 ), padding = (0 , 4 ), bias = False
173- ),
163+ nn .Conv2d (32 , 64 , kernel_size = (1 , 9 ), stride = (1 , 2 ), padding = (0 , 4 ), bias = False ),
174164 nn .BatchNorm2d (64 ),
175165 nn .LeakyReLU (0.1 ),
176166 )
177167 # nn.MaxPool2d(kernel_size=(1, 2), stride=1))
178- self .layer3 = nn .Conv2d (
179- 64 , n_out , kernel_size = (2 , 64 ), stride = (1 , 1 ), padding = (0 , 0 )
180- )
168+ self .layer3 = nn .Conv2d (64 , n_out , kernel_size = (2 , 64 ), stride = (1 , 1 ), padding = (0 , 0 ))
181169
182170 def forward (self , x ): # x.shape = [bs, 512]
183171 """Forward pass for processing input tensor through convolutional layers and reshaping output for
@@ -263,24 +251,18 @@ def __init__(self, n_out=2):
263251 """Initializes the WAVE2 model architecture components."""
264252 super ().__init__ ()
265253 self .layer1 = nn .Sequential (
266- nn .Conv2d (
267- 1 , 32 , kernel_size = (2 , 30 ), stride = (1 , 2 ), padding = (1 , 15 ), bias = False
268- ),
254+ nn .Conv2d (1 , 32 , kernel_size = (2 , 30 ), stride = (1 , 2 ), padding = (1 , 15 ), bias = False ),
269255 nn .BatchNorm2d (32 ),
270256 nn .LeakyReLU (0.1 ),
271257 nn .MaxPool2d (kernel_size = (1 , 2 ), stride = 1 ),
272258 )
273259 self .layer2 = nn .Sequential (
274- nn .Conv2d (
275- 32 , 64 , kernel_size = (2 , 30 ), stride = (1 , 2 ), padding = (0 , 15 ), bias = False
276- ),
260+ nn .Conv2d (32 , 64 , kernel_size = (2 , 30 ), stride = (1 , 2 ), padding = (0 , 15 ), bias = False ),
277261 nn .BatchNorm2d (64 ),
278262 nn .LeakyReLU (0.1 ),
279263 nn .MaxPool2d (kernel_size = (1 , 2 ), stride = 1 ),
280264 )
281- self .layer3 = nn .Sequential (
282- nn .Conv2d (64 , n_out , kernel_size = (2 , 64 ), stride = (1 , 1 ), padding = (0 , 0 ))
283- )
265+ self .layer3 = nn .Sequential (nn .Conv2d (64 , n_out , kernel_size = (2 , 64 ), stride = (1 , 1 ), padding = (0 , 0 )))
284266
285267 def forward (self , x ): # x.shape = [bs, 512]
286268 """Forward pass for processing input tensor x through sequential layers, reshaping as needed for the model."""
@@ -297,12 +279,8 @@ def forward(self, x): # x.shape = [bs, 512]
297279if __name__ == "__main__" :
298280 parser = argparse .ArgumentParser ()
299281 parser .add_argument ("--epochs" , type = int , default = 5000 , help = "number of epochs" )
300- parser .add_argument (
301- "--batch-size" , type = int , default = 2000 , help = "size of each image batch"
302- )
303- parser .add_argument (
304- "--printerval" , type = int , default = 1 , help = "print results interval"
305- )
282+ parser .add_argument ("--batch-size" , type = int , default = 2000 , help = "size of each image batch" )
283+ parser .add_argument ("--printerval" , type = int , default = 1 , help = "print results interval" )
306284 parser .add_argument ("--var" , nargs = "+" , default = [3 ], help = "debug list" )
307285 opt = parser .parse_args ()
308286 opt .var = [float (x ) for x in opt .var ]
0 commit comments