9
9
import os
10
10
import random
11
11
import numpy as np
12
- import copy
13
12
from PIL import Image
14
13
15
14
import torch
16
15
import torch .utils .data as data
17
16
from torchvision import transforms
18
17
19
- import augly .image as imaugs
20
-
21
-
22
18
def pil_loader (path ):
23
19
with open (path , 'rb' ) as f :
24
20
with Image .open (f ) as img :
@@ -71,8 +67,6 @@ def __init__(self,
71
67
self .resize [i ] = transforms .Resize ((self .height // s , self .width // s ),
72
68
interpolation = self .interp )
73
69
74
- self .load_depth = self .check_depth ()
75
-
76
70
self .mapping = {'l' :'0' , 'r' :'1' }
77
71
self .rev_mapping = {'l' :'1' , 'r' :'0' }
78
72
@@ -128,32 +122,16 @@ def __getitem__(self, index):
128
122
129
123
do_color_aug = self .is_train and random .random () > 0.5
130
124
do_flip = self .is_train and random .random () > 0.5
131
- do_encoding = self .is_train and random .random () > 0.5
132
125
133
126
line = self .filenames [index ].split ()
134
127
folder = line [0 ]
135
128
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
-
146
129
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 ' )
149
132
inputs [("color" , i , - 1 )] = self .get_color (path , do_flip )
150
133
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" )
157
135
158
136
# adjusting intrinsics to match each scale in the pyramid
159
137
for scale in range (self .num_scales ):
@@ -178,7 +156,6 @@ def __getitem__(self, index):
178
156
else :
179
157
color_aug = (lambda x : x )
180
158
181
-
182
159
self .preprocess (inputs , color_aug )
183
160
184
161
for i in self .frame_idxs :
@@ -187,26 +164,16 @@ def __getitem__(self, index):
187
164
188
165
#if it's not training (testing time), load the gt depth for calculating the error
189
166
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 )
191
169
depth_gt = self .get_depth (path , do_flip )
192
170
inputs ["depth_gt" ] = np .expand_dims (depth_gt , 0 )
193
171
inputs ["depth_gt" ] = torch .from_numpy (inputs ["depth_gt" ].astype (np .float32 ))
194
172
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
-
203
173
return inputs
204
174
205
175
def get_color (self , folder , frame_index , side , do_flip ):
206
176
raise NotImplementedError
207
177
208
- def check_depth (self ):
209
- raise NotImplementedError
210
-
211
178
def get_depth (self , folder , frame_index , side , do_flip ):
212
179
raise NotImplementedError
0 commit comments