-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
197 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
configs/user/nguyen.yaml | ||
.hydra/ | ||
outputs/ | ||
None/ | ||
bop_viz_kit/ | ||
huggingface/ | ||
slurm_logs/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os, random | ||
import numpy as np | ||
from PIL import Image, ImageFilter | ||
import pandas as pd | ||
import torch | ||
import torchvision.transforms as transforms | ||
import torch.utils.data as data | ||
import json | ||
from src.dataloader.base import BaseBOP | ||
import logging | ||
import cv2 | ||
import os.path as osp | ||
|
||
# set level logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
class BOPDataset(BaseBOP): | ||
def __init__( | ||
self, | ||
root_dir, | ||
template_dir, | ||
obj_ids, | ||
img_size, | ||
cropping_with_bbox=None, | ||
reset_metaData=False, | ||
**kwargs, | ||
): | ||
self.root_dir = root_dir | ||
self.template_dir = template_dir | ||
self.img_size = img_size | ||
self.mask_size = 25 if img_size == 64 else int(img_size // 8) | ||
|
||
self.cropping_with_bbox = cropping_with_bbox | ||
self.obj_ids = obj_ids | ||
self.load_template_poses(template_dir=template_dir) | ||
self.load_list_scene(obj_ids) | ||
self.load_metaData( | ||
reset_metaData=reset_metaData, | ||
mode="query", | ||
) | ||
self.im_transform = transforms.Compose( | ||
[ | ||
transforms.ToTensor(), | ||
transforms.Normalize( | ||
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225] | ||
), | ||
] | ||
) | ||
logging.info(f"Length of dataloader: {self.__len__()}") | ||
|
||
def load_template_poses(self, template_dir): | ||
self.templates_poses = np.load(osp.join(template_dir, "obj_poses.npy")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import os, sys | ||
import numpy as np | ||
import shutil | ||
from tqdm import tqdm | ||
import time | ||
from functools import partial | ||
import multiprocessing | ||
import logging | ||
import os, sys | ||
import os.path as osp | ||
|
||
# set level logging | ||
logging.basicConfig(level=logging.INFO) | ||
import logging | ||
import hydra | ||
from omegaconf import DictConfig, OmegaConf | ||
import numpy as np | ||
from src.scripts.render_template import call_blender_proc | ||
|
||
|
||
@hydra.main( | ||
version_base=None, | ||
config_path="../../configs", | ||
config_name="render", | ||
) | ||
def render(cfg: DictConfig) -> None: | ||
OmegaConf.set_struct(cfg, False) | ||
save_dir = osp.join(osp.dirname(cfg.data.lm.root_dir), "templates") | ||
dataset_name = cfg.dataset_to_render | ||
if dataset_name == "tless": | ||
data_cfg = cfg.data["tless_test"] | ||
else: | ||
data_cfg = cfg.data[dataset_name] | ||
obj_pose_path = f"{save_dir}/{dataset_name}/obj_poses.npy" | ||
logging.info(f"Checking {data_cfg.dataset_name} ...") | ||
if dataset_name in ["tless"]: | ||
cad_dir = os.path.join(data_cfg.root_dir, "models/models_cad") | ||
else: | ||
cad_dir = os.path.join(data_cfg.root_dir, "models/models") | ||
object_ids = sorted( | ||
[ | ||
int(name[4:][:-4]) | ||
for name in os.listdir(cad_dir) | ||
if name.endswith(".ply") and not name.endswith("old.ply") | ||
] | ||
) | ||
cad_paths, template_dirs = [], [] | ||
for object_id in object_ids: | ||
cad_path = os.path.join( | ||
cad_dir, | ||
"obj_{:06d}.ply".format(object_id), | ||
) | ||
template_dir = os.path.join(save_dir, f"{dataset_name}/obj_{object_id:06d}") | ||
num_templates = len(os.listdir(template_dir)) | ||
if num_templates != 642: | ||
logging.info( | ||
f"Dataset {data_cfg.dataset_name}, obj {object_id} failed, found only {num_templates}" | ||
) | ||
cad_paths.append(cad_path) | ||
template_dirs.append(template_dir) | ||
|
||
os.environ["CUDA_VISIBLE_DEVICES"] = cfg.gpus | ||
start_time = time.time() | ||
pool = multiprocessing.Pool(processes=int(cfg.num_workers)) | ||
call_blender_proc_with_index = partial( | ||
call_blender_proc, | ||
list_cad_path=cad_paths, | ||
list_output_dir=template_dirs, | ||
obj_pose_path=obj_pose_path, | ||
disable_output=cfg.disable_output, | ||
gpus_devices=cfg.gpus, | ||
) | ||
mapped_values = list( | ||
tqdm( | ||
pool.imap_unordered( | ||
call_blender_proc_with_index, range(len(template_dirs)) | ||
), | ||
total=len(template_dirs), | ||
) | ||
) | ||
finish_time = time.time() | ||
print("Total time to render templates for query:", finish_time - start_time) | ||
|
||
|
||
if __name__ == "__main__": | ||
render() |