NeuralNetworks 0.2.5__tar.gz → 0.2.6__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.
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/PKG-INFO +1 -1
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/Dependances/pytorch.py +3 -1
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/MLP/__init__.py +8 -21
- neuralnetworks-0.2.6/src/NeuralNetworks/MLP/inference.py +12 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/__init__.py +15 -8
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/train.py +5 -10
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/__init__.py +1 -1
- neuralnetworks-0.2.6/src/NeuralNetworks/shared/__init__.py +8 -0
- neuralnetworks-0.2.6/src/NeuralNetworks/shared/module.py +41 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/PKG-INFO +1 -1
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/SOURCES.txt +3 -1
- neuralnetworks-0.2.5/src/NeuralNetworks/MLP/inference.py +0 -26
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/LICENSE +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/README.md +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/pyproject.toml +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/setup.cfg +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/Dependances/__init__.py +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/Dependances/matplot.py +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/MLP/FourierFeatures.py +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/MLP/Layers.py +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/dynamic_learning_rate.py +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/sample_data.py +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/UI/Learnings.py +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/UI/Losses.py +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/UI/__init__.py +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/dependency_links.txt +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/requires.txt +0 -0
- {neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: NeuralNetworks
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Multi-Layer Perceptrons with multi-Fourier encoding, variable learning rate, visualization and PyTorch compilation
|
|
5
5
|
Author-email: Alexandre Brun <alexandre51160@gmail.com>
|
|
6
6
|
License: GPL-3.0-or-later
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
# (at your option) any later version.
|
|
7
7
|
|
|
8
8
|
import os
|
|
9
|
-
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
|
|
10
9
|
|
|
11
10
|
import platform
|
|
12
11
|
|
|
@@ -20,6 +19,8 @@ from torch.utils.data import TensorDataset, DataLoader
|
|
|
20
19
|
from torchmetrics.image import PeakSignalNoiseRatio as PSNR
|
|
21
20
|
from torchvision.transforms import ToTensor, Resize, Compose
|
|
22
21
|
|
|
22
|
+
import visualtorch
|
|
23
|
+
|
|
23
24
|
torch.cuda.empty_cache()
|
|
24
25
|
def get_best_device():
|
|
25
26
|
|
|
@@ -51,6 +52,7 @@ def get_best_device():
|
|
|
51
52
|
|
|
52
53
|
# =========== Unknown OS ===========
|
|
53
54
|
return torch.device("cpu")
|
|
55
|
+
|
|
54
56
|
device = get_best_device()
|
|
55
57
|
|
|
56
58
|
# --- Optimisations CUDA ---
|
|
@@ -10,7 +10,9 @@ from .FourierFeatures import encode
|
|
|
10
10
|
from .Layers import create_layers
|
|
11
11
|
from .inference import infer
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
from ..shared import Module
|
|
14
|
+
|
|
15
|
+
class MLP (Module):
|
|
14
16
|
"""
|
|
15
17
|
Multi-Layer Perceptron avec encodage de Fourier optionnel.
|
|
16
18
|
|
|
@@ -49,18 +51,13 @@ class MLP (nn.Module):
|
|
|
49
51
|
nb_fourier = 8,
|
|
50
52
|
norm = "Relu",
|
|
51
53
|
name = "Net"):
|
|
52
|
-
super ().__init__ ()
|
|
54
|
+
super ().__init__ (name)
|
|
53
55
|
|
|
54
56
|
# --- Activation ---
|
|
55
57
|
self.norm = norm_list.get (norm)
|
|
56
58
|
if self.norm is None:
|
|
57
|
-
print (f"Warning: '{norm}' not recognized,
|
|
59
|
+
print (f"Warning: '{norm}' not recognized, fRelung back to 'm is'")
|
|
58
60
|
self.norm = norm_list.get ("Relu")
|
|
59
|
-
|
|
60
|
-
# --- Attributs ---
|
|
61
|
-
self.losses = []
|
|
62
|
-
self.learnings = []
|
|
63
|
-
self.name = name
|
|
64
61
|
|
|
65
62
|
## --- Encodage Fourier ou passthrough ---
|
|
66
63
|
self.encodings, self.f = encode (
|
|
@@ -82,18 +79,8 @@ class MLP (nn.Module):
|
|
|
82
79
|
self.norm
|
|
83
80
|
)
|
|
84
81
|
|
|
85
|
-
def
|
|
86
|
-
|
|
87
|
-
Effectue une passe avant du réseau.
|
|
88
|
-
|
|
89
|
-
Parameters
|
|
90
|
-
----------
|
|
91
|
-
x : torch.Tensor
|
|
92
|
-
Entrées du réseau de shape `(N, input_size)`.
|
|
82
|
+
def _forward (self, x):
|
|
83
|
+
return infer (self, x)
|
|
93
84
|
|
|
94
|
-
|
|
95
|
-
-------
|
|
96
|
-
torch.Tensor
|
|
97
|
-
Sortie du MLP de shape `(N, output_size)`.
|
|
98
|
-
"""
|
|
85
|
+
def train_forward (self, x):
|
|
99
86
|
return infer (self, x)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# NeuralNetworks - Multi-Layer Perceptrons avec encodage Fourier
|
|
2
|
+
# Copyright (C) 2026 Alexandre Brun
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
|
|
8
|
+
from ..Dependances import torch, np, device
|
|
9
|
+
|
|
10
|
+
def infer (net, x):
|
|
11
|
+
results_list = [net.model (encoding (x)) for encoding in net.encodings]
|
|
12
|
+
return net.f (torch.cat (results_list, dim = 1))
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# the Free Software Foundation, either version 3 of the License, or
|
|
6
6
|
# (at your option) any later version.
|
|
7
7
|
|
|
8
|
-
from ..Dependances import crit_list, optim_list
|
|
8
|
+
from ..Dependances import crit_list, optim_list, np
|
|
9
9
|
from .train import train_f
|
|
10
10
|
from .sample_data import sample_data
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ class Trainer:
|
|
|
15
15
|
*nets,
|
|
16
16
|
inputs,
|
|
17
17
|
outputs,
|
|
18
|
-
|
|
18
|
+
train_size = None,
|
|
19
19
|
optim = 'Adam',
|
|
20
20
|
init_lr = 0.01,
|
|
21
21
|
crit = 'MSE',
|
|
@@ -24,12 +24,19 @@ class Trainer:
|
|
|
24
24
|
self.batch_size = batch_size
|
|
25
25
|
self.nets = nets
|
|
26
26
|
self.init_lr = init_lr
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
inputs
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
if train_size is None:
|
|
28
|
+
|
|
29
|
+
self.X_train = inputs
|
|
30
|
+
self.X_test = inputs
|
|
31
|
+
self.y_train = outputs
|
|
32
|
+
self.y_test = outputs
|
|
33
|
+
else:
|
|
34
|
+
|
|
35
|
+
self.X_train, self.X_test, self.y_train, self.y_test = sample_data (
|
|
36
|
+
inputs,
|
|
37
|
+
outputs,
|
|
38
|
+
min(1,np.abs(1 - train_size))
|
|
39
|
+
)
|
|
33
40
|
|
|
34
41
|
# --- Fonction de perte ---
|
|
35
42
|
self.crit = crit_list.get(crit)
|
|
@@ -27,7 +27,8 @@ def train_f (Trainer, num_epochs = 1, activate_tqdm = True):
|
|
|
27
27
|
pbar = tqdm (
|
|
28
28
|
range (num_epochs),
|
|
29
29
|
desc = f"train epoch",
|
|
30
|
-
disable = not (activate_tqdm)
|
|
30
|
+
disable = not (activate_tqdm),
|
|
31
|
+
mininterval=0.5
|
|
31
32
|
)
|
|
32
33
|
|
|
33
34
|
for epoch in pbar:
|
|
@@ -43,14 +44,8 @@ def train_f (Trainer, num_epochs = 1, activate_tqdm = True):
|
|
|
43
44
|
def closure ():
|
|
44
45
|
Trainer.optims [k].zero_grad (set_to_none = True)
|
|
45
46
|
with autocast (dev):
|
|
46
|
-
loss = Trainer.crit (
|
|
47
|
-
|
|
48
|
-
torch.cat (
|
|
49
|
-
[net.model (encoding (Trainer.X_train [idx]))for encoding in net.encodings],
|
|
50
|
-
dim = 1
|
|
51
|
-
)
|
|
52
|
-
),
|
|
53
|
-
Trainer.y_train[idx]
|
|
47
|
+
loss = Trainer.crit (net.train_forward (Trainer.X_train [idx]),
|
|
48
|
+
Trainer.y_train [idx]
|
|
54
49
|
)
|
|
55
50
|
scaler.scale (loss).backward ()
|
|
56
51
|
return loss
|
|
@@ -66,7 +61,7 @@ def train_f (Trainer, num_epochs = 1, activate_tqdm = True):
|
|
|
66
61
|
for param_group in Trainer.optims [k].param_groups:
|
|
67
62
|
param_group ['lr'] = net.learnings[-1]
|
|
68
63
|
|
|
69
|
-
pbar.set_postfix(loss=f"{epoch_loss:.5f}",lr=f"{net.learnings[-1]:.5f}")
|
|
64
|
+
#pbar.set_postfix(loss=f"{epoch_loss:.5f}",lr=f"{net.learnings[-1]:.5f}")
|
|
70
65
|
|
|
71
66
|
net = net.to ('cpu')
|
|
72
67
|
net.learnings.pop(-1)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# NeuralNetworks - Multi-Layer Perceptrons avec encodage Fourier
|
|
2
|
+
# Copyright (C) 2026 Alexandre Brun
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
|
|
8
|
+
from .module import Module
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# NeuralNetworks - Multi-Layer Perceptrons avec encodage Fourier
|
|
2
|
+
# Copyright (C) 2026 Alexandre Brun
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
|
|
8
|
+
from ..Dependances import norm_list, nn, torch, device
|
|
9
|
+
|
|
10
|
+
class Module (nn.Module):
|
|
11
|
+
|
|
12
|
+
def __init__ (self, name = "Net"):
|
|
13
|
+
super ().__init__ ()
|
|
14
|
+
|
|
15
|
+
# --- Attributs ---
|
|
16
|
+
self.losses = []
|
|
17
|
+
self.learnings = []
|
|
18
|
+
self.name = name
|
|
19
|
+
|
|
20
|
+
def _forward (self,x):
|
|
21
|
+
raise Exception ("_forward n'est pas défini dans la classe")
|
|
22
|
+
|
|
23
|
+
def train_forward (self,x):
|
|
24
|
+
raise Exception ("train_forward n'est pas défini dans la classe")
|
|
25
|
+
|
|
26
|
+
def forward (self, x):
|
|
27
|
+
|
|
28
|
+
with torch.no_grad ():
|
|
29
|
+
x = x.unsqueeze (0) if x.dim () == 1 else x
|
|
30
|
+
self = self.to (device)
|
|
31
|
+
x = x.to (device)
|
|
32
|
+
|
|
33
|
+
output = self._forward(x).cpu ().numpy ().flatten ()
|
|
34
|
+
|
|
35
|
+
x = x.to ('cpu')
|
|
36
|
+
self = self.to ('cpu')
|
|
37
|
+
|
|
38
|
+
return output
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: NeuralNetworks
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Multi-Layer Perceptrons with multi-Fourier encoding, variable learning rate, visualization and PyTorch compilation
|
|
5
5
|
Author-email: Alexandre Brun <alexandre51160@gmail.com>
|
|
6
6
|
License: GPL-3.0-or-later
|
|
@@ -20,4 +20,6 @@ src/NeuralNetworks/Trainer/sample_data.py
|
|
|
20
20
|
src/NeuralNetworks/Trainer/train.py
|
|
21
21
|
src/NeuralNetworks/UI/Learnings.py
|
|
22
22
|
src/NeuralNetworks/UI/Losses.py
|
|
23
|
-
src/NeuralNetworks/UI/__init__.py
|
|
23
|
+
src/NeuralNetworks/UI/__init__.py
|
|
24
|
+
src/NeuralNetworks/shared/__init__.py
|
|
25
|
+
src/NeuralNetworks/shared/module.py
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# NeuralNetworks - Multi-Layer Perceptrons avec encodage Fourier
|
|
2
|
-
# Copyright (C) 2026 Alexandre Brun
|
|
3
|
-
# This program is free software: you can redistribute it and/or modify
|
|
4
|
-
# it under the terms of the GNU General Public License as published by
|
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
-
# (at your option) any later version.
|
|
7
|
-
|
|
8
|
-
from ..Dependances import torch, np, device
|
|
9
|
-
|
|
10
|
-
def infer (net, x):
|
|
11
|
-
with torch.no_grad ():
|
|
12
|
-
x = x.unsqueeze (0) if x.dim () == 1 else x
|
|
13
|
-
|
|
14
|
-
net = net.to (device)
|
|
15
|
-
x = x.to (device)
|
|
16
|
-
results_list = [net.model (encoding (x)) for encoding in net.encodings]
|
|
17
|
-
x = x.to ('cpu')
|
|
18
|
-
|
|
19
|
-
output = np.array (
|
|
20
|
-
net.f (
|
|
21
|
-
torch.cat (results_list, dim = 1)
|
|
22
|
-
).cpu ().numpy ().flatten ()
|
|
23
|
-
)
|
|
24
|
-
net = net.to ('cpu')
|
|
25
|
-
|
|
26
|
-
return output
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/dynamic_learning_rate.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{neuralnetworks-0.2.5 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|