sharifIslam commited on
Commit
5d309f7
·
1 Parent(s): f4e460d

Add Python 3.10, fix dependencies, add detailed logging

Browse files
Files changed (4) hide show
  1. README.md +1 -0
  2. app.py +25 -4
  3. model.py +16 -4
  4. requirements.txt +2 -0
README.md CHANGED
@@ -8,6 +8,7 @@ sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: false
10
  license: cc-by-nc-sa-4.0
 
11
  ---
12
 
13
  # Multi-View 3D Reconstruction (MV3DR)
 
8
  app_file: app.py
9
  pinned: false
10
  license: cc-by-nc-sa-4.0
11
+ python_version: 3.10
12
  ---
13
 
14
  # Multi-View 3D Reconstruction (MV3DR)
app.py CHANGED
@@ -2,30 +2,51 @@ import os
2
  import sys
3
  import torch
4
  import subprocess
 
 
 
 
 
 
 
 
5
 
6
  if not os.path.exists('dust3r/.git'):
7
- print("Initializing dust3r submodule...")
8
  subprocess.run(['git', 'submodule', 'update', '--init', '--recursive'], check=False)
9
 
 
10
  sys.path.append(os.path.join(os.path.dirname(__file__), 'dust3r'))
11
 
 
12
  from model import initialize
 
 
13
  from gradio_ui import build_ui
 
 
14
  from config import WEIGHTS_PATH, OUTPUT_DIR, SERVER_NAME, SERVER_PORT, SHARE, SHOW_ERROR
15
 
16
 
17
  def main():
 
18
  os.makedirs(OUTPUT_DIR, exist_ok=True)
19
 
20
  device = "cuda" if torch.cuda.is_available() else "cpu"
21
- print(f"Using device: {device}")
22
 
23
- print("Loading DUSt3R model...")
 
24
  model = initialize(WEIGHTS_PATH, device)
 
25
 
26
- print("Starting Multi-View 3D Reconstruction (MV3DR)...")
27
  app = build_ui(OUTPUT_DIR, model, device)
 
 
 
28
  app.launch()
 
29
 
30
 
31
  if __name__ == "__main__":
 
2
  import sys
3
  import torch
4
  import subprocess
5
+ import logging
6
+
7
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
8
+ logger = logging.getLogger(__name__)
9
+
10
+ logger.info("="*50)
11
+ logger.info("Starting MV3DR Application")
12
+ logger.info("="*50)
13
 
14
  if not os.path.exists('dust3r/.git'):
15
+ logger.info("Initializing dust3r submodule...")
16
  subprocess.run(['git', 'submodule', 'update', '--init', '--recursive'], check=False)
17
 
18
+ logger.info("Adding dust3r to Python path...")
19
  sys.path.append(os.path.join(os.path.dirname(__file__), 'dust3r'))
20
 
21
+ logger.info("Importing model initialization module...")
22
  from model import initialize
23
+
24
+ logger.info("Importing UI builder...")
25
  from gradio_ui import build_ui
26
+
27
+ logger.info("Importing configuration...")
28
  from config import WEIGHTS_PATH, OUTPUT_DIR, SERVER_NAME, SERVER_PORT, SHARE, SHOW_ERROR
29
 
30
 
31
  def main():
32
+ logger.info("Creating output directory...")
33
  os.makedirs(OUTPUT_DIR, exist_ok=True)
34
 
35
  device = "cuda" if torch.cuda.is_available() else "cpu"
36
+ logger.info(f"Using device: {device}")
37
 
38
+ logger.info("Loading DUSt3R model...")
39
+ logger.info(f"Model weights path: {WEIGHTS_PATH}")
40
  model = initialize(WEIGHTS_PATH, device)
41
+ logger.info("Model loaded successfully!")
42
 
43
+ logger.info("Building Gradio UI...")
44
  app = build_ui(OUTPUT_DIR, model, device)
45
+ logger.info("UI built successfully!")
46
+
47
+ logger.info("Launching application...")
48
  app.launch()
49
+ logger.info("Application started!")
50
 
51
 
52
  if __name__ == "__main__":
model.py CHANGED
@@ -1,11 +1,17 @@
1
  import torch
2
- from dust3r.model import AsymmetricCroCo3DStereo, inf
 
 
 
3
 
4
 
5
  def initialize(model_path: str, device: str) -> torch.nn.Module:
6
- print(f"Loading model from: {model_path}")
 
 
7
  ckpt = torch.load(model_path, map_location='cpu', weights_only=False)
8
 
 
9
  args = ckpt['args'].model.replace("ManyAR_PatchEmbed", "PatchEmbedDust3R")
10
 
11
  if 'landscape_only' not in args:
@@ -13,8 +19,14 @@ def initialize(model_path: str, device: str) -> torch.nn.Module:
13
  else:
14
  args = args.replace(" ", "").replace('landscape_only=True', 'landscape_only=False')
15
 
 
16
  net = eval(args)
 
 
17
  net.load_state_dict(ckpt['model'], strict=False)
18
 
19
- print(f"Model loaded successfully on {device}")
20
- return net.to(device)
 
 
 
 
1
  import torch
2
+ import logging
3
+ from dust3r.model import AsymmetricCroCo3DStereo
4
+
5
+ logger = logging.getLogger(__name__)
6
 
7
 
8
  def initialize(model_path: str, device: str) -> torch.nn.Module:
9
+ logger.info(f"Loading model from: {model_path}")
10
+
11
+ logger.info("Loading checkpoint...")
12
  ckpt = torch.load(model_path, map_location='cpu', weights_only=False)
13
 
14
+ logger.info("Parsing model arguments...")
15
  args = ckpt['args'].model.replace("ManyAR_PatchEmbed", "PatchEmbedDust3R")
16
 
17
  if 'landscape_only' not in args:
 
19
  else:
20
  args = args.replace(" ", "").replace('landscape_only=True', 'landscape_only=False')
21
 
22
+ logger.info("Instantiating model...")
23
  net = eval(args)
24
+
25
+ logger.info("Loading model weights...")
26
  net.load_state_dict(ckpt['model'], strict=False)
27
 
28
+ logger.info(f"Moving model to {device}...")
29
+ model = net.to(device)
30
+
31
+ logger.info("Model initialization complete!")
32
+ return model
requirements.txt CHANGED
@@ -11,3 +11,5 @@ pillow
11
  tqdm
12
  numpy
13
  opencv-python
 
 
 
11
  tqdm
12
  numpy
13
  opencv-python
14
+ pydub
15
+ ffmpeg-python