hassiahk commited on
Commit
0071656
1 Parent(s): a8a560e

UI Changes

Browse files
Files changed (2) hide show
  1. .gitignore +2 -1
  2. app.py +44 -34
.gitignore CHANGED
@@ -1,3 +1,4 @@
1
  .idea
2
  __pycache__
3
- models
 
 
1
  .idea
2
  __pycache__
3
+ models
4
+ .vscode
app.py CHANGED
@@ -3,35 +3,37 @@ import builtins
3
  import math
4
  import streamlit as st
5
  import gdown
6
- #from google_drive_downloader import GoogleDriveDownloader as gdd
 
7
 
8
  from demo.src.models import load_trained_model
9
  from demo.src.utils import render_predict_from_pose, predict_to_image
10
- #from demo.src.config import MODEL_DIR, MODEL_NAME, FILE_ID
 
11
 
12
  st.set_page_config(page_title="DietNeRF")
13
 
 
14
  def select_model():
15
- obj_select = st.selectbox("Select an object to render", ('Chair', 'Lego','Ship','Hotdog'))
16
- if obj_select == 'Chair':
17
  FILE_ID = "17dj0pQieo94TozFv-noSBkXebduij1aM"
18
- MODEL_DIR = 'models'
19
- MODEL_NAME = 'diet_nerf_chair'
20
- elif obj_select == 'Lego':
21
  FILE_ID = "1D9I-qIVMPaxuCHfUWPWMHaoLYtAmCjwI"
22
- MODEL_DIR = 'models'
23
- MODEL_NAME = 'diet_nerf_lego'
24
- elif obj_select == 'Ship':
25
  FILE_ID = "14ZeJ86ETQr8dtu6CFoxU-ifvniHKo_Dt"
26
- MODEL_DIR = 'models'
27
- MODEL_NAME = 'diet_nerf_ship'
28
- elif obj_select == 'Hotdog':
29
  FILE_ID = "11vNlR4lMvV_AVFgVjZmKMrMWGVG7qhNu"
30
- MODEL_DIR = 'models'
31
- MODEL_NAME = 'diet_nerf_hotdog'
32
- return MODEL_DIR,MODEL_NAME,FILE_ID
33
 
34
- MODEL_DIR,MODEL_NAME,FILE_ID = select_model()
35
 
36
  @st.cache
37
  def download_model():
@@ -40,9 +42,9 @@ def download_model():
40
  # gdd.download_file_from_google_drive(file_id=FILE_ID,
41
  # dest_path=_model_path,
42
  # unzip=True)
43
- url = f'https://drive.google.com/uc?id={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)
@@ -58,26 +60,34 @@ if not os.path.isfile(model_path):
58
  model, state = fetch_model()
59
  pi = math.pi
60
  st.sidebar.image("images/diet-nerf.png", width=310)
61
- st.sidebar.header('SELECT YOUR VIEW DIRECTION')
62
- theta = st.sidebar.slider("Theta", min_value=-pi, max_value=pi,
63
- step=0.5, value=0.)
64
- phi = st.sidebar.slider("Phi", min_value=0., max_value=0.5*pi,
65
- step=0.1, value=1.)
66
- radius = st.sidebar.slider("Radius", min_value=2., max_value=6.,
67
- step=1., value=3.)
68
-
69
- caption = "Diet-NeRF achieves SoTA few-shot learning capacity in 3D model reconstruction. " \
70
- "Thanks to the 2D supervision by CLIP (aka semantic loss), " \
71
- "it can render novel and challenging views with ONLY 8 training images, " \
72
- "outperforming original NeRF!"
73
- st.markdown(f""" <h4> {caption} </h4> """,
74
- unsafe_allow_html=True)
 
 
 
 
 
 
 
 
75
  st.markdown("")
76
 
77
  with st.spinner("Rendering Image, it may take 2-3 mins. So, why don't you read our report in the meantime"):
78
  pred_color, _ = render_predict_from_pose(state, theta, phi, radius)
79
  im = predict_to_image(pred_color)
80
  w, _ = im.size
