def get_rgb_paths(split, category, modifier=''): """Reads a file containing a list of .npz files on which to run inference.""" t = time.time() ensure_split_valid(split) ensure_category_valid(category) path = ('/ROOT_DIR/%s-%s%s.txt') % (category, split, modifier) try: files = file_util.readlines(path) except: raise ValueError('Failed to read filelist %s' % path) tf.logging.info('Time loading filelist %0.2f', (time.time() - t)) return files
def get_npz_paths(split, category, modifier=''): """Returns the list of npz paths for the split's ground truth.""" t = time.time() ensure_split_valid(split) filelist = os.path.join( path_util.get_path_to_ldif_root(), 'data/basedirs/%s-%s%s.txt' % (split, category, modifier)) try: filenames = file_util.readlines(filelist) except: raise ValueError('Unable to read filelist %s.' % filelist) tf.logging.info('Loaded filelist in %0.2fms.', (time.time() - t)) return filenames
def read_cam_file(path, verbose=False): """Reads a GAPS .cam file to 4x4 matrices. Args: path: filepath to a gaps .cam file with K cameras. verbose: Boolean. Whether to print detailed file info. Returns: cam2world: Numpy array with shape [K, 4, 4]. xfov: Numpy array with shape [K]. The x field-of-view in GAPS' format (which is the half-angle in radians). """ lines = file_util.readlines(path) if verbose: log.info('There are %i cameras in %s.' % (len(lines), path)) cam2worlds, xfovs = [], [] for i, l in enumerate(lines): vals = [float(x) for x in l.split(' ') if x] if len(vals) != 12: raise ValueError( 'Failed reading %s: Expected 12 items on line %i, but read %i.' % (path, i, len(vals))) viewpoint = np.array(vals[0:3]).astype(np.float32) towards = np.array(vals[3:6]).astype(np.float32) up = np.array(vals[6:9]).astype(np.float32) right = np.cross(towards, up) right = right / np.linalg.norm(right) xfov = vals[9] # 11th is yfov but GAPS ignores it and recomputes. # 12th is a 'score' that is irrelevant. towards = towards / np.linalg.norm(towards) up = np.cross(right, towards) up = up / np.linalg.norm(up) # aspect = float(height) / float(width) # yf = math.atan(aspect * math.tan(xfov)) rotation = np.stack([right, up, -towards], axis=1) rotation_4x4 = np.eye(4) rotation_4x4[:3, :3] = rotation cam2world = rotation_4x4.copy() cam2world[:3, 3] = viewpoint cam2worlds.append(cam2world) xfovs.append(xfov) cam2worlds = np.stack(cam2worlds, axis=0).astype(np.float32) xfovs = np.array(xfovs, dtype=np.float32) return cam2worlds, xfovs
def _load_v1_txt(path): """Parses a SIF V1 text file, returning numpy arrays. Args: path: string containing the path to the ASCII file. Returns: A tuple of 4 elements: constants: A numpy array of shape (element_count). The constant associated with each SIF element. centers: A numpy array of shape (element_count, 3). The centers of the SIF elements. radii: A numpy array of shape (element_count, 3). The axis-aligned radii of the gaussian falloffs. rotations: A numpy array of shape (element_count, 3). The euler-angle rotations of the SIF elements. symmetry_count: An integer. The number of elements which are left-right symmetric. features: A numpy array of shape (element_count, implicit_len). The LDIF neural features, if they are present. """ lines = file_util.readlines(path) if lines[0] != 'SIF': raise ValueError( f'Could not parse {path} as a sif txt. First line was {lines[0]}') shape_count, version, implicit_len = [int(x) for x in lines[1].split(' ')] version += 1 if version != 1: raise ValueError( f'This function can only parse v1 files. This version: {version}.') symmetry_count = 0 last_was_symmetric = True constants = [] centers = [] radii = [] rotations = [] features = [] for row in lines[2:]: elts = row.split(' ') if len(elts) != 11 + implicit_len: raise ValueError('Failed to parse the following row with ' f'implicit_len {implicit_len}: {row}') explicit_params = np.array([float(x) for x in elts[:10]], dtype=np.float32) is_symmetric = bool(int(elts[10])) if is_symmetric: symmetry_count += 1 if not last_was_symmetric: raise ValueError( f'File not supported by parser: row {row} is ' 'symmetric but follows an asymmetric element.') constants.append(explicit_params[0]) centers.append(explicit_params[1:4]) radii.append(explicit_params[4:7]) rotations.append(explicit_params[7:10]) if implicit_len > 0: implicit_params = np.array([float(x) for x in elts[11:]], dtype=np.float32) features.append(implicit_params) constants = np.stack(constants) centers = np.stack(centers) radii = np.stack(radii) rotations = np.stack(rotations) features = np.stack(features) if features else None # Radii have their sqrt stored for GAPS: radii = radii * radii return constants, centers, radii, rotations, symmetry_count, features
def get_evaluation_directories(split): registry_path = f'{FLAGS.dataset_directory}/{split}.txt' items_to_eval = file_util.readlines(registry_path) return items_to_eval