Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d8d7193
first commit - visualization_branch
Teo56 Jan 15, 2024
0c6e94b
visualization class with functions to plot the latent space - still t…
Teo56 Jan 15, 2024
0d1b06d
- visualization implemented as part of the _run() function in the Tra…
Teo56 Jan 16, 2024
4f09e1f
- Fix issue with visualization for MPLVariationalAutoencoder model
Teo56 Jan 16, 2024
311bd73
Adds the option to train multiple models simultaneously andan example
AlexKClarke Jan 29, 2024
5a5e8fd
linking the two models for iop
Teo56 Jan 30, 2024
750f734
- implemented visualization of latents at the end of training
Feb 1, 2024
f62ac1b
- corrected errors with visualization when the option 'full_dataset' …
Feb 1, 2024
cfa6c2a
- corrected error in Conv2dTranspose
Feb 6, 2024
7399f43
- corrected error in Conv2dTranspose
Feb 6, 2024
6607d42
- corrected error in Conv2dTranspose
Feb 6, 2024
bb46416
- implemented visualization of original image and reconstructed image
Feb 7, 2024
03b1ad6
- first commit
Feb 13, 2024
c3f4a72
- first commit
Feb 13, 2024
374923c
update local repo
Feb 13, 2024
22741ee
update local repo
Feb 13, 2024
a9d530e
- update gitignore
Feb 13, 2024
1529815
- update gitignore
Feb 14, 2024
6b2b1da
new data updates
Mar 5, 2024
e610e2e
network implementation and latents visualization
Mar 11, 2024
674e817
gitignore update
Mar 11, 2024
1c46879
- Update in the way EMG is standardised
Mar 11, 2024
e07e862
- Implemented block to use Conv2d and a series of linear layers
Mar 13, 2024
ce35fa9
- raw_EMG_vae branch update
Mar 13, 2024
1e71a0e
update
Mar 13, 2024
c1e5ab3
- Implemented Conv2D+MLP block
Mar 17, 2024
b7800c4
- Gitignore updates
Mar 18, 2024
9982acd
- small test updates
Mar 18, 2024
3d9f26f
- update raw_emg branch
Mar 22, 2024
4d54b3c
- removed pycache files
Mar 25, 2024
bcb11e3
Delete loader_modules/__pycache__ directory
Teo56 Mar 26, 2024
0f974a7
Delete networks/__pycache__ directory
Teo56 Mar 26, 2024
8db3c18
Delete training/__pycache__ directory
Teo56 Mar 26, 2024
6a61351
Delete update_modules/__pycache__ directory
Teo56 Mar 26, 2024
e43b13f
Delete visualization_modules/__pycache__ directory
Teo56 Mar 26, 2024
01da372
Delete .idea directory
Teo56 Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/mps_test.py
/emg_data_folder/
/logs
/venv
100 changes: 100 additions & 0 deletions examples/run_mnist_io_variational_autoencoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""Example of training a 2D convolutional neural network to autoencode
8x8 MNIST images"""

import os, sys

if os.path.basename(os.getcwd()) == "examples":
os.chdir("..")
sys.path.append(os.path.abspath(""))

from training import TrainingModule

if __name__ == "__main__":
# The entirety of the run is defined by config, which will be unpacked
# at run time. The training module will look in the loader_modules
# and update_modules __init__.py for the named modules and then pass
training_module_config = {
"log_name": "mnist_vae",
"update_module_config": {
"update_module_name": "IOVariationalAutoencoder",
"update_module_kwargs": {
"optimizer": "multimodel",
"optimizer_kwargs": {
0: {
"optimizer": "AdamW",
"optimizer_kwargs": {"lr": 0.01},
},
1: {
"optimizer": "AdamW",
"optimizer_kwargs": {"lr": 0.01},
},
},
"beta_step": 1e-2,
"max_beta": 1,
"n_steps_per_switch": 5,
"network_training_steps": [20, 10],
"n_samples_in_aux": 32,
},
"maximize_val_target": False,
"network_config": {
"network_name": "multimodel",
"network_kwargs": {

0: {
"network_name": "vae.MLPVariationalAutoencoder",
"network_kwargs": {
"latent_dim": 5,
"out_chans_per_layer": [256, 128, 64],
"fix_recon_var": False,
},
},

1: {
"network_name": "blocks.MLPBlock",
"network_kwargs": {
"input_shape": [5],
"output_shape": [1],
"out_chans_per_layer": [8, 8],
"output_activation": "Sigmoid",
},
},
},
},
},
"loader_module_config": {
"loader_module_name": "MNIST28",
"loader_module_kwargs": {
"batch_size": 32,
"auto": True,
"flatten_input": True,
},
},

"latents_visualization": True,

"trainer_kwargs": {
"accelerator": "gpu",
"devices": 1,
"max_epochs": 100,
"log_every_n_steps": 1,
},



}

# Once the config is defined it can be passed to an instance of the
# training module
training_module = TrainingModule(training_module_config)

# Train the model and pass the results to tensorboard
training_module.train()



""""trainer_kwargs": {
"accelerator": "cpu",
"devices": 1,
"max_epochs": 200,
"log_every_n_steps": 1,
},"""
17 changes: 12 additions & 5 deletions examples/run_mnist_sparse_autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,24 @@
"network_config": {
"network_name": "sparse.Conv2dSparseAutoencoder",
"network_kwargs": {
"input_shape": [1, 8, 8],
"output_shape": [1, 8, 8],
"sparse_dim": 3,
"out_chans_per_layer": [32, 64],
"input_shape": [1, 28, 28],
"output_shape": [1, 28, 28],
"sparse_dim": 2,
"out_chans_per_layer": [4, 8],
},
},
},
"loader_module_config": {
"loader_module_name": "MNIST",
"loader_module_name": "MNIST28",
"loader_module_kwargs": {"batch_size": 64, "auto": True},
},
"trainer_kwargs": {
"accelerator": "gpu",
"devices": 1,
"max_epochs": 10,
"log_every_n_steps": 10,
},
"latents_visualization": True,
}

# Once the config is defined it can be passed to an instance of the
Expand Down
70 changes: 70 additions & 0 deletions examples/run_mnist_variational_autoencoder_CNN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Example of training a 2D convolutional neural network to autoencode
8x8 MNIST images"""

