Commit 6e635d97 authored by Johann Schröder's avatar Johann Schröder
Browse files

cached datasets

parent cc414553
......@@ -11,12 +11,12 @@ import numpy as np
import matplotlib.pyplot as plt
import tonic
import gc
from tonic import CachedDataset
plt.style.use('science')
gc.collect()
torch.cuda.empty_cache()
sensor_size = tonic.datasets.DVSGesture.sensor_size
surface_dimensions = [41, 41]
surface_dimensions = [85, 85]
transform = tonic.transforms.Compose(
[
tonic.transforms.Downsample(time_factor=0.001),
......@@ -37,15 +37,27 @@ trainset = tonic.datasets.DVSGesture(
testset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=False)
#Frames
cached_dataset_train = CachedDataset(
trainset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_train')
cached_dataset_test = CachedDataset(
testset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_test')
# #Timesurfaces
# cached_dataset_train = CachedDataset(
# trainset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_train')
# cached_dataset_test = CachedDataset(
# testset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_test')
# train samples: 1077, test samples: 264
BATCH_SIZE = 16
BATCH_SIZE = 8
train_subset_len = 1077
test_subset_len = 264
train_subset = torch.utils.data.random_split(
trainset, [train_subset_len, len(trainset)-train_subset_len])[0]
cached_dataset_train, [train_subset_len, len(trainset)-train_subset_len])[0]
test_subset = torch.utils.data.random_split(
testset, [test_subset_len, len(testset)-test_subset_len])[0]
cached_dataset_test, [test_subset_len, len(testset)-test_subset_len])[0]
train_loader = torch.utils.data.DataLoader(dataset=train_subset,
batch_size=BATCH_SIZE,
......@@ -215,7 +227,8 @@ try:
tf_str[1] = tf_str[1].replace(",decay='exp'", "")
except:
pass
opt = str(optimizer).replace(
" ", "").strip().splitlines(keepends=False)[2:-1]
print(
f"Train Accuracy:{train_accuracies[-1]:.2f}, Test Accuracy{test_accuracies[-1]:.2f}")
fig = plt.figure(facecolor="w", figsize=(10, 5))
......@@ -256,7 +269,7 @@ fields = ['n',
' loss (train, test)',
' epochs',
' batch_size',
' lr',
' opt',
' layers',
' method',
' alpha',
......@@ -284,7 +297,7 @@ rows = [[num_rows,
(mean_losses[-1], test_losses[-1]),
EPOCHS,
BATCH_SIZE,
LR,
opt,
layers,
p_izhi.method,
p_izhi.alpha,
......
......@@ -11,13 +11,13 @@ import numpy as np
import matplotlib.pyplot as plt
import tonic
import gc
from tonic import CachedDataset
plt.style.use('science')
gc.collect()
torch.cuda.empty_cache()
sensor_size = tonic.datasets.DVSGesture.sensor_size
surface_dimensions = [41, 41]
surface_dimensions = [85, 85]
transform = tonic.transforms.Compose(
[
tonic.transforms.Downsample(time_factor=0.001),
......@@ -36,17 +36,29 @@ transform = tonic.transforms.Compose(
trainset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=True)
testset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=False)
save_to='../../data', transform=transform, train=False)
#Frames
cached_dataset_train = CachedDataset(
trainset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_train')
cached_dataset_test = CachedDataset(
testset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_test')
# #Timesurfaces
# cached_dataset_train = CachedDataset(
# trainset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_train')
# cached_dataset_test = CachedDataset(
# testset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_test')
# train samples: 1077, test samples: 264
BATCH_SIZE = 16
BATCH_SIZE = 8
train_subset_len = 1077
test_subset_len = 264
train_subset = torch.utils.data.random_split(
trainset, [train_subset_len, len(trainset)-train_subset_len])[0]
cached_dataset_train, [train_subset_len, len(trainset)-train_subset_len])[0]
test_subset = torch.utils.data.random_split(
testset, [test_subset_len, len(testset)-test_subset_len])[0]
cached_dataset_test, [test_subset_len, len(testset)-test_subset_len])[0]
train_loader = torch.utils.data.DataLoader(dataset=train_subset,
batch_size=BATCH_SIZE,
......@@ -229,7 +241,8 @@ try:
tf_str[1] = tf_str[1].replace(",decay='exp'", "")
except:
pass
opt = str(optimizer).replace(
" ", "").strip().splitlines(keepends=False)[2:-1]
print(
f"Train Accuracy:{train_accuracies[-1]:.2f}, Test Accuracy{test_accuracies[-1]:.2f}")
fig = plt.figure(facecolor="w", figsize=(10, 5))
......@@ -270,7 +283,7 @@ fields = ['n',
' loss (train, test)',
' epochs',
' batch_size',
' lr',
' opt',
' layers',
' method',
' alpha',
......@@ -298,7 +311,7 @@ rows = [[num_rows,
(mean_losses[-1], test_losses[-1]),
EPOCHS,
BATCH_SIZE,
LR,
opt,
layers,
p_izhi.method,
p_izhi.alpha,
......
......@@ -11,12 +11,12 @@ import numpy as np
import matplotlib.pyplot as plt
import tonic
import gc
from tonic import CachedDataset
plt.style.use('science')
gc.collect()
torch.cuda.empty_cache()
sensor_size = tonic.datasets.DVSGesture.sensor_size
surface_dimensions = [41, 41]
surface_dimensions = [85, 85]
transform = tonic.transforms.Compose(
[
tonic.transforms.Downsample(time_factor=0.001),
......@@ -35,17 +35,29 @@ transform = tonic.transforms.Compose(
trainset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=True)
testset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=False)
save_to='../../data', transform=transform, train=False)
#Frames
cached_dataset_train = CachedDataset(
trainset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_train')
cached_dataset_test = CachedDataset(
testset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_test')
# #Timesurfaces
# cached_dataset_train = CachedDataset(
# trainset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_train')
# cached_dataset_test = CachedDataset(
# testset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_test')
# train samples: 1077, test samples: 264
BATCH_SIZE = 16
BATCH_SIZE = 8
train_subset_len = 1077
test_subset_len = 264
train_subset = torch.utils.data.random_split(
trainset, [train_subset_len, len(trainset)-train_subset_len])[0]
cached_dataset_train, [train_subset_len, len(trainset)-train_subset_len])[0]
test_subset = torch.utils.data.random_split(
testset, [test_subset_len, len(testset)-test_subset_len])[0]
cached_dataset_test, [test_subset_len, len(testset)-test_subset_len])[0]
train_loader = torch.utils.data.DataLoader(dataset=train_subset,
batch_size=BATCH_SIZE,
......@@ -236,7 +248,8 @@ try:
tf_str[1] = tf_str[1].replace(",decay='exp'", "")
except:
pass
opt = str(optimizer).replace(
" ", "").strip().splitlines(keepends=False)[2:-1]
print(
f"Train Accuracy:{train_accuracies[-1]:.2f}, Test Accuracy{test_accuracies[-1]:.2f}")
fig = plt.figure(facecolor="w", figsize=(10, 5))
......@@ -277,7 +290,7 @@ fields = ['n',
' loss (train, test)',
' epochs',
' batch_size',
' lr',
' opt',
' layers',
' method',
' alpha',
......@@ -305,7 +318,7 @@ rows = [[num_rows,
(mean_losses[-1], test_losses[-1]),
EPOCHS,
BATCH_SIZE,
LR,
opt,
layers,
p_izhi.method,
p_izhi.alpha,
......
......@@ -13,12 +13,12 @@ import gc
import torch.nn as nn
import torch.nn.functional as F
import sys
from tonic import CachedDataset
plt.style.use('science')
gc.collect()
torch.cuda.empty_cache()
sensor_size = tonic.datasets.DVSGesture.sensor_size
surface_dimensions = [41, 41]
surface_dimensions = [85, 85]
transform = tonic.transforms.Compose(
[
tonic.transforms.Downsample(time_factor=0.001),
......@@ -39,15 +39,27 @@ trainset = tonic.datasets.DVSGesture(
testset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=False)
#Frames
cached_dataset_train = CachedDataset(
trainset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_train')
cached_dataset_test = CachedDataset(
testset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_test')
# #Timesurfaces
# cached_dataset_train = CachedDataset(
# trainset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_train')
# cached_dataset_test = CachedDataset(
# testset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_test')
# train samples: 1077, test samples: 264
BATCH_SIZE = 16
BATCH_SIZE = 8
train_subset_len = 1077
test_subset_len = 264
train_subset = torch.utils.data.random_split(
trainset, [train_subset_len, len(trainset)-train_subset_len])[0]
cached_dataset_train, [train_subset_len, len(trainset)-train_subset_len])[0]
test_subset = torch.utils.data.random_split(
testset, [test_subset_len, len(testset)-test_subset_len])[0]
cached_dataset_test, [test_subset_len, len(testset)-test_subset_len])[0]
train_loader = torch.utils.data.DataLoader(dataset=train_subset,
batch_size=BATCH_SIZE,
......@@ -254,7 +266,8 @@ try:
tf_str[1] = tf_str[1].replace(",decay='exp'", "")
except:
pass
opt = str(optimizer).replace(
" ", "").strip().splitlines(keepends=False)[2:-1]
print(
f"Train Accuracy:{train_accuracies[-1]:.2f}, Test Accuracy{test_accuracies[-1]:.2f}")
fig = plt.figure(facecolor="w", figsize=(10, 5))
......@@ -295,7 +308,7 @@ fields = ['n',
' loss (train, test)',
' epochs',
' batch_size',
' lr',
' opt',
' layers',
' method',
' alpha',
......@@ -323,7 +336,7 @@ rows = [[num_rows,
(mean_losses[-1], test_losses[-1]),
EPOCHS,
BATCH_SIZE,
LR,
opt,
layers,
p_izhi.method,
p_izhi.alpha,
......
......@@ -12,11 +12,12 @@ import datetime
import sys
import time
from prettytable.prettytable import from_csv
from tonic import CachedDataset
plt.style.use('science')
gc.collect()
torch.cuda.empty_cache()
sensor_size = tonic.datasets.DVSGesture.sensor_size
surface_dimensions = [41, 41]
surface_dimensions = [85, 85]
transform = tonic.transforms.Compose(
[
tonic.transforms.Downsample(time_factor=0.001),
......@@ -37,15 +38,27 @@ trainset = tonic.datasets.DVSGesture(
testset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=False)
#Frames
cached_dataset_train = CachedDataset(
trainset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_train')
cached_dataset_test = CachedDataset(
testset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_test')
# #Timesurfaces
# cached_dataset_train = CachedDataset(
# trainset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_train')
# cached_dataset_test = CachedDataset(
# testset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_test')
# train samples: 1077, test samples: 264
BATCH_SIZE = 16
BATCH_SIZE = 8
train_subset_len = 1077
test_subset_len = 264
train_subset = torch.utils.data.random_split(
trainset, [train_subset_len, len(trainset)-train_subset_len])[0]
cached_dataset_train, [train_subset_len, len(trainset)-train_subset_len])[0]
test_subset = torch.utils.data.random_split(
testset, [test_subset_len, len(testset)-test_subset_len])[0]
cached_dataset_test, [test_subset_len, len(testset)-test_subset_len])[0]
train_loader = torch.utils.data.DataLoader(dataset=train_subset,
batch_size=BATCH_SIZE,
......@@ -220,7 +233,8 @@ try:
tf_str[1] = tf_str[1].replace(",decay='exp'", "")
except:
pass
opt = str(optimizer).replace(
" ", "").strip().splitlines(keepends=False)[2:-1]
print(
f"Train Accuracy:{train_accuracies[-1]:.2f}, Test Accuracy{test_accuracies[-1]:.2f}")
......@@ -262,7 +276,7 @@ fields = ['n',
' loss (train, test)',
' epochs',
' batch_size',
' lr',
' opt',
' layers',
' method',
' alpha',
......@@ -290,7 +304,7 @@ rows = [[num_rows,
(mean_losses[-1], test_losses[-1]),
EPOCHS,
BATCH_SIZE,
LR,
opt,
layers,
p_izhi.method,
p_izhi.alpha,
......
......@@ -12,41 +12,54 @@ import matplotlib.pyplot as plt
import tonic
import gc
import sys
from tonic import CachedDataset
plt.style.use('science')
gc.collect()
torch.cuda.empty_cache()
sensor_size = tonic.datasets.DVSGesture.sensor_size
surface_dimensions = [41, 41]
surface_dimensions = [85, 85]
transform = tonic.transforms.Compose(
[
# tonic.transforms.Downsample(time_factor=0.001),
# tonic.transforms.ToFrame(sensor_size=sensor_size,
# time_window=10,
# ),
tonic.transforms.Denoise(filter_time=1),
tonic.transforms.ToTimesurface(sensor_size=sensor_size,
surface_dimensions=surface_dimensions,
tau=5000,
decay='exp'
)
tonic.transforms.Downsample(time_factor=0.001),
tonic.transforms.ToFrame(sensor_size=sensor_size,
time_window=10,
),
# tonic.transforms.Denoise(filter_time=1),
# tonic.transforms.ToTimesurface(sensor_size=sensor_size,
# surface_dimensions=surface_dimensions,
# tau=5000,
# decay='exp'
# )
]
)
trainset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=True)
testset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=False)
#Frames
cached_dataset_train = CachedDataset(
trainset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_train')
cached_dataset_test = CachedDataset(
testset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_test')
# #Timesurfaces
# cached_dataset_train = CachedDataset(
# trainset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_train')
# cached_dataset_test = CachedDataset(
# testset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_test')
# train samples: 1077, test samples: 264
BATCH_SIZE = 16
BATCH_SIZE = 8
train_subset_len = 1077
test_subset_len = 264
train_subset = torch.utils.data.random_split(
trainset, [train_subset_len, len(trainset)-train_subset_len])[0]
cached_dataset_train, [train_subset_len, len(trainset)-train_subset_len])[0]
test_subset = torch.utils.data.random_split(
testset, [test_subset_len, len(testset)-test_subset_len])[0]
cached_dataset_test, [test_subset_len, len(testset)-test_subset_len])[0]
train_loader = torch.utils.data.DataLoader(dataset=train_subset,
batch_size=BATCH_SIZE,
......@@ -62,8 +75,8 @@ train_len = train_subset_len/BATCH_SIZE
test_len = test_subset_len/BATCH_SIZE
neuron_params = LIFParameters(
alpha=torch.as_tensor(25),
tau_mem_inv=torch.as_tensor(1.0/5e-3),
alpha=torch.as_tensor(50),
tau_mem_inv=torch.as_tensor(1.0/2e-2),
tau_syn_inv=torch.as_tensor(1.0/2e-2),
v_th=torch.as_tensor(0.5),
v_leak=torch.as_tensor(0.0),
......@@ -118,8 +131,8 @@ class Model(torch.nn.Module):
EPOCHS = 1
LR = 0.002
# INPUT_FEATURES = np.product(sensor_size)
INPUT_FEATURES = np.product(surface_dimensions) * 2
INPUT_FEATURES = np.product(sensor_size)
# INPUT_FEATURES = np.product(surface_dimensions) * 2
HIDDEN_FEATURES = 100
OUTPUT_FEATURES = len(trainset.classes)
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
......@@ -208,7 +221,8 @@ try:
tf_str[1] = tf_str[1].replace(",decay='exp'", "")
except:
pass
opt = str(optimizer).replace(
" ", "").strip().splitlines(keepends=False)[2:-1]
print(
f"Train Accuracy:{train_accuracies[-1]:.2f}, Test Accuracy{test_accuracies[-1]:.2f}")
fig = plt.figure(facecolor="w", figsize=(10, 5))
......@@ -249,7 +263,7 @@ fields = ['n',
' loss (train, test)',
' epochs',
' batch_size',
' lr',
' optimizer',
' layers',
' method',
' alpha',
......@@ -275,7 +289,7 @@ rows = [[num_rows,
(mean_losses[-1], test_losses[-1]),
EPOCHS,
BATCH_SIZE,
LR,
opt,
layers,
neuron_params.method,
neuron_params.alpha.item(),
......
......@@ -15,13 +15,13 @@ import gc
import torch.nn as nn
import torch.nn.functional as F
import sys
from tonic import CachedDataset
plt.style.use('science')
gc.collect()
torch.cuda.empty_cache()
sensor_size = tonic.datasets.DVSGesture.sensor_size
surface_dimensions = [41, 41]
surface_dimensions = [85, 85]
transform = tonic.transforms.Compose(
[
tonic.transforms.Downsample(time_factor=0.001),
......@@ -42,15 +42,27 @@ trainset = tonic.datasets.DVSGesture(
testset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=False)
#Frames
cached_dataset_train = CachedDataset(
trainset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_train')
cached_dataset_test = CachedDataset(
testset, cache_path='../../data/cached_datasets/dvsgesture_TF_tw10_test')
# #Timesurfaces
# cached_dataset_train = CachedDataset(
# trainset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_train')
# cached_dataset_test = CachedDataset(
# testset, cache_path='../../data/cached_datasets/dvsgesture_TTS_f1_test')
# train samples: 1077, test samples: 264
BATCH_SIZE = 64
BATCH_SIZE = 8
train_subset_len = 1077
test_subset_len = 264
train_subset = torch.utils.data.random_split(
trainset, [train_subset_len, len(trainset)-train_subset_len])[0]
cached_dataset_train, [train_subset_len, len(trainset)-train_subset_len])[0]
test_subset = torch.utils.data.random_split(
testset, [test_subset_len, len(testset)-test_subset_len])[0]
cached_dataset_test, [test_subset_len, len(testset)-test_subset_len])[0]
train_loader = torch.utils.data.DataLoader(dataset=train_subset,
batch_size=BATCH_SIZE,
......@@ -66,8 +78,8 @@ train_len = train_subset_len/BATCH_SIZE
test_len = test_subset_len/BATCH_SIZE
neuron_params = LIFParameters(
alpha=torch.as_tensor(100),
tau_mem_inv=torch.as_tensor(1.0/5e-3),
alpha=torch.as_tensor(50),
tau_mem_inv=torch.as_tensor(1.0/2e-2),
tau_syn_inv=torch.as_tensor(1.0/2e-2),
v_th=torch.as_tensor(0.5),
v_leak=torch.as_tensor(0.0),
......@@ -125,7 +137,7 @@ class Model(torch.nn.Module):
return log_p_y
EPOCHS = 50
EPOCHS = 25
LR = 0.002
INPUT_FEATURES = np.product(sensor_size)
# INPUT_FEATURES = np.product(surface_dimensions) * 2
......@@ -219,7 +231,8 @@ try:
tf_str[1] = tf_str[1].replace(",decay='exp'", "")
except:
pass
opt = str(optimizer).replace(
" ", "").strip().splitlines(keepends=False)[2:-1]
print(
f"Train Accuracy:{train_accuracies[-1]:.2f}, Test Accuracy{test_accuracies[-1]:.2f}")
fig = plt.figure(facecolor="w", figsize=(10, 5))
......@@ -260,7 +273,7 @@ fields = ['n',
' loss (train, test)',
' epochs',
' batch_size',
' lr',
' opt',
' layers',
' method',
' alpha',
......@@ -286,7 +299,7 @@ rows = [[num_rows,
(mean_losses[-1], test_losses[-1]),
EPOCHS,
BATCH_SIZE,
LR,
opt,
layers,
neuron_params.method,
neuron_params.alpha.item(),
......
......@@ -15,12 +15,12 @@ import gc
import torch.nn as nn
import torch.nn.functional as F
import sys
from tonic import CachedDataset
plt.style.use('science')
gc.collect()
torch.cuda.empty_cache()
sensor_size = tonic.datasets.DVSGesture.sensor_size
surface_dimensions = [41, 41]
surface_dimensions = [85, 85]
transform = tonic.transforms.Compose(
[
tonic.transforms.Downsample(time_factor=0.001),
......@@ -35,21 +35,32 @@ transform = tonic.transforms.Compose(
# )
]
)
trainset = tonic.datasets.DVSGesture(
save_to='../../data', transform=transform, train=True)
testset = tonic.datasets.DVSGesture(