Skip to content

Commit d908b71

Browse files
committed
update NYUv2 eval
1 parent abd8fa7 commit d908b71

17 files changed

+155
-138
lines changed

Diff for: IO.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This source code is licensed under the license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
import imageio
78
import os
89
import re
910
import numpy as np
@@ -12,7 +13,7 @@
1213
import numpy as np
1314
from PIL import Image
1415
import sys
15-
import imageio
16+
1617

1718
def read(file):
1819
if file.endswith('.float3'): return readFloat(file)

Diff for: README.md

+39-6
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ Install packages
3131

3232
2. Install pre-requisite common packages. Go to https://pytorch.org/get-started/locally/ and install pytorch that is compatible to your computer. We test on pytorch v1.9.0 and cudatoolkit-11.1. (The codes should work under other v1.0+ versions)
3333

34-
```conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=11.3 -c pytorch -c conda-forge ```
35-
3634
3. Install other dependencies: opencv-python and matplotlib, imageio, Pillow, augly, tensorboardX
3735

3836
``` pip install opencv-python, matplotlib, imageio, Pillow, augly, tensorboardX ```
3937

4038
Download pretrained models
4139

42-
4. Download pretrained models [<a href="https://drive.google.com/file/d/1N3UAeSR5sa7KcMJAeKU961KUNBZ6vIgi/view?usp=sharing">here</a>] (ResNet152, 246MB).
40+
4. Download pretrained models [<a href="https://drive.google.com/file/d/1N3UAeSR5sa7KcMJAeKU961KUNBZ6vIgi/view?usp=sharing">here</a>] (ResNet152, 246MB, illustation for averagely good in-the-wild indoor scenes).
4341

44-
5. Move the downloaded item under this folder, and then unzip it. You should be able to see a new folder 'ckpts' that contains the pretrained models.
42+
5. Unzip under the root. 'ckpts' that contains the pretrained models is created.
4543

4644
6. Run
4745

@@ -87,15 +85,50 @@ Download VA (8G) first. Extract under the root folder.
8785
├── gt_depth_rectify
8886
├── cam0_frame0000.depth.pfm
8987
......
90-
├── VA_left_all.txt
88+
├── VA_left_all.txt
9189

9290
Run ``` bash eval.sh ``` The performances will be saved under the root folder.
9391

94-
To visualize the predicted depth maps,
92+
To visualize the predicted depth maps in a minibatch:
9593

