Sohaib36 commited on
Commit
e5f4906
1 Parent(s): e502daa

add: adding nyu model

Browse files
Files changed (1) hide show
  1. app.py +30 -28
app.py CHANGED
@@ -15,43 +15,46 @@ torch.set_grad_enabled(False)
15
  # "anhquancao/monoscene_kitti", trust_remote_code=True, revision='bf033f87c2a86b60903ab811b790a1532c1ae313'
16
  # )#.cuda()
17
  model = MonoScene.load_from_checkpoint(
18
- "monoscene_kitti.ckpt",
19
- dataset="kitti",
20
- n_classes=20,
21
- feature = 64,
22
- project_scale = 2,
23
- full_scene_size = (256, 256, 32),
24
- )
25
 
26
- img_W, img_H = 1220, 370
27
 
28
 
29
  def predict(img):
30
  img = np.array(img, dtype=np.float32, copy=False) / 255.0
31
 
32
  normalize_rgb = transforms.Compose(
33
- [
34
- transforms.ToTensor(),
35
- transforms.Normalize(
36
- mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
37
- ),
38
- ]
39
- )
40
  img = normalize_rgb(img)
41
-
42
  batch = get_projections(img_W, img_H)
43
  batch["img"] = img
44
  for k in batch:
45
- batch[k] = batch[k].unsqueeze(0)#.cuda()
46
 
47
  pred = model(batch).squeeze()
48
- # print(pred.shape)
49
- pred = majority_pooling(pred, k_size=2)
50
- fig = draw(pred, batch['fov_mask_2'])
51
-
 
 
 
 
52
 
53
  return fig
54
-
55
 
56
  description = """
57
  MonoScene Demo on SemanticKITTI Validation Set (Sequence 08), which uses the <b>camera parameters of Sequence 08</b>.
@@ -66,7 +69,7 @@ The output is <b>downsampled by 2</b> for faster rendering. <b>Darker</b> colors
66
  </center>
67
  """
68
  title = "MonoScene: Monocular 3D Semantic Scene Completion"
69
- article="""
70
  <center>
71
  We also released a <b>smaller</b> MonoScene model (Half resolution - w/o 3D CRP) at: <a href="https://huggingface.co/spaces/CVPR/monoscene_lite">https://huggingface.co/spaces/CVPR/monoscene_lite</a>
72
  <img src='https://visitor-badge.glitch.me/badge?page_id=anhquancao.MonoScene&left_color=darkmagenta&right_color=purple' alt='visitor badge'>
@@ -110,11 +113,10 @@ examples = [
110
  ]
111
 
112
 
113
-
114
  demo = gr.Interface(
115
- predict,
116
- gr.Image(shape=(1220, 370)),
117
- gr.Plot(),
118
  article=article,
119
  title=title,
120
  enable_queue=True,
@@ -124,4 +126,4 @@ demo = gr.Interface(
124
  description=description)
125
 
126
 
127
- demo.launch(enable_queue=True, debug=False)
 
15
  # "anhquancao/monoscene_kitti", trust_remote_code=True, revision='bf033f87c2a86b60903ab811b790a1532c1ae313'
16
  # )#.cuda()
17
  model = MonoScene.load_from_checkpoint(
18
+ "monoscene_nyu.ckpt",
19
+ dataset="NYU",
20
+ feature=200,
21
+ project_scale=1,
22
+ full_scene_size=(60, 36, 60),
23
+ )
 
24
 
25
+ img_W, img_H = 640, 480
26
 
27
 
28
  def predict(img):
29
  img = np.array(img, dtype=np.float32, copy=False) / 255.0
30
 
31
  normalize_rgb = transforms.Compose(
32
+ [
33
+ transforms.ToTensor(),
34
+ transforms.Normalize(
35
+ mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
36
+ ),
37
+ ]
38
+ )
39
  img = normalize_rgb(img)
40
+
41
  batch = get_projections(img_W, img_H)
42
  batch["img"] = img
43
  for k in batch:
44
+ batch[k] = batch[k].unsqueeze(0) # .cuda()
45
 
46
  pred = model(batch).squeeze()
47
+ y_pred = torch.softmax(pred["ssc_logit"], dim=1).detach().cpu().numpy()
48
+ cam_pose = np.asarray([[ 9.6699458e-01, 4.2662762e-02, 2.5120059e-01, 0.0000000e+00],
49
+ [-2.5147417e-01, 1.0867463e-03, 9.6786356e-01, 0.0000000e+00],
50
+ [ 4.1018680e-02, -9.9908894e-01, 1.1779292e-02, 1.1794727e+00],
51
+ [ 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 1.0000000e+00]])
52
+ vox_origin = np.array([-1.54591799, 0.8907361 , -0.05 ])
53
+
54
+ fig = draw(y_pred.squeeze(),cam_pose, vox_origin)
55
 
56
  return fig
57
+
58
 
59
  description = """
60
  MonoScene Demo on SemanticKITTI Validation Set (Sequence 08), which uses the <b>camera parameters of Sequence 08</b>.
 
69
  </center>
70
  """
71
  title = "MonoScene: Monocular 3D Semantic Scene Completion"
72
+ article = """
73
  <center>
74
  We also released a <b>smaller</b> MonoScene model (Half resolution - w/o 3D CRP) at: <a href="https://huggingface.co/spaces/CVPR/monoscene_lite">https://huggingface.co/spaces/CVPR/monoscene_lite</a>
75
  <img src='https://visitor-badge.glitch.me/badge?page_id=anhquancao.MonoScene&left_color=darkmagenta&right_color=purple' alt='visitor badge'>
 
113
  ]
114
 
115
 
 
116
  demo = gr.Interface(
117
+ predict,
118
+ gr.Image(shape=(1220, 370)),
119
+ gr.Plot(),
120
  article=article,
121
  title=title,
122
  enable_queue=True,
 
126
  description=description)
127
 
128
 
129
+ demo.launch(enable_queue=True, debug=False)