To use the SC6D-pose repository with your custom dataset, you will need to adapt your data to the format expected by the code and update the configuration file. Here's a breakdown of the steps:
Organize your dataset in the BOP format: The code is designed to work with datasets structured like the BOP datasets. This means you'll need to organize your custom dataset with the following structure:
code
YourCustomDataset/
train_yourdataset_subset/ # e.g., train_real, train_synthetic
000001/ # Scene ID
scene_camera.json # Camera intrinsics for each image
scene_gt.json # 6D poses of objects in each image
scene_gt_info.json # Visibility information for each object
rgb/ # RGB images
[Redacted PhoneNumber].jpg
[Redacted PhoneNumber].jpg
...
mask_visib/ # Visible object masks
000000_000000.png
000000_000001.png
...
test/ # If you have a test set
000001/
scene_camera.json
[Redacted Person]
scene_gt_info.json
rgb/
mask_visib/
# ... other scenes ...
scene_camera.json: This file contains the camera intrinsics (cam_K) for each image in the scene. The format should be a dictionary where keys are image IDs (strings) and values are dictionaries containing "cam_K" (a list of 9 floats representing the 3x3 camera matrix).
scene_gt.json: This file contains the ground truth 6D poses of the objects in each image. The format is a dictionary where keys are image IDs (strings) and values are lists of dictionaries, each representing an object instance. Each instance dictionary should have:
"obj_id": The ID of the object (integer, 1-based).
"cam_R_m2c": The 3x3 rotation matrix from the object's model space to the camera space (list of 9 floats).
"cam_t_m2c": The 3D translation vector from the object's model space to the camera space (list of 3 floats, in millimeters).
scene_gt_info.json: This file provides additional information about the object instances, including the visible bounding boxes. The format mirrors scene_gt.json, with each instance dictionary containing "bbox_visib" (a list of 4 integers: [x_min, y_min, width, height]).
rgb/: This directory contains the RGB images (e.g., .jpg or .png). Filenames should correspond to the image IDs in the JSON files (e.g., [Redacted PhoneNumber].jpg).
mask_visib/: This directory contains the visible masks for each object instance. Filenames should be in the format {image_id}_{annotation_index}.png (e.g., 000000_000000.png). These should be binary masks where the object is white (or 1) and the background is black (or 0).
Update the config.py file: You need to add a new configuration entry for your custom dataset in the DATASET_CONFIG dictionary. Refer to the existing dataset configurations (like 'tless', 'itodd', 'ycbv') as examples. Here's what you'll likely need to define:
python
DATASET_CONFIG = {
# ... other datasets ...
'your_dataset_name': {
'width': your_image_width,
'height': your_image_height,
'Tz_near': your_near_depth_value, # Approximate near depth in meters
'Tz_far': your_far_depth_value, # Approximate far depth in meters
'num_class': number_of_object_classes,
'id2mod': {i + 1: f"obj_{i+1:02d}" for i in range(number_of_object_classes)}, # Mapping from object ID to model name (if applicable)
'id2cls': {i + 1: i for i in range(number_of_object_classes)}, # Mapping from object ID to class index (0-based)
'train_set': ['train_yourdataset_subset'], # List of training subsets
'test_set': 'test', # Name of the test set directory (if available)
},
}
Replace 'your_dataset_name' with the actual name you want to use for your dataset.
Set 'width' and 'height' to the dimensions of your images.
Adjust 'Tz_near' and 'Tz_far' to reasonable values based on the depth range in your dataset (in meters). These values are used to discretize the depth for translation estimation.
Set 'num_class' to the number of distinct object categories in your dataset.
Update 'id2mod' and 'id2cls' accordingly. If you don't have separate 3D models, 'id2mod' might not be strictly necessary, but it's good practice to keep it consistent.
Set 'train_set' to a list containing the names of the subdirectories within your main dataset directory that hold the training data (e.g., ['train_real']).
Modify the BOP_Dataset class (if necessary): The dataset/bop_dataset.py file contains the BOP_Dataset class responsible for loading and processing the data. You might need to make adjustments here depending on the specifics of your data format:
Image loading: Ensure the image paths and loading method are correct for your dataset.
Annotation parsing: Verify that the code correctly parses your scene_gt.json, scene_camera.json, and scene_gt_info.json files. Double-check the keys used to access the object ID, pose information (rotation and translation), and bounding boxes.
Mask loading: Confirm that the mask loading logic (mask_visib/) is appropriate for your mask filenames and format.
Filtering invalid data: Review the filtering conditions for small or invalid instances. You might need to adjust the thresholds.
Set the DATASET_ROOT in config.py: Make sure the DATASET_ROOT variable in config.py points to the directory where you've placed your custom dataset.
python
DATASET_ROOT = "Path/to/YourCustomDataset-Root"
Adapt the training script (SC6D_training.py): When running the training script, specify the name of your custom dataset using the --dataset_name argument.
Replace your_dataset_name with the name you defined in config.py.
Example Modification in dataset/bop_dataset.py (Illustrative):
If your mask filenames are different, you might need to adjust this part in the BOP_Dataset class's __init__ method:
python
# ... inside the loop processing annotations ...
mask_visib_file = os.path.join(scene_dir, "mask_visib/{:06d}_{:06d}.png".format(img_id_int, anno_idx))
# Modify the filename pattern if needed, e.g.,
# mask_visib_file = os.path.join(scene_dir, "masks", f"image_{img_id_int}_object_{anno_dict['object_instance_id']}.png")
assert os.path.exists(mask_visib_file), mask_visib_file
# ... rest of the code ...
Important Considerations:
Units: Ensure consistency in units (e.g., millimeters for translation in the JSON files, meters in the code).
Coordinate Systems: Be aware of the coordinate systems used for the poses (camera-centric vs. world-centric). The code expects poses relative to the camera.
Object IDs: The obj_id in your annotations should correspond to the object indices you intend to train for.
Background Images: The training process uses background images from the VOC dataset by default. You might want to provide a custom set of background images by adjusting the BG_TYPE and related parameters in config.py and ensuring the paths are correct.
By following these steps, you should be able to adapt the SC6D-pose repository to train and evaluate models on your custom 6D object pose estimation dataset. Remember to carefully review the code and adapt it to the specific structure and format of your data.
Set 'test_set' to the name of the subdirectory containing the test data, if you have one.