import os, sys

if os.path.basename(os.getcwd()) == "examples":
os.chdir("..")
sys.path.append(os.path.abspath(""))

from training import TrainingModule

if __name__ == "__main__":
# The entirety of the run is defined by config, which will be unpacked
# at run time. The training module will look in the loader_modules
# and update_modules __init__.py for the named modules and then pass
training_module_config = {
"log_name": "mnist_vae",
"update_module_config": {
"update_module_name": "VariationalAutoencoder",
"update_module_kwargs": {
"optimizer": "AdamW",
"optimizer_kwargs": {"lr": 0.01},
"beta_step": 1e-2,
"max_beta": 1.0,
},
"maximize_val_target": False,
"network_config": {
"network_name": "vae.Conv2dVariationalAutoencoder",
"network_kwargs": {
"latent_dim": 4,
"kernel_size_per_layer": 2,
"stride_per_layer": 2,
"out_chans_per_layer": [10, 20, 30],
"fix_recon_var": False,
},
},
},
"loader_module_config": {
"loader_module_name": "MNIST28",
"loader_module_kwargs": {
"batch_size": 32,
"auto": True,
"flatten_input": False,
},
},
"trainer_kwargs": {
"accelerator": "gpu",
"devices": 1,
"max_epochs": 10,
"log_every_n_steps": 10,
},

"latents_visualization": True,
}

# Once the config is defined it can be passed to an instance of the
# training module
training_module = TrainingModule(training_module_config)

# Train the model and pass the results to tensorboard
training_module.train()



