File size: 1,450 Bytes
7f19394
 
 
f67aafa
7f19394
 
 
 
 
bc73fb3
 
 
7f19394
46cd050
 
bc73fb3
46cd050
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f19394
46cd050
7f19394
bc73fb3
 
 
 
 
 
7f19394
bc73fb3
7f19394
bc73fb3
 
f67aafa
bc73fb3
f67aafa
bc73fb3
 
 
 
 
 
7f19394
bc73fb3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import numpy as np
import streamlit as st
import torch
import matplotlib.pyplot as plt

import disvae
import transforms as trans

P_MODEL = "model/drilling_ds_btcvae"
SAMPLING_TIME = 0.15

st.set_page_config(page_title="Drilling VAE")

@st.cache_resource
def load_decode_function():
    
    sorter = trans.LatentSorter(disvae.get_kl_dict(P_MODEL))
    vae = disvae.load_model(P_MODEL)
    scaler = trans.MinMaxScaler(_min=torch.tensor([1.3]),_max=torch.tensor([4.0]),min_norm=0.3,max_norm=0.6)
    imaging = trans.SumField()

    _dec = trans.sequential_function(
        sorter.inv,
        vae.decoder,
        scaler.inv,
        imaging.inv
    )

    def decode(latent):
        with torch.no_grad():
            return trans.np_sample(_dec)(latent)
    
    return decode
    
decode = load_decode_function()

col1,col2 = st.columns(2)

with col1:
    st.markdown("**Latent Space Parameters**")
    latent_vector = np.array([st.slider(f"Latent Dimension {l}",min_value=-3.0,max_value=3.0,value=0.0) for l in range(3)])
    latent_vector = np.concatenate([latent_vector,np.zeros(7)],axis=0)

    ts = decode(latent_vector)

with col2:
    st.markdown("**Generated Time Series**")

    fig, ax = plt.subplots(figsize=(4,3))

    time = np.arange(0,len(ts)*SAMPLING_TIME,SAMPLING_TIME)
    ax.plot(time,ts.ravel())
    ax.set_xlabel("Time t [s]")
    ax.set_ylabel("Spindle torque t [Nm]")
    ax.set_ylim([0,4])
    ax.grid()

    st.pyplot(fig)