Spaces:
Runtime error
Runtime error
lmoss
commited on
Commit
·
a577b73
1
Parent(s):
8c8b3fb
added initial
Browse files- app.py +59 -0
- dcgan.py +50 -0
- requirements.txt +8 -0
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import streamlit.components.v1 as components
|
| 3 |
+
import pyvista as pv
|
| 4 |
+
from pyvista import examples
|
| 5 |
+
import numpy as np
|
| 6 |
+
from dcgan import DCGAN3D_G
|
| 7 |
+
import torch
|
| 8 |
+
import requests
|
| 9 |
+
|
| 10 |
+
url = "https://raw.githubusercontent.com/LukasMosser/PorousMediaGan/raw/master/checkpoints/berea/berea_generator_epoch_24.pth"
|
| 11 |
+
|
| 12 |
+
# If repo is private - we need to add a token in header:
|
| 13 |
+
resp = requests.get(url)
|
| 14 |
+
print(resp.status_code)
|
| 15 |
+
|
| 16 |
+
pv.set_plot_theme("document")
|
| 17 |
+
pl = pv.Plotter(shape=(1, 1),
|
| 18 |
+
window_size=(800, 800))
|
| 19 |
+
|
| 20 |
+
netG = DCGAN3D_G(64, 512, 1, 32, 1)
|
| 21 |
+
netG.load_state_dict(torch.load("./src/berea_generator_epoch_24.pth"))
|
| 22 |
+
z = torch.randn(1, 512, 5, 5, 5)
|
| 23 |
+
with torch.no_grad():
|
| 24 |
+
X = netG(z)
|
| 25 |
+
print(X.size())
|
| 26 |
+
print(X.min(), X.max())
|
| 27 |
+
st.image((X[0, 0, 32].numpy()+1)/2, output_format="png")
|
| 28 |
+
"""
|
| 29 |
+
data = examples.load_channels()
|
| 30 |
+
channels = data.threshold([0.9, 1.1])
|
| 31 |
+
print(channels)
|
| 32 |
+
bodies = channels.split_bodies()
|
| 33 |
+
# Now remove all bodies with a small volume
|
| 34 |
+
for key in bodies.keys():
|
| 35 |
+
b = bodies[key]
|
| 36 |
+
vol = b.volume
|
| 37 |
+
if vol < 1000.0:
|
| 38 |
+
del bodies[key]
|
| 39 |
+
continue
|
| 40 |
+
# Now lets add a volume array to all blocks
|
| 41 |
+
b.cell_data["TOTAL VOLUME"] = np.full(b.n_cells, vol)
|
| 42 |
+
|
| 43 |
+
for i, body in enumerate(bodies):
|
| 44 |
+
print(f"Body {i:02d} volume: {body.volume:.3f}")
|
| 45 |
+
|
| 46 |
+
pl.add_mesh(bodies)
|
| 47 |
+
pl.export_html('pyvista.html')
|
| 48 |
+
|
| 49 |
+
st.header("test html import")
|
| 50 |
+
view_width = 800
|
| 51 |
+
view_height = 800
|
| 52 |
+
HtmlFile = open("pyvista.html", 'r', encoding='utf-8')
|
| 53 |
+
source_code = HtmlFile.read()
|
| 54 |
+
|
| 55 |
+
components.html(source_code, width=view_width, height=view_height)
|
| 56 |
+
|
| 57 |
+
#snippet = embed.embed_snippet(views=view(reader.GetOutput()))
|
| 58 |
+
#html = embed.html_template.format(title="", snippet=snippet)
|
| 59 |
+
#components.html(html, width=view_width, height=view_height)"""
|
dcgan.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch.nn as nn
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class DCGAN3D_G(nn.Module):
|
| 5 |
+
def __init__(self, isize, nz, nc, ngf, ngpu, n_extra_layers=0):
|
| 6 |
+
super(DCGAN3D_G, self).__init__()
|
| 7 |
+
self.ngpu = ngpu
|
| 8 |
+
assert isize % 16 == 0, "isize has to be a multiple of 16"
|
| 9 |
+
|
| 10 |
+
cngf, tisize = ngf // 2, 4
|
| 11 |
+
while tisize != isize:
|
| 12 |
+
cngf = cngf * 2
|
| 13 |
+
tisize = tisize * 2
|
| 14 |
+
|
| 15 |
+
main = nn.Sequential(
|
| 16 |
+
# input is Z, going into a convolution
|
| 17 |
+
nn.ConvTranspose3d(nz, cngf, 4, 1, 0, bias=False),
|
| 18 |
+
nn.BatchNorm3d(cngf),
|
| 19 |
+
nn.ReLU(True),
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
i, csize, cndf = 3, 4, cngf
|
| 23 |
+
while csize < isize // 2:
|
| 24 |
+
main.add_module(str(i),
|
| 25 |
+
nn.ConvTranspose3d(cngf, cngf // 2, 4, 2, 1, bias=False))
|
| 26 |
+
main.add_module(str(i + 1),
|
| 27 |
+
nn.BatchNorm3d(cngf // 2))
|
| 28 |
+
main.add_module(str(i + 2),
|
| 29 |
+
nn.ReLU(True))
|
| 30 |
+
i += 3
|
| 31 |
+
cngf = cngf // 2
|
| 32 |
+
csize = csize * 2
|
| 33 |
+
|
| 34 |
+
# Extra layers
|
| 35 |
+
for t in range(n_extra_layers):
|
| 36 |
+
main.add_module(str(i),
|
| 37 |
+
nn.Conv3d(cngf, cngf, 3, 1, 1, bias=False))
|
| 38 |
+
main.add_module(str(i + 1),
|
| 39 |
+
nn.BatchNorm3d(cngf))
|
| 40 |
+
main.add_module(str(i + 2),
|
| 41 |
+
nn.ReLU(True))
|
| 42 |
+
i += 3
|
| 43 |
+
|
| 44 |
+
main.add_module(str(i),
|
| 45 |
+
nn.ConvTranspose3d(cngf, nc, 4, 2, 1, bias=False))
|
| 46 |
+
main.add_module(str(i + 1), nn.Tanh())
|
| 47 |
+
self.main = main
|
| 48 |
+
|
| 49 |
+
def forward(self, input):
|
| 50 |
+
return self.main(input)
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pyvista
|
| 2 |
+
streamlit
|
| 3 |
+
pythreejs
|
| 4 |
+
matplotlib
|
| 5 |
+
torch==1.10.1+cu113
|
| 6 |
+
torchvision==0.11.2+cu113
|
| 7 |
+
torchaudio==0.10.1+cu113
|
| 8 |
+
-f https://download.pytorch.org/whl/cu113/torch_stable.html
|