SW777SW commited on
Commit
a2a921c
·
verified ·
1 Parent(s): 7b845d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -5
app.py CHANGED
@@ -11,6 +11,9 @@ import subprocess
11
  TMP_DIR = os.path.join(tempfile.gettempdir(), 'gradio')
12
  os.makedirs(TMP_DIR, exist_ok=True)
13
 
 
 
 
14
 
15
  def move_uploaded_files(files, temp_dir):
16
  saved_files = []
@@ -24,14 +27,18 @@ def move_uploaded_files(files, temp_dir):
24
 
25
  def process_images(files):
26
  n_view = len(files)
 
27
  files_str = ','.join([f.name for f in files])
28
- hashdir = hashlib.md5(files_str.encode('utf8')).hexdigest()
29
- hashdir_path = os.path.join(TMP_DIR, hashdir)
30
  hashdir_path_img = os.path.join(hashdir_path, 'images')
31
  os.makedirs(hashdir_path_img, exist_ok=True)
32
  saved_files = move_uploaded_files(files, hashdir_path_img)
33
  saved_files_str = ' '.join(saved_files)
34
 
 
 
 
35
  command = [
36
  "python", "-W", "ignore",
37
  "./coarse_init_infer.py",
@@ -41,11 +48,69 @@ def process_images(files):
41
  ]
42
 
43
  result = subprocess.run(command, capture_output=True, text=True)
44
- result_tree = subprocess.run(["tree", hashdir_path], capture_output=True, text=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  ply_file = os.path.join(hashdir_path, 'sparse/0/', 'points3D.ply')
47
 
48
- return ply_file, result_tree.stdout, result.stdout, result.stderr
49
 
50
  def run():
51
  with gr.Blocks() as demo:
@@ -56,7 +121,7 @@ def run():
56
  # outputs = [gr.Image(type="numpy", label="Processed Images", interactive=False), gr.Video(label="Output Video")]
57
  # outputs = [gr.Textbox(label="Log"), gr.Image(type="filepath", label="Processed Images", interactive=False)]
58
  outputs = [
59
- gr.Model3D(label="3D Model"),
60
  gr.Textbox(label="Output dirs"),
61
  gr.Textbox(label="Log (stdout)"),
62
  gr.Textbox(label="Log (stderr)"),
 
11
  TMP_DIR = os.path.join(tempfile.gettempdir(), 'gradio')
12
  os.makedirs(TMP_DIR, exist_ok=True)
13
 
14
+ gs_train_iter = 1000
15
+ pose_lr = 1x
16
+
17
 
18
  def move_uploaded_files(files, temp_dir):
19
  saved_files = []
 
27
 
28
  def process_images(files):
29
  n_view = len(files)
30
+
31
  files_str = ','.join([f.name for f in files])
32
+ hashdir_name = hashlib.md5(files_str.encode('utf8')).hexdigest()
33
+ hashdir_path = os.path.join(TMP_DIR, hashdir_name)
34
  hashdir_path_img = os.path.join(hashdir_path, 'images')
35
  os.makedirs(hashdir_path_img, exist_ok=True)
36
  saved_files = move_uploaded_files(files, hashdir_path_img)
37
  saved_files_str = ' '.join(saved_files)
38
 
39
+ stdout, stderr, = [], []
40
+
41
+ # ----- (1) Dust3r_coarse_geometric_initialization -----
42
  command = [
43
  "python", "-W", "ignore",
44
  "./coarse_init_infer.py",
 
48
  ]
49
 
50
  result = subprocess.run(command, capture_output=True, text=True)
51
+ stdout.append(result.stdout)
52
+ stderr.append(result.stderr)
53
+
54
+ # ----- (2) Train: jointly optimize pose -----
55
+ # python -W ignore ./train_joint.py \
56
+ # -s ${SOURCE_PATH} \
57
+ # -m ${MODEL_PATH} \
58
+ # --n_views ${N_VIEW} \
59
+ # --scene ${SCENE} \
60
+ # --iter ${gs_train_iter} \
61
+ # --optim_pose \
62
+
63
+ scene = hashdir_name
64
+ model_path = os.path.join(hashdir_path, 'infer', scene, f'{n_view}_views_{gs_train_iter}Iter_{pose_lr}PoseLR')
65
+
66
+ command = [
67
+ "python", "-W", "ignore",
68
+ "./train_joint.py",
69
+ "-s", hashdir_path,
70
+ "-m", model_path,
71
+ "--n_views", str(n_view),
72
+ "--scene", scene,
73
+ "--iter", str(gs_train_iter),
74
+ "--optim_pose",
75
+ ]
76
 
77
+ result = subprocess.run(command, capture_output=True, text=True)
78
+ stdout.append(result.stdout)
79
+ stderr.append(result.stderr)
80
+
81
+ # ----- (3) Render interpolated pose & output video -----
82
+ # python -W ignore ./render_by_interp.py \
83
+ # -s ${SOURCE_PATH} \
84
+ # -m ${MODEL_PATH} \
85
+ # --n_views ${N_VIEW} \
86
+ # --scene ${SCENE} \
87
+ # --iter ${gs_train_iter} \
88
+ # --eval \
89
+ # --get_video
90
+
91
+ command = [
92
+ "python", "-W", "ignore",
93
+ "./render_by_interp.py",
94
+ "-s", hashdir_path,
95
+ "-m", model_path,
96
+ "--n_views", str(n_view),
97
+ "--scene", scene,
98
+ "--iter", str(gs_train_iter),
99
+ "--eval",
100
+ "--get_video",
101
+ ]
102
+
103
+ result = subprocess.run(command, capture_output=True, text=True)
104
+ stdout.append(result.stdout)
105
+ stderr.append(result.stderr)
106
+
107
+ stdout = '\n'.join(stdout)
108
+ stderr = '\n'.join(stderr)
109
+
110
+ result_tree = subprocess.run(["tree", hashdir_path], capture_output=True, text=True)
111
  ply_file = os.path.join(hashdir_path, 'sparse/0/', 'points3D.ply')
112
 
113
+ return result_tree.stdout, stdout, stderr
114
 
115
  def run():
116
  with gr.Blocks() as demo:
 
121
  # outputs = [gr.Image(type="numpy", label="Processed Images", interactive=False), gr.Video(label="Output Video")]
122
  # outputs = [gr.Textbox(label="Log"), gr.Image(type="filepath", label="Processed Images", interactive=False)]
123
  outputs = [
124
+ # gr.Model3D(label="3D Model"),
125
  gr.Textbox(label="Output dirs"),
126
  gr.Textbox(label="Log (stdout)"),
127
  gr.Textbox(label="Log (stderr)"),