9694
```shell
9795
python execute.py --exe eval_save --log_dir='./tmp' --data_path VA --dataset VA --batch_size 1 --load_weights_folder <path to weights> --models_to_load encoder depth --width 256 --height 256 --max_depth 10 --frame_ids 0 --num_layers 152 ```
9896
```
97+
98+
To visualize the predicted depth maps for all testing data on the list:
99+
100+
```shell
101+
python execute.py --exe eval_save_all --log_dir='./tmp' --data_path VA --dataset VA --batch_size 1 --load_weights_folder <path to weights> --models_to_load encoder depth --width 256 --height 256 --max_depth 10 --frame_ids 0 --num_layers 152 ```
102+
```
103+
104+
Evaluation on NYUv2
105+
106+
Prepare <a href="https://cs.nyu.edu/~silberman/datasets/nyu_depth_v2.html">NYUv2</a> data.
107+
108+
.
109+
├── NYUv2
110+
├── img_val
111+
├── 00001.png
112+
......
113+
├── depth_val
114+
├── 00001.npy
115+
......
116+
......
117+
├── NYUv2.txt
118+
119+
| Name | Arch | Expert | MAE | AbsRel | RMSE | acc@ 1.25 | acc@ 1.25^2 | acc@ 1.25^3 | Download |
120+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
121+
| DistDepth-finetuned | ResNet152 | DPT on NYUv2 | 0.308 | 0.113 | 0.444 | 87.3 | 97.3 | 99.3 | [model](https://drive.google.com/file/d/1kLJBuMOf0xSpYq7DtxnPpBTxMwW0ylGm/view?usp=sharing) |
122+
| DistDepth-SimSIN | ResNet152 | DPT | 0.411 | 0.163 | 0.563 | 78.0 | 93.6 | 98.1 | [model](https://drive.google.com/file/d/1Hf_WPaBGMpPBFymCwmN8Xh1blXXZU1cd/view?usp=sharing) |
123+
124+
Change train_filenames (dummy) and val_filenames in execute_func.py to NYUv2. Then,
125+
126+
```shell
127+
python execute.py --exe eval_measure --log_dir='./tmp' --data_path NYUv2 --dataset NYUv2 --batch_size 1 --load_weights_folder <path to weights> --models_to_load encoder depth --width 256 --height 256 --max_depth 12 --frame_ids 0 --num_layers 152
128+
```
129+
130+
## <div align=""> Visualization</div>
131+
99132
## <div align="">Depth-aware AR effects</div>
100133

101134
Virtual object insertion:

Diff for: datasets/NYUv2base.py

+5-38
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@
99
import os
1010
import random
1111
import numpy as np
12-
import copy
1312
from PIL import Image
1413

1514
import torch
1615
import torch.utils.data as data
1716
from torchvision import transforms
1817

19-
import augly.image as imaugs
20-
21-
2218
def pil_loader(path):
2319
with open(path, 'rb') as f:
2420
with Image.open(f) as img:
@@ -71,8 +67,6 @@ def __init__(self,
7167
self.resize[i] = transforms.Resize((self.height // s, self.width // s),
7268
interpolation=self.interp)
7369

74-
self.load_depth = self.check_depth()
75-
7670
self.mapping = {'l':'0', 'r':'1'}
7771
self.rev_mapping = {'l':'1', 'r':'0'}
7872

@@ -128,32 +122,16 @@ def __getitem__(self, index):
128122

129123
do_color_aug = self.is_train and random.random() > 0.5
130124
do_flip = self.is_train and random.random() > 0.5
131-
do_encoding = self.is_train and random.random() > 0.5
132125

133126
line = self.filenames[index].split()
134127
folder = line[0]
135128

136-
if len(line) == 3:
137-
frame_index = int(line[1])
138-
else:
139-
frame_index = 0
140-
141-
if len(line) == 3:
142-
side = line[2]
143-
else:
144-
side = None
145-
146129
for i in self.frame_idxs:
147-
if i == "s":
148-
path = os.path.join(self.data_path, folder[:-1]+self.rev_mapping[side]+'.jpg')
130+
if i == 0:
131+
path = os.path.join(self.data_path, folder + '.png')
149132
inputs[("color", i, -1)] = self.get_color(path, do_flip)
150133
else:
151-
if not self.is_train:
152-
path = os.path.join(self.data_path, folder+'.jpg')
153-
else:
154-
folder_idx = folder.rsplit('/',1)[0]
155-
path = os.path.join(self.data_path, folder_idx +'/'+ str(frame_index+1*i) + '.jpg')
156-
inputs[("color", i, -1)] = self.get_color(path, do_flip)
134+
raise NotImplementedError("NYUv2 only supports current frame")
157135

158136
# adjusting intrinsics to match each scale in the pyramid
159137
for scale in range(self.num_scales):
@@ -178,7 +156,6 @@ def __getitem__(self, index):
178156
else:
179157
color_aug = (lambda x: x)
180158

181-
182159
self.preprocess(inputs, color_aug)
183160

184161
for i in self.frame_idxs:
@@ -187,26 +164,16 @@ def __getitem__(self, index):
187164

188165
#if it's not training (testing time), load the gt depth for calculating the error
189166
if not self.is_train:
190-
path = os.path.join(self.data_path, folder+'.png')
167+
gt_folder = f'{folder}.npy'.replace('img','depth')
168+
path = os.path.join(self.data_path, gt_folder)
191169
depth_gt = self.get_depth(path, do_flip)
192170
inputs["depth_gt"] = np.expand_dims(depth_gt, 0)
193171
inputs["depth_gt"] = torch.from_numpy(inputs["depth_gt"].astype(np.float32))
194172

195-
if "s" in self.frame_idxs:
196-
stereo_T = np.eye(4, dtype=np.float32)
197-
baseline_sign = -1 if do_flip else 1
198-
side_sign = -1 if side == "l" else 1
199-
stereo_T[0, 3] = side_sign * baseline_sign * 0.1
200-
201-
inputs["stereo_T"] = torch.from_numpy(stereo_T)
202-
203173
return inputs
204174

205175
def get_color(self, folder, frame_index, side, do_flip):
206176
raise NotImplementedError
207177

208-
def check_depth(self):
209-
raise NotImplementedError
210-
211178
def get_depth(self, folder, frame_index, side, do_flip):
212179
raise NotImplementedError

Diff for: datasets/NYUv2dataset.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
from __future__ import absolute_import, division, print_function
88

9-
import cv2
10-
import h5py
119
import numpy as np
1210
import os
1311
import PIL.Image as pil
14-
import skimage.transform
1512

1613
from .NYUv2base import NYUv2Base
1714

@@ -24,29 +21,26 @@ def __init__(self, *args, **kwargs):
2421
[0, 0, 0, 1]], dtype=np.float32)
2522

2623
width, height = 640, 480
27-
new_width, new_height = 608, 448 #448, 448
24+
new_width, new_height = 608, 448
2825
self.left = (width - new_width)//2
2926
self.top = (height - new_height)//2
3027
self.right = (width + new_width)//2
3128
self.bottom = (height + new_height)//2
3229

33-
self.full_res_shape = (640, 480)
34-
35-
def check_depth(self):
36-
return True
37-
3830
def get_color(self, path, do_flip):
3931
color = self.loader(path)
32+
4033
# center crop
41-
#color = color.crop((self.left, self.top, self.right , self.bottom))
34+
color = color.crop((self.left, self.top, self.right , self.bottom))
4235
if do_flip:
4336
color = color.transpose(pil.FLIP_LEFT_RIGHT)
4437
return color
4538

4639
def get_depth(self, path, do_flip):
4740
depth_path = os.path.join(path)
48-
depth_gt = cv2.imread(depth_path,-1)#[::2,::2]
49-
depth_gt = depth_gt[16:-16, 16:-16] # the calculation is different for PIL and numpy indexing
41+
depth_gt = np.load(depth_path)
42+
depth_gt = depth_gt[self.top:self.bottom, self.left:self.right]
5043
if do_flip:
5144
depth_gt = np.fliplr(depth_gt)
45+
5246
return depth_gt

Diff for: datasets/SimSINbase.py

-8
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,17 @@
99
import os
1010
import random
1111
import numpy as np
12-
import copy
1312
from PIL import Image
1413

1514
import torch
1615
import torch.utils.data as data
1716
from torchvision import transforms
18-
import torch.nn.functional as F
19-
import augly.image as imaugs
20-
2117

2218
def pil_loader(path):
2319
with open(path, 'rb') as f:
2420
with Image.open(f) as img:
2521
return img.convert('RGB')
2622

27-
2823
class SimSINBase(data.Dataset):
2924
def __init__(self,
3025
data_path,
@@ -198,8 +193,5 @@ def __getitem__(self, index):
198193
def get_color(self, folder, frame_index, side, do_flip):
199194
raise NotImplementedError
200195

201-
def check_depth(self):
202-
raise NotImplementedError
203-
204196
def get_depth(self, folder, frame_index, side, do_flip):
205197
raise NotImplementedError

Diff for: datasets/SimSINdataset.py

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ def __init__(self, *args, **kwargs):
2828

2929
self.full_res_shape = (512, 512)
3030

31-
def check_depth(self):
32-
return True
33-
3431
def get_color(self, path, do_flip):
3532
color = self.loader(path)
3633
if do_flip:

Diff for: datasets/UniSINbase.py

-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
import os
1010
import random
1111
import numpy as np
12-
import copy
1312
from PIL import Image
1413

1514
import torch
1615
import torch.utils.data as data
1716
from torchvision import transforms
1817

19-
import augly.image as imaugs
20-
2118

2219
def pil_loader(path):
2320
with open(path, 'rb') as f:
@@ -71,8 +68,6 @@ def __init__(self,
7168
self.resize[i] = transforms.Resize((self.height // s, self.width // s),
7269
interpolation=self.interp)
7370

74-
self.load_depth = self.check_depth()
75-
7671
self.mapping = {'l':'0', 'r':'1'}
7772
self.rev_mapping = {'l':'1', 'r':'0'}
7873

@@ -195,8 +190,5 @@ def __getitem__(self, index):
195190
def get_color(self, folder, frame_index, side, do_flip):
196191
raise NotImplementedError
197192

198-
def check_depth(self):
199-
raise NotImplementedError
200-
201193
def get_depth(self, folder, frame_index, side, do_flip):
202194
raise NotImplementedError

Diff for: datasets/UniSINdataset.py

-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
from __future__ import absolute_import, division, print_function
88

9-
import cv2
10-
import h5py
119
import numpy as np
1210
import os
1311
import PIL.Image as pil
14-
import skimage.transform
1512

1613
from .UniSINbase import UniSINBase
1714
from IO import read
@@ -29,21 +26,16 @@ def __init__(self, *args, **kwargs):
2926

3027
self.full_res_shape = (1280, 720)
3128

32-
def check_depth(self):
33-
return True
34-
3529
def get_color(self, path, do_flip):
3630
color = self.loader(path)
3731

3832
if do_flip:
3933
color = color.transpose(pil.FLIP_LEFT_RIGHT)
40-
4134
return color
4235

4336
def get_depth(self, path, do_flip):
4437
depth_path = os.path.join(path)
4538
depth_gt = read(depth_path)
4639
if do_flip:
4740
depth_gt = np.fliplr(depth_gt)
48-
4941
return depth_gt

Diff for: datasets/VAbase.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
import os
1010
import random
1111
import numpy as np
12-
import copy
13-
from PIL import Image # using pillow-simd for increased speed
12+
from PIL import Image
1413

1514
import torch
1615
import torch.utils.data as data
1716
from torchvision import transforms
18-
import augly.image as imaugs
1917

2018

2119
def pil_loader(path):

Diff for: datasets/VAdataset.py

-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
from __future__ import absolute_import, division, print_function
88

99
import cv2
10-
import h5py
1110
import numpy as np
1211
import os
1312
import PIL.Image as pil
14-
import skimage.transform
1513

1614
from .VAbase import VABase
1715

@@ -38,7 +36,6 @@ def get_color(self, path, do_flip):
3836

3937
if do_flip:
4038
color = color.transpose(pil.FLIP_LEFT_RIGHT)
41-
4239
return color
4340

4441
def get_depth(self, path, do_flip):
@@ -47,5 +44,4 @@ def get_depth(self, path, do_flip):
4744
depth_gt = cv2.imread(depth_path, cv2.IMREAD_UNCHANGED)
4845
if do_flip:
4946
depth_gt = np.fliplr(depth_gt)
50-
5147
return depth_gt

0 commit comments

Comments
 (0)