Spaces:
Sleeping
Sleeping
File size: 1,138 Bytes
7f19394 f67aafa 7f19394 46cd050 7f19394 46cd050 7f19394 f67aafa 7f19394 46cd050 7f19394 f67aafa 7f19394 f67aafa |
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 |
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"
@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()
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)
st.markdown("**Generated Time Series**")
fig, ax = plt.subplots(figsize=(8,4))
ax.plot(ts.ravel())
ax.set_ylim([0,4])
st.pyplot(fig) |