'''"trainer_kwargs": {
"accelerator": "cpu",
"devices": 1,
"max_epochs": 10,
"log_every_n_steps": 1,
},'''
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Example of training a 2D convolutional neural network to autoencode
"""Example of training a 2D convolutional neural network to autoencode
8x8 MNIST images"""

import os, sys
Expand All @@ -14,7 +14,7 @@
# at run time. The training module will look in the loader_modules
# and update_modules __init__.py for the named modules and then pass
training_module_config = {
"log_name": "mnist_vae",
"log_name": "mnist_vae_MLP",
"update_module_config": {
"update_module_name": "VariationalAutoencoder",
"update_module_kwargs": {
Expand All @@ -25,10 +25,10 @@
},
"maximize_val_target": False,
"network_config": {
"network_name": "vae.Conv2dVariationalAutoencoder",
"network_name": "vae.MLPVariationalAutoencoder",
"network_kwargs": {
"latent_dim": 3,
"out_chans_per_layer": [16, 32],
"out_chans_per_layer": [256, 128],
"fix_recon_var": False,
},
},
Expand All @@ -38,9 +38,17 @@
"loader_module_kwargs": {
"batch_size": 32,
"auto": True,
"flatten_input": False,
"flatten_input": True,
},
},
"trainer_kwargs": {
"accelerator": "gpu",
"devices": 1,
"max_epochs": 20,
"log_every_n_steps": 1,
},

"latents_visualization": True,
}

# Once the config is defined it can be passed to an instance of the
Expand All @@ -50,9 +58,11 @@
# Train the model and pass the results to tensorboard
training_module.train()



'''"trainer_kwargs": {
"accelerator": "cpu",
"devices": 1,
"max_epochs": 200,
"max_epochs": 10,
"log_every_n_steps": 1,
},'''
68 changes: 68 additions & 0 deletions examples/run_raw_emg_classifier_vae_CNN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Example of training a 1D convolutional neural network to learn a classifier
on MU labelled EMG"""

import os, sys
from ray import tune

if os.path.basename(os.getcwd()) == "examples":
os.chdir("..")
sys.path.append(os.path.abspath(""))

from training import TrainingModule

if __name__ == "__main__":
# The entirety of the run is defined by config, which will be unpacked
# at run time. The training module will look in the loader_modules
# and update_modules __init__.py for the named modules and then pass
training_module_config = {
"log_name": "raw_emg_classifier_CNN",
"update_module_config": {
"update_module_name": "VariationalAutoencoder",
"update_module_kwargs": {
"optimizer": "AdamW",
"optimizer_kwargs": {"lr": 0.01},
"beta_step": 1.0e-2,
"max_beta": 1.0,
},
"maximize_val_target": True,
"network_config": {
"network_name": "vae.Conv2dVariationalAutoencoder",
"network_kwargs": {
"latent_dim": 2,
"kernel_size_per_layer": [(15, 1), (30, 1), (15, 1)], # (time, channels) for each layer
"stride_per_layer": [(1, 1), (3, 1), (5, 1)], # (time, channels)
"out_chans_per_layer": [10, 10, 20],
"fix_recon_var": False,
},
},
},
"loader_module_config": {
"loader_module_name": "RawEMGLabelled",
"loader_module_kwargs": {
"file_path": "emg_data_folder/gesture_set_1",
"test_fraction": 0.1, # of whole dataset
"val_fraction": 0.03, # of test set
"group_size": 1,
"batch_size": 32,
"one_hot_labels": False,
"shuffle_data": False,
"flatten_input": False,
"rectify_emg": True,
},
},
"trainer_kwargs": {
"accelerator": "gpu",
"devices": 1,
"max_epochs": 30,
"log_every_n_steps": 10,
},

"latents_visualization": True,
}

# Once the config is defined it can be passed to an instance of the
# training module
training_module = TrainingModule(training_module_config)

# Train the model and pass the results to tensorboard
training_module.train()
Loading