def rotate_voxels(rep, angle): a = binvox_rw.read_as_3d_array( open("tmpTest/outline_scale_47.0.binvox", "rb")) val = a.data val = tf.convert_to_tensor(np.expand_dims(np.expand_dims(val, 0), -1)) phi, theta = angle rot_mat = voxel.get_transform_matrix_tf([theta], [phi]) proj_val = voxel.rotate_voxel(val, rot_mat) num = np.where(proj_val > 0.5)[0] proj_val = np.squeeze(proj_val) proj_val = proj_val > 0.5 # st() proj_imgZ = np.mean(proj_val, 0) imsave( '{}/valRotate_phi_{}_theta_{}_fov_{}_Z.png'.format( rep, phi, theta, const.fov), proj_imgZ) # st() save_voxel( np.squeeze(proj_val), "{}/valRotate_THETA_{}_PHI_{}_fov_{}_.binvox".format( rep, theta, phi, const.fov))
def create_single_data(mesh_filaname): """ create input data for the network. The data is wrapped by Data structure in pytorch-geometric library :param mesh_filaname: name of the input mesh :return: wrapped data, voxelized mesh, and geodesic distance matrix of all vertices """ mesh = o3d.io.read_triangle_mesh(mesh_filaname) mesh.compute_triangle_normals() mesh_v = np.asarray(mesh.vertices) mesh_vn = np.asarray(mesh.vertex_normals) mesh_f = np.asarray(mesh.triangles) mesh_v, translation_normalize, scale_normalize = normalize_obj(mesh_v) mesh_normalized = o3d.geometry.TriangleMesh( vertices=o3d.utility.Vector3dVector(mesh_v), triangles=o3d.utility.Vector3iVector(mesh_f)) o3d.io.write_triangle_mesh( mesh_filename.replace("_remesh.obj", "_normalized.obj"), mesh_normalized) # vertices v = np.concatenate((mesh_v, mesh_vn), axis=1) v = torch.from_numpy(v).float() # topology edges print(" gathering topological edges.") tpl_e = get_tpl_edges(mesh_v, mesh_f).T tpl_e = torch.from_numpy(tpl_e).long() tpl_e, _ = add_self_loops(tpl_e, num_nodes=v.size(0)) # surface geodesic distance matrix print(" calculating surface geodesic matrix.") surface_geodesic = calc_surface_geodesic(mesh) # geodesic edges print(" gathering geodesic edges.") geo_e = get_geo_edges(surface_geodesic, mesh_v).T geo_e = torch.from_numpy(geo_e).long() geo_e, _ = add_self_loops(geo_e, num_nodes=v.size(0)) # batch batch = torch.zeros(len(v), dtype=torch.long) # voxel if not os.path.exists( mesh_filaname.replace('_remesh.obj', '_normalized.binvox')): os.system("./binvox -d 88 -pb " + mesh_filaname.replace("_remesh.obj", "_normalized.obj")) with open(mesh_filaname.replace('_remesh.obj', '_normalized.binvox'), 'rb') as fvox: vox = binvox_rw.read_as_3d_array(fvox) data = Data(x=v[:, 3:6], pos=v[:, 0:3], tpl_edge_index=tpl_e, geo_edge_index=geo_e, batch=batch) return data, vox, surface_geodesic, translation_normalize, scale_normalize
def load_label(self, category, model_id): voxel_fn = get_voxel_file(self.cfg.DIR.VOXEL_PATH, category, model_id) with open(voxel_fn, 'rb') as f: voxel = read_as_3d_array(f) # Set the original value to [MIN_VOXEL_VALUE, -MIN_VOXEL_VALUE] # instead of [0, -MIN_VOXEL_VALUE * 2) voxel.data += self.cfg.CONST.MIN_VOXEL_VALUE return voxel
def readGridFullSeg(self): binvoxPath = self.binvoxPath + '/model.binvox' with open(binvoxPath,'rb') as f: binvoxObj = binvox_rw.read_as_3d_array(f) voxelgrid = np.reshape(binvoxObj.data,(dims,dims,dims,1)) voxelgrid = voxelgrid.astype('float32') partSegs = [] for i in range(1,self.nParts+1): segPath = self.binvoxPath + '/model_'+str(i)+'.binvox' with open(segPath,'rb') as f: segBinvoxObj = binvox_rw.read_as_3d_array(f) segGrid = np.reshape(segBinvoxObj.data,(dims,dims,dims,1)) segGrid = segGrid.astype('float32') partSegs.append(segGrid) return voxelgrid,partSegs
def __getitem__(self, idx): if torch.is_tensor(idx): idx = idx.tolist() character_idx = idx // self.motions_per_character motion_idx = idx % self.motions_per_character character_name = self.characters_list[character_idx] motion_name = self.motions_list[motion_idx] data_dir = self.data_dir if self.use_front_faced: vox_file = os.path.join(data_dir, 'objs_fixed/{}/{}.binvox'.format(character_name, motion_name)) joint_matrix_file = os.path.join(data_dir, 'transforms_fixed/{}/{}.csv'.format(character_name, motion_name)) else: vox_file = os.path.join(data_dir, 'objs/{}/{}.binvox'.format(character_name, motion_name)) joint_matrix_file = os.path.join(data_dir, 'transforms/{}/{}.csv'.format(character_name, motion_name)) # Read binvox r, dim_ori, dim_pad = self.r, self.dim_ori, self.dim_pad with open(vox_file, 'rb') as f: bin_vox = binvox_rw.read_as_3d_array(f) meta = {'translate': bin_vox.translate, 'scale': bin_vox.scale, 'dims': bin_vox.dims[0], 'character_name': character_name, 'motion_name': motion_name, 'mode': self.mode} bin_vox_padded = np.zeros((bin_vox.dims[0] + 2 * r, bin_vox.dims[1] + 2 * r, bin_vox.dims[2] + 2 * r), dtype= np.float16) bin_vox_padded[r:bin_vox.dims[0] + r, r:bin_vox.dims[1] + r, r:bin_vox.dims[2] + r] = bin_vox.data # put the occupied voxels at the center instead of left-top corner bin_vox_padded, center_trans = center_vox(bin_vox_padded) meta['center_trans'] = np.array(center_trans) # convert binary voxels to SDF representation sdf_vox_padded = bin2sdf(bin_vox_padded) # Relative Coordinate JM4x4 = np.concatenate([np.genfromtxt(joint_matrix_file, delimiter=',', dtype='float'), np.array([[0, 0, 0, 1]]*22)], axis=1).reshape(22, 4, 4) # IBM4x4 = np.concatenate([np.genfromtxt(inverse_bind_matrix_file, delimiter=',', dtype='float'), np.array([[0, 0, 0, 1]]*22)], # axis=1).reshape(22, 4, 4) # skinweights = np.genfromtxt(skin_file, delimiter=',', dtype='float') tree = maketree(22) JM4x4_glob = [None] * 22 bfs(tree, JM4x4, JM4x4_glob) JM4x4_glob = np.array(JM4x4_glob) JM4x4_glob_p = JM4x4_glob[:, :3, 3] target_heatmap = np.zeros((self.n_joint, int(bin_vox.dims[0] + 2 * r), int(bin_vox.dims[1] + 2 * r), int(bin_vox.dims[2] + 2 * r)), dtype=np.float16) for joint_idx in range(self.n_joint): heatmap, pos = target_heatmap[joint_idx], JM4x4_glob_p[joint_idx] pos = Cartesian2Voxcoord(pos, bin_vox.translate, bin_vox.scale, bin_vox.dims[0]) pos = (pos[0] - center_trans[0] + r, pos[1] - center_trans[1] + r, pos[2] - center_trans[2] + r) pos = np.clip(pos, a_min=0, a_max=dim_pad - 1) draw_jointmap(heatmap, pos, sigma=self.sigma) return bin_vox_padded, sdf_vox_padded, target_heatmap, JM4x4, meta
def process(self): data_list = [] i = 0.0 for v_filename in self.raw_paths: print('preprecessing data complete: {:.4f}%'.format( 100 * i / len(self.raw_paths))) i += 1.0 v = np.loadtxt(v_filename) m = np.loadtxt(v_filename.replace('_v.txt', '_attn.txt')) tpl_e = np.loadtxt(v_filename.replace('_v.txt', '_tpl_e.txt')).T geo_e = np.loadtxt(v_filename.replace('_v.txt', '_geo_e.txt')).T joints = np.loadtxt(v_filename.replace('_v.txt', '_j.txt')) adj = np.loadtxt(v_filename.replace('_v.txt', '_adj.txt'), dtype=np.uint8) vox_file = v_filename.replace('_v.txt', '.binvox') with open(vox_file, 'rb') as fvox: vox = binvox_rw.read_as_3d_array(fvox) pairs = list(it.combinations(range(adj.shape[0]), 2)) pair_attr = [] for pr in pairs: dist = np.linalg.norm(joints[pr[0]] - joints[pr[1]]) bone_samples = self.sample_on_bone(joints[pr[0]], joints[pr[1]]) bone_samples_inside, _ = self.inside_check(bone_samples, vox) outside_proportion = len(bone_samples_inside) / ( len(bone_samples) + 1e-10) attr = np.array([dist, outside_proportion, adj[pr[0], pr[1]]]) pair_attr.append(attr) pairs = np.array(pairs) pair_attr = np.array(pair_attr) name = int(v_filename.split('/')[-1].split('_')[0]) v = torch.from_numpy(v).float() m = torch.from_numpy(m).long() tpl_e = torch.from_numpy(tpl_e).long() geo_e = torch.from_numpy(geo_e).long() tpl_e, _ = add_self_loops(tpl_e, num_nodes=v.size(0)) geo_e, _ = add_self_loops(geo_e, num_nodes=v.size(0)) joints = torch.from_numpy(joints).float() pairs = torch.from_numpy(pairs).float() pair_attr = torch.from_numpy(pair_attr).float() data_list.append( SkeletonData(x=v[:, 3:6], pos=v[:, 0:3], name=name, mask=m, joints=joints, tpl_edge_index=tpl_e, geo_edge_index=geo_e, pairs=pairs, pair_attr=pair_attr)) data, slices = self.collate(data_list) torch.save((data, slices), self.processed_paths[0])
def readGridAndSeg(self,return_params=False): binvoxPath = self.binvoxPath + '/model.binvox' with open(binvoxPath,'rb') as f: binvoxObj = binvox_rw.read_as_3d_array(f) scale = binvoxObj.scale translate = binvoxObj.translate self.scale = scale self.translate = translate voxelgrid = np.reshape(binvoxObj.data,(dims,dims,dims,1)) voxelgrid = voxelgrid.astype('float32') pointCloud = np.array(list(csv.reader(open(self.ptsPath,'r'),delimiter=' '))) strSeg = open(self.segPath).read().splitlines() segLabels = [int(l) for l in strSeg] if not return_params: return voxelgrid,pointCloud,segLabels else: return voxelgrid,scale,translate,pointCloud,segLabels
def readGrid(self,return_params=False): if self.cache is None: binvoxPath = self.binvoxPath + '/model.binvox' with open(binvoxPath,'rb') as f: binvoxObj = binvox_rw.read_as_3d_array(f) scale = binvoxObj.scale translate = binvoxObj.translate self.scale = scale self.translate = translate voxelgrid = np.reshape(binvoxObj.data,(dims,dims,dims,1)) voxelgrid = voxelgrid.astype('float32') self.cache = voxelgrid else: voxelgrid = self.cache scale = self.scale translate = self.translate if not return_params: return voxelgrid else: return voxelgrid,scale,translate
def project_voxel(rep): a = binvox_rw.read_as_3d_array( open( "/Users/ashar/work/visual_imagination/prob_scene_gen/3dProbNeuralProgNet/data/CLEVR/clevr-dataset-gen/image_generation/output_90_20.binvox", "rb")) val = a.data val = tf.convert_to_tensor(np.expand_dims(np.expand_dims(val, 0), -1)) proj_val = voxel.project_voxel(val) num = np.where(proj_val > 0.5)[0] # if len(num) > 0: # print("found") # fovs_working[fov] = len(num) proj_val = np.squeeze(proj_val) proj_val = proj_val > 0.5 proj_imgZ = np.mean(proj_val, 0) proj_imgY = np.mean(proj_val, 1) proj_imgX = np.mean(proj_val, 2) imsave('{}/valProject_fov_{}_Z.png'.format(rep, const.fov), proj_imgZ) imsave('{}/valProject_fov_{}_Y.png'.format(rep, const.fov), proj_imgY) imsave('{}/valProject_fov_{}_X.png'.format(rep, const.fov), proj_imgX) save_voxel(proj_val, "{}/valProject_fov_{}.binvox".format(rep, const.fov))
def process(self): data_list = [] i = 0.0 for v_filename in self.raw_paths: print('preprecessing data complete: {:.4f}%'.format( 100 * i / len(self.raw_paths))) i += 1.0 v = np.loadtxt(v_filename) m = np.loadtxt(v_filename.replace('_v.txt', '_attn.txt')) v = torch.from_numpy(v).float() m = torch.from_numpy(m).long() tpl_e = np.loadtxt(v_filename.replace('_v.txt', '_tpl_e.txt')).T geo_e = np.loadtxt(v_filename.replace('_v.txt', '_geo_e.txt')).T tpl_e = torch.from_numpy(tpl_e).long() geo_e = torch.from_numpy(geo_e).long() tpl_e, _ = add_self_loops(tpl_e, num_nodes=v.size(0)) geo_e, _ = add_self_loops(geo_e, num_nodes=v.size(0)) y = np.loadtxt(v_filename.replace('_v.txt', '_j.txt')) num_joint = len(y) joint_pos = y if len(y) < len(v): y = np.tile(y, (round(1.0 * len(v) / len(y) + 0.5), 1)) y = y[:len(v), :] elif len(y) > len(v): y = y[:len(v), :] y = torch.from_numpy(y).float() adj = np.loadtxt(v_filename.replace('_v.txt', '_adj.txt'), dtype=np.uint8) vox_file = v_filename.replace('_v.txt', '.binvox') with open(vox_file, 'rb') as fvox: vox = binvox_rw.read_as_3d_array(fvox) pair_all = [] for joint1_id in range(adj.shape[0]): for joint2_id in range(joint1_id + 1, adj.shape[1]): dist = np.linalg.norm(joint_pos[joint1_id] - joint_pos[joint2_id]) bone_samples = self.sample_on_bone(joint_pos[joint1_id], joint_pos[joint2_id]) bone_samples_inside, _ = self.inside_check( bone_samples, vox) outside_proportion = len(bone_samples_inside) / ( len(bone_samples) + 1e-10) pair = np.array([ joint1_id, joint2_id, dist, outside_proportion, adj[joint1_id, joint2_id] ]) pair_all.append(pair) pair_all = np.array(pair_all) pair_all = torch.from_numpy(pair_all).float() num_pair = len(pair_all) name = int(v_filename.split('/')[-1].split('_')[0]) data_list.append( Data(x=v[:, 3:6], pos=v[:, 0:3], name=name, mask=m, y=y, num_joint=num_joint, tpl_edge_index=tpl_e, geo_edge_index=geo_e, pairs=pair_all, num_pair=num_pair)) data, slices = self.collate(data_list) torch.save((data, slices), self.processed_paths[0])
def load_voxel_data(path): with open(path, 'rb') as f: model = binvox_rw.read_as_3d_array(f) return model.data
def get_binvox(self, binvox_file, cat_id, obj): with open(binvox_file, 'rb') as fp: voxel = read_as_3d_array(fp) return voxel.data.astype(np.float32)
def create_single_data(mesh_obj): """ create input data for the network. The data is wrapped by Data structure in pytorch-geometric library :param mesh_filaname: name of the input mesh :return: wrapped data, voxelized mesh, and geodesic distance matrix of all vertices """ # triangulate first bm = bmesh.new() bm.from_mesh(mesh_obj.data) bmesh.ops.triangulate(bm, faces=bm.faces[:], quad_method='BEAUTY', ngon_method='BEAUTY') bm.verts.ensure_lookup_table() bm.faces.ensure_lookup_table() mesh_v = np.asarray([list(v.co) for v in bm.verts]) mesh_f = np.asarray([[v.index for v in f.verts] for f in bm.faces]) bm.free() mesh = o3d.geometry.TriangleMesh(o3d.utility.Vector3dVector(mesh_v), o3d.open3d.utility.Vector3iVector(mesh_f)) mesh.compute_vertex_normals() mesh.compute_triangle_normals() # renew mesh component list with o3d mesh, for consistency mesh_v = np.asarray(mesh.vertices) mesh_vn = np.asarray(mesh.vertex_normals) mesh_f = np.asarray(mesh.triangles) mesh_v, translation_normalize, scale_normalize = normalize_obj(mesh_v) mesh_normalized = o3d.geometry.TriangleMesh( vertices=o3d.utility.Vector3dVector(mesh_v), triangles=o3d.utility.Vector3iVector(mesh_f)) global MESH_NORMALIZED MESH_NORMALIZED = mesh_normalized # vertices v = np.concatenate((mesh_v, mesh_vn), axis=1) v = torch.from_numpy(v).float() # topology edges print(" gathering topological edges.") tpl_e = get_tpl_edges(mesh_v, mesh_f).T tpl_e = torch.from_numpy(tpl_e).long() tpl_e, _ = add_self_loops(tpl_e, num_nodes=v.size(0)) # surface geodesic distance matrix print(" calculating surface geodesic matrix.") surface_geodesic = calc_surface_geodesic(mesh) # geodesic edges print(" gathering geodesic edges.") geo_e = get_geo_edges(surface_geodesic, mesh_v).T geo_e = torch.from_numpy(geo_e).long() geo_e, _ = add_self_loops(geo_e, num_nodes=v.size(0)) # batch batch = torch.zeros(len(v), dtype=torch.long) # voxel fo_normalized = tempfile.NamedTemporaryFile(suffix='_normalized.obj') fo_normalized.close() o3d.io.write_triangle_mesh(fo_normalized.name, mesh_normalized) # TODO: we might cache the .binvox file somewhere, as in the RigNet quickstart example rignet_path = bpy.context.preferences.addons[ __package__].preferences.rignet_path binvox_exe = os.path.join(rignet_path, "binvox") if sys.platform.startswith("win"): binvox_exe += ".exe" if not os.path.isfile(binvox_exe): os.unlink(fo_normalized.name) clear() raise FileNotFoundError( "binvox executable not found in {0}, please check RigNet path in the addon preferences" ) os.system(binvox_exe + " -d 88 " + fo_normalized.name) with open(os.path.splitext(fo_normalized.name)[0] + '.binvox', 'rb') as fvox: vox = binvox_rw.read_as_3d_array(fvox) os.unlink(fo_normalized.name) data = Data(x=v[:, 3:6], pos=v[:, 0:3], tpl_edge_index=tpl_e, geo_edge_index=geo_e, batch=batch) return data, vox, surface_geodesic, translation_normalize, scale_normalize
def readtask(task_filename): object_dict = dict() f = open(task_filename, 'r') #read object name while True: name = readline_skip(f).strip() if name.startswith("goal:"): object_dict['goal'] = name.split(":")[1].strip() continue if not name: break assert name not in object_dict, "name is duplicated :"+ name assert '-' not in name, "name should not contain char '-' :" + name object_property = dict() pname, value = check_line(readline_skip(f)) while not pname == "end": object_property[pname] = value pname, value = check_line(readline_skip(f)) isURDF = object_property['file'].endswith('.urdf') isOBJ = object_property['file'].endswith('.obj') if not isURDF and not isOBJ: print("Error: Only urdf and obj filenames are supported") assert(1==2) return if isURDF: if 'mass' in object_property: print(colored('Warning: urdf file will use pre-defined mass', 'red')) for line in open(os.path.join(urdf_path, object_property['file']), 'r'): if "<mesh filename" in line: split_line = line.split("\"") assert "filename" in split_line[0] and "scale" in split_line[2] obj_filename = os.path.join(urdf_path, split_line[1]) object_property['scale'] = split_line[3].replace(" ", ",") object_property['bbox'] = rigid_mesh_scan(obj_filename) break if isOBJ: assert 'mass' in object_property, 'Error: mass is not defined for obj file'+ name if 'scale' not in object_property: object_property['scale'] = 1.0 object_property['bbox'] = rigid_mesh_scan(object_property['file']) crop_max = np.max(np.abs(object_property["bbox"]) * 1.5) object_property['binvox_crop_max'] = crop_max obj_file = object_property['file'] output_binvox_file = obj_file[:-4] + ".binvox" #.replace(".obj", ".binvox") #assert(not os.path.exists(output_binvox_file)), f"binvox file {output_binvox_file} exists you might" \ # "want to delete it first" if not os.path.exists(output_binvox_file): command = f'binvox -aw -dc -d 128 -bb -{crop_max} -{crop_max} -{crop_max} {crop_max}'\ f' {crop_max} {crop_max} -t binvox {obj_file}' os.system(command) # generate new urdf file for the obj object template_file = open(os.path.join(urdf_path, "obj_template.urdf"), 'r').read() template_file = template_file.replace("robotname", "\"" + name + "\"") template_file = template_file.replace("mass_value", "\"" + object_property['mass'] + "\"") template_file = template_file.replace("scale_value", "\"" + " ".join([str(item) for item in parse_scale(object_property['scale'])]) + "\"") template_file = template_file.replace("path_to_obj_file", "\"" + object_property['file'] + "\"") newfile = open(os.path.join(urdf_folder, name + ".urdf"), 'w').write(template_file) object_property['file'] = os.path.join(urdf_folder, name + ".urdf") object_property['obj_file'] = obj_file object_property['binvox_file'] = output_binvox_file with open(output_binvox_file, 'rb') as f1: m1 = binvox_rw.read_as_3d_array(f1) object_property['binvox'] = np.transpose(m1.data, [2, 1, 0]) assert 'pos' in object_property, 'Error: pos is not defined' assert 'orn' in object_property, 'Error: orn is not defined' check_pos(object_property['pos']) check_pos(object_property['orn']) object_property['scale'] = parse_scale(object_property['scale']) if "open" in object_property: object_property['open'] = parse_open(object_property['open']) object_dict[name] = object_property bbox = object_property['bbox'] object_property['scaled_bbox'] = [bbox[0]*object_property['scale'][0], bbox[1]*object_property['scale'][0], bbox[2]*object_property['scale'][1], bbox[3]*object_property['scale'][1], bbox[4]*object_property['scale'][2], bbox[5]*object_property['scale'][2]] object_dict['taskfile'] = task_filename return object_dict
def predict_joints(model_id, args): """ predict joints for a specified model :param model_id: processed model ID number :param args: :return: predicted joints, and voxelized mesh """ vox_folder = os.path.join(args.dataset_folder, 'vox/') mesh_folder = os.path.join(args.dataset_folder, 'obj_remesh/') raw_pred = os.path.join(args.res_folder, '{:d}.ply'.format(model_id)) vox_file = os.path.join(vox_folder, '{:d}.binvox'.format(model_id)) mesh_file = os.path.join(mesh_folder, '{:d}.obj'.format(model_id)) pred_attn = np.load( os.path.join(args.res_folder, '{:d}_attn.npy'.format(model_id))) with open(vox_file, 'rb') as fvox: vox = binvox_rw.read_as_3d_array(fvox) pred_joints = readPly(raw_pred) pred_joints, index_inside = inside_check(pred_joints, vox) pred_attn = pred_attn[index_inside, :] # img = draw_shifted_pts(mesh_file, pred_joints, weights=pred_attn) bandwidth = np.load( os.path.join(args.res_folder, '{:d}_bandwidth.npy'.format(model_id))) bandwidth = bandwidth[0] pred_joints = pred_joints[pred_attn.squeeze() > 1e-3] pred_attn = pred_attn[pred_attn.squeeze() > 1e-3] # reflect raw points pred_joints_reflect = pred_joints * np.array([[-1, 1, 1]]) pred_joints = np.concatenate((pred_joints, pred_joints_reflect), axis=0) pred_attn = np.tile(pred_attn, (2, 1)) # img = draw_shifted_pts(mesh_file, pred_joints, weights=pred_attn) # cv2.imwrite(os.path.join(res_folder, '{:s}_raw.jpg'.format(model_id)), img[:, :, ::-1]) pred_joints = meanshift_cluster(pred_joints, bandwidth, pred_attn, max_iter=20) Y_dist = np.sum( ((pred_joints[np.newaxis, ...] - pred_joints[:, np.newaxis, :])**2), axis=2) density = np.maximum(bandwidth**2 - Y_dist, np.zeros(Y_dist.shape)) # density = density * pred_attn density = np.sum(density, axis=0) density_sum = np.sum(density) pred_joints_ = pred_joints[density / density_sum > args.threshold_best] density_ = density[density / density_sum > args.threshold_best] pred_joints_ = nms_meanshift(pred_joints_, density_, bandwidth) pred_joints_, _ = flip(pred_joints_) reduce_threshold = args.threshold_best while len(pred_joints_) < 2 and reduce_threshold > 1e-7: # print('reducing') reduce_threshold = reduce_threshold / 1.3 pred_joints_ = pred_joints[density / density_sum >= reduce_threshold] density_ = density[density / density_sum > reduce_threshold] pred_joints_ = nms_meanshift(pred_joints_, density_, bandwidth) pred_joints_, _ = flip(pred_joints_) if reduce_threshold <= 1e-7: pred_joints_ = nms_meanshift(pred_joints_, density, bandwidth) pred_joints_, _ = flip(pred_joints_) pred_joints = pred_joints_ # img = draw_shifted_pts(mesh_file, pred_joints) # cv2.imwrite(os.path.join(res_folder, '{:d}_joint.jpg'.format(model_id)), img) # np.save(os.path.join(res_folder, '{:d}_joint.npy'.format(model_id)), pred_joints) return pred_joints, vox
def read_voxel(voxel_path: str) -> br.Voxels: with open(voxel_path, "rb") as f: return br.read_as_3d_array(f)