Spaces:
Build error
Build error
added finalise
Browse files- .gitignore +1 -0
- app.py +1 -1
- funcs/dataloader.py +1 -0
- funcs/som.py +4 -1
- models/r10d.pth +3 -0
- test.py +47 -0
.gitignore
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
# Byte-compiled / optimized / DLL files
|
|
|
2 |
*.mp4
|
3 |
*.xz
|
4 |
*.json
|
|
|
1 |
# Byte-compiled / optimized / DLL files
|
2 |
+
*.pkg
|
3 |
*.mp4
|
4 |
*.xz
|
5 |
*.json
|
app.py
CHANGED
@@ -13,7 +13,7 @@ from funcs.dataloader import BaseDataset2, read_json_files
|
|
13 |
|
14 |
DEVICE = torch.device("cpu")
|
15 |
reducer10d = PHATEAE(epochs=30, n_components=10, lr=.0001, batch_size=128, t='auto', knn=8, relax=True, metric='euclidean')
|
16 |
-
reducer10d.load('models/
|
17 |
|
18 |
cluster_som = ClusterSOM()
|
19 |
cluster_som.load("models/cluster_som2.pkl")
|
|
|
13 |
|
14 |
DEVICE = torch.device("cpu")
|
15 |
reducer10d = PHATEAE(epochs=30, n_components=10, lr=.0001, batch_size=128, t='auto', knn=8, relax=True, metric='euclidean')
|
16 |
+
reducer10d.load('models/r10d.pth')
|
17 |
|
18 |
cluster_som = ClusterSOM()
|
19 |
cluster_som.load("models/cluster_som2.pkl")
|
funcs/dataloader.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import glob, json, os
|
2 |
import torch
|
3 |
import warnings
|
|
|
4 |
|
5 |
from torch.utils.data import Dataset
|
6 |
|
|
|
1 |
import glob, json, os
|
2 |
import torch
|
3 |
import warnings
|
4 |
+
import numpy as np
|
5 |
|
6 |
from torch.utils.data import Dataset
|
7 |
|
funcs/som.py
CHANGED
@@ -435,7 +435,10 @@ class ClusterSOM:
|
|
435 |
if len(self.som_models) == 0:
|
436 |
raise ValueError("SOM models not trained yet.")
|
437 |
|
438 |
-
|
|
|
|
|
|
|
439 |
|
440 |
fig, axes = plt.subplots(1, len(self.som_models), figsize=(20, 5), sharex=True, sharey=True)
|
441 |
fig.suptitle(f"Activation map for SOM {prediction[0]}, node {prediction[1]}", fontsize=16)
|
|
|
435 |
if len(self.som_models) == 0:
|
436 |
raise ValueError("SOM models not trained yet.")
|
437 |
|
438 |
+
try:
|
439 |
+
prediction = self.predict([data[int(slice_select)-1]])[0]
|
440 |
+
except:
|
441 |
+
prediction = self.predict([data[int(slice_select)-2]])[0]
|
442 |
|
443 |
fig, axes = plt.subplots(1, len(self.som_models), figsize=(20, 5), sharex=True, sharey=True)
|
444 |
fig.suptitle(f"Activation map for SOM {prediction[0]}, node {prediction[1]}", fontsize=16)
|
models/r10d.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ad5529c863ea3fcaf1525cf59b9352dfe42ff4568ed459ac978baaf818a8ad7d
|
3 |
+
size 13100223
|
test.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
|
7 |
+
from phate import PHATEAE
|
8 |
+
from funcs.som import ClusterSOM
|
9 |
+
from funcs.tools import numpy_to_native
|
10 |
+
|
11 |
+
from funcs.processor import process_data
|
12 |
+
from funcs.plot_func import plot_sensor_data_from_json
|
13 |
+
from funcs.dataloader import BaseDataset2, read_json_files
|
14 |
+
|
15 |
+
DEVICE = torch.device("cpu")
|
16 |
+
reducer10d = PHATEAE(epochs=30, n_components=10, lr=.0001, batch_size=128, t='auto', knn=8, relax=True, metric='euclidean')
|
17 |
+
reducer10d.load('models/r10d_2.pth')
|
18 |
+
|
19 |
+
cluster_som = ClusterSOM()
|
20 |
+
cluster_som.load("models/cluster_som2.pkl")
|
21 |
+
|
22 |
+
# ml inference
|
23 |
+
def get_som_mp4(file, slice_select, reducer=reducer10d, cluster=cluster_som):
|
24 |
+
|
25 |
+
try:
|
26 |
+
train_x, train_y = read_json_files(file)
|
27 |
+
except:
|
28 |
+
train_x, train_y = read_json_files(file.name)
|
29 |
+
|
30 |
+
# Convert tensors to numpy arrays if necessary
|
31 |
+
if isinstance(train_x, torch.Tensor):
|
32 |
+
train_x = train_x.numpy()
|
33 |
+
if isinstance(train_y, torch.Tensor):
|
34 |
+
train_y = train_y.numpy()
|
35 |
+
|
36 |
+
# load the time series slices of the data 4*3*2*64 (feeds+axis*sensor*samples) + 5 for time diff
|
37 |
+
data = BaseDataset2(train_x.reshape(len(train_x), -1) / 32768, train_y)
|
38 |
+
|
39 |
+
#compute the 10 dimensional embeding vector
|
40 |
+
embedding10d = reducer.transform(data)
|
41 |
+
|
42 |
+
# prediction = cluster_som.predict(embedding10d)
|
43 |
+
fig = cluster.plot_activation_v2(embedding10d, slice_select)
|
44 |
+
plt.savefig('test.png')
|
45 |
+
return fig
|
46 |
+
|
47 |
+
get_som_mp4('Data-JSON/Dressage/Tempi/Trab/Arbeitstrab/20210906-093200-Don-Arbeitstrab.json', 1)
|