81
- new_w = int(2*w)
82
  im = im.resize(size=(new_w, new_w))
83
  st.image(im, use_column_width=True)
 
3
  import math
4
  import streamlit as st
5
  import gdown
6
+
7
+ # from google_drive_downloader import GoogleDriveDownloader as gdd
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
+ # from demo.src.config import MODEL_DIR, MODEL_NAME, FILE_ID
13
 
14
  st.set_page_config(page_title="DietNeRF")
15
 
16
+
17
  def select_model():
18
+ obj_select = st.selectbox("Select an object to render", ("Chair", "Lego", "Ship", "Hotdog"))
19
+ if obj_select == "Chair":
20
  FILE_ID = "17dj0pQieo94TozFv-noSBkXebduij1aM"
21
+ MODEL_DIR = "models"
22
+ MODEL_NAME = "diet_nerf_chair"
23
+ elif obj_select == "Lego":
24
  FILE_ID = "1D9I-qIVMPaxuCHfUWPWMHaoLYtAmCjwI"
25
+ MODEL_DIR = "models"
26
+ MODEL_NAME = "diet_nerf_lego"
27
+ elif obj_select == "Ship":
28
  FILE_ID = "14ZeJ86ETQr8dtu6CFoxU-ifvniHKo_Dt"
29
+ MODEL_DIR = "models"
30
+ MODEL_NAME = "diet_nerf_ship"
31
+ elif obj_select == "Hotdog":
32
  FILE_ID = "11vNlR4lMvV_AVFgVjZmKMrMWGVG7qhNu"
33
+ MODEL_DIR = "models"
34
+ MODEL_NAME = "diet_nerf_hotdog"
35
+ return MODEL_DIR, MODEL_NAME, FILE_ID
36
 
 
37
 
38
  @st.cache
39
  def download_model():
 
42
  # gdd.download_file_from_google_drive(file_id=FILE_ID,
43
  # dest_path=_model_path,
44
  # unzip=True)
45
+ url = f"https://drive.google.com/uc?id={FILE_ID}"
46
  gdown.download(url, _model_path, quiet=False)
47
+ print(f"Model downloaded from google drive: {_model_path}")
48
 
49
 
50
  @st.cache(show_spinner=False, allow_output_mutation=True)
 
60
  model, state = fetch_model()
61
  pi = math.pi
62
  st.sidebar.image("images/diet-nerf.png", width=310)
63
+ st.sidebar.header("SELECT YOUR VIEW DIRECTION")
64
+ theta = st.sidebar.slider(
65
+ "Theta", min_value=-pi, max_value=pi, step=0.5, value=0.0, help="Rotational angle in Horizontal direction"
66
+ )
67
+ phi = st.sidebar.slider(
68
+ "Phi", min_value=0.0, max_value=0.5 * pi, step=0.1, value=1.0, help="Rotational angle in Vertical direction"
69
+ )
70
+ radius = st.sidebar.slider(
71
+ "Radius", min_value=2.0, max_value=6.0, step=1.0, value=3.0, help="Distance between object and the viewer"
72
+ )
73
+
74
+ st.title("DietNeRF")
75
+ caption = (
76
+ "Diet-NeRF achieves SoTA few-shot learning capacity in 3D model reconstruction. "
77
+ "Thanks to the 2D supervision by CLIP (aka semantic loss), "
78
+ "it can render novel and challenging views with ONLY 8 training images, "
79
+ "outperforming original NeRF!"
80
+ )
81
+ st.markdown(caption)
82
+ st.markdown("")
83
+ MODEL_DIR, MODEL_NAME, FILE_ID = select_model()
84
+
85
  st.markdown("")
86
 
87
  with st.spinner("Rendering Image, it may take 2-3 mins. So, why don't you read our report in the meantime"):
88
  pred_color, _ = render_predict_from_pose(state, theta, phi, radius)
89
  im = predict_to_image(pred_color)
90
  w, _ = im.size
91
+ new_w = int(2 * w)
92
  im = im.resize(size=(new_w, new_w))
93
  st.image(im, use_column_width=True)