Spaces:
Build error
Build error
Code refactoring
Browse files- app.py +11 -14
- config.json +10 -5
app.py
CHANGED
@@ -6,55 +6,52 @@ import json
|
|
6 |
import streamlit as st
|
7 |
import gdown
|
8 |
|
9 |
-
# from google_drive_downloader import GoogleDriveDownloader as gdd
|
10 |
-
|
11 |
from demo.src.models import load_trained_model
|
12 |
from demo.src.utils import render_predict_from_pose, predict_to_image
|
13 |
|
14 |
-
# from demo.src.config import MODEL_DIR, MODEL_NAME, FILE_ID
|
15 |
-
|
16 |
st.set_page_config(page_title="DietNeRF")
|
17 |
|
18 |
with open("config.json") as f:
|
19 |
cfg = json.loads(f.read())
|
20 |
|
|
|
|
|
21 |
|
22 |
def select_model():
|
23 |
obj_select = st.selectbox("Select a Scene", ("Mic", "Chair", "Lego", "Ship", "Hotdog"))
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
return MODEL_DIR, MODEL_NAME, FILE_ID
|
28 |
|
29 |
|
30 |
st.title("DietNeRF")
|
31 |
caption = (
|
32 |
"DietNeRF achieves SoTA few-shot learning capacity in 3D model reconstruction. "
|
33 |
-
"Thanks to the 2D supervision by CLIP (aka
|
34 |
"it can render novel and challenging views with ONLY 8 training images, "
|
35 |
"outperforming original NeRF!"
|
36 |
)
|
37 |
st.markdown(caption)
|
38 |
st.markdown("")
|
39 |
-
|
40 |
|
41 |
|
42 |
@st.cache(show_spinner=False)
|
43 |
def download_model():
|
44 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
45 |
-
_model_path = os.path.join(MODEL_DIR,
|
46 |
-
url = f"https://drive.google.com/uc?id={
|
47 |
gdown.download(url, _model_path, quiet=False)
|
48 |
print(f"Model downloaded from google drive: {_model_path}")
|
49 |
|
50 |
|
51 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
52 |
def fetch_model():
|
53 |
-
model, state = load_trained_model(MODEL_DIR,
|
54 |
return model, state
|
55 |
|
56 |
|
57 |
-
model_path = os.path.join(MODEL_DIR,
|
58 |
if not os.path.isfile(model_path):
|
59 |
download_model()
|
60 |
|
|
|
6 |
import streamlit as st
|
7 |
import gdown
|
8 |
|
|
|
|
|
9 |
from demo.src.models import load_trained_model
|
10 |
from demo.src.utils import render_predict_from_pose, predict_to_image
|
11 |
|
|
|
|
|
12 |
st.set_page_config(page_title="DietNeRF")
|
13 |
|
14 |
with open("config.json") as f:
|
15 |
cfg = json.loads(f.read())
|
16 |
|
17 |
+
MODEL_DIR = "models"
|
18 |
+
|
19 |
|
20 |
def select_model():
|
21 |
obj_select = st.selectbox("Select a Scene", ("Mic", "Chair", "Lego", "Ship", "Hotdog"))
|
22 |
+
DIET_NERF_MODEL_NAME = cfg[obj_select]["DIET_NERF_MODEL_NAME"]
|
23 |
+
DIET_NERF_FILE_ID = cfg[obj_select]["DIET_NERF_FILE_ID"]
|
24 |
+
return DIET_NERF_MODEL_NAME, DIET_NERF_FILE_ID
|
|
|
25 |
|
26 |
|
27 |
st.title("DietNeRF")
|
28 |
caption = (
|
29 |
"DietNeRF achieves SoTA few-shot learning capacity in 3D model reconstruction. "
|
30 |
+
"Thanks to the 2D supervision by CLIP (aka. _Semantic Consisteny Loss_), "
|
31 |
"it can render novel and challenging views with ONLY 8 training images, "
|
32 |
"outperforming original NeRF!"
|
33 |
)
|
34 |
st.markdown(caption)
|
35 |
st.markdown("")
|
36 |
+
DIET_NERF_MODEL_NAME, DIET_NERF_FILE_ID = select_model()
|
37 |
|
38 |
|
39 |
@st.cache(show_spinner=False)
|
40 |
def download_model():
|
41 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
42 |
+
_model_path = os.path.join(MODEL_DIR, DIET_NERF_MODEL_NAME)
|
43 |
+
url = f"https://drive.google.com/uc?id={DIET_NERF_FILE_ID}"
|
44 |
gdown.download(url, _model_path, quiet=False)
|
45 |
print(f"Model downloaded from google drive: {_model_path}")
|
46 |
|
47 |
|
48 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
49 |
def fetch_model():
|
50 |
+
model, state = load_trained_model(MODEL_DIR, DIET_NERF_MODEL_NAME)
|
51 |
return model, state
|
52 |
|
53 |
|
54 |
+
model_path = os.path.join(MODEL_DIR, DIET_NERF_MODEL_NAME)
|
55 |
if not os.path.isfile(model_path):
|
56 |
download_model()
|
57 |
|
config.json
CHANGED
@@ -1,26 +1,31 @@
|
|
1 |
{
|
2 |
"Chair": {
|
3 |
-
"
|
|
|
4 |
"DIET_NERF_MODEL_NAME": "diet_nerf_chair",
|
5 |
"NERF_MODEL_NAME": "nerf_chair"
|
6 |
},
|
7 |
"Lego": {
|
8 |
-
"
|
|
|
9 |
"DIET_NERF_MODEL_NAME": "diet_nerf_lego",
|
10 |
"NERF_MODEL_NAME": "nerf_lego"
|
11 |
},
|
12 |
"Ship": {
|
13 |
-
"
|
|
|
14 |
"DIET_NERF_MODEL_NAME": "diet_nerf_ship",
|
15 |
"NERF_MODEL_NAME": "nerf_ship"
|
16 |
},
|
17 |
"Hotdog": {
|
18 |
-
"
|
|
|
19 |
"DIET_NERF_MODEL_NAME": "diet_nerf_hotdog",
|
20 |
"NERF_MODEL_NAME": "nerf_hotdog"
|
21 |
},
|
22 |
"Mic": {
|
23 |
-
"
|
|
|
24 |
"DIET_NERF_MODEL_NAME": "diet_nerf_mic",
|
25 |
"NERF_MODEL_NAME": "nerf_mic"
|
26 |
}
|
|
|
1 |
{
|
2 |
"Chair": {
|
3 |
+
"DIET_NERF_FILE_ID": "17dj0pQieo94TozFv-noSBkXebduij1aM",
|
4 |
+
"NERF_FILE_ID": "17dj0pQieo94TozFv-noSBkXebduij1aM",
|
5 |
"DIET_NERF_MODEL_NAME": "diet_nerf_chair",
|
6 |
"NERF_MODEL_NAME": "nerf_chair"
|
7 |
},
|
8 |
"Lego": {
|
9 |
+
"DIET_NERF_FILE_ID": "1UaUKgShJTKp5zNQdXvVhkyxgU-2YU3Ay",
|
10 |
+
"NERF_FILE_ID": "17dj0pQieo94TozFv-noSBkXebduij1aM",
|
11 |
"DIET_NERF_MODEL_NAME": "diet_nerf_lego",
|
12 |
"NERF_MODEL_NAME": "nerf_lego"
|
13 |
},
|
14 |
"Ship": {
|
15 |
+
"DIET_NERF_FILE_ID": "1Eb4eZ9vn6FcbqLIaBoW-6NlyWr-y0eTW",
|
16 |
+
"NERF_FILE_ID": "17dj0pQieo94TozFv-noSBkXebduij1aM",
|
17 |
"DIET_NERF_MODEL_NAME": "diet_nerf_ship",
|
18 |
"NERF_MODEL_NAME": "nerf_ship"
|
19 |
},
|
20 |
"Hotdog": {
|
21 |
+
"DIET_NERF_FILE_ID": "11vNlR4lMvV_AVFgVjZmKMrMWGVG7qhNu",
|
22 |
+
"NERF_FILE_ID": "17dj0pQieo94TozFv-noSBkXebduij1aM",
|
23 |
"DIET_NERF_MODEL_NAME": "diet_nerf_hotdog",
|
24 |
"NERF_MODEL_NAME": "nerf_hotdog"
|
25 |
},
|
26 |
"Mic": {
|
27 |
+
"DIET_NERF_FILE_ID": "1vuyCAY8YKLo7OSlTpLJgMem47gJc1W2S",
|
28 |
+
"NERF_FILE_ID": "17dj0pQieo94TozFv-noSBkXebduij1aM",
|
29 |
"DIET_NERF_MODEL_NAME": "diet_nerf_mic",
|
30 |
"NERF_MODEL_NAME": "nerf_mic"
|
31 |
}
|