Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin Integration of NeRF Grasping Metric #7

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 0 additions & 192 deletions frogger/baselines.py

This file was deleted.

84 changes: 84 additions & 0 deletions frogger/baselines/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from dataclasses import dataclass, fields, make_dataclass
from typing import Callable

from frogger.robots.robot_core import RobotModelConfig


def combine_dataclasses(cls_a: type, cls_b: type) -> type:
"""Combines two config dataclasses into a new one, prioritizing attributes of cls_b.

Parameters
----------
cls_a : type
The first dataclass type.
cls_b : type
The second dataclass type.

Returns
-------
new_cls : type
The new dataclass type.
"""
# extract attributes from cls_a
attributes = {
field.name: (field.type, getattr(cls_a, field.name)) for field in fields(cls_a)
}

# remove fields that are methods in cls_b
for k in list(attributes.keys()):
if k in cls_b.__dict__ and isinstance(getattr(cls_b, k), Callable):
del attributes[k]

# include attributes from cls_b, prioritizing non-callable attributes
for field in fields(cls_b):
if field.name not in attributes and not isinstance(
getattr(cls_b, field.name), Callable
):
attributes[field.name] = field.type, getattr(cls_b, field.name)

# combine methods, prioritizing those from B
# note that we look through ALL attributes of cls_a, but only through the __dict__ of cls_b.
# this is so that we have inherited methods but only override them with cls_b impls if they
# are explicitly overridden.
methods = {}
for method_name in dir(cls_a):
method = getattr(cls_a, method_name)
if isinstance(method, Callable) and method_name not in cls_b.__dict__:
methods[method_name] = method
for method_name, method in cls_b.__dict__.items():
if isinstance(method, Callable):
methods[method_name] = method

# generate the new class
new_class_name = cls_a.__name__.replace("Config", "") + cls_b.__name__
new_cls = make_dataclass(
new_class_name,
[(name, type_, default) for name, (type_, default) in attributes.items()],
kw_only=True,
bases=(cls_a, cls_b),
)

# add methods to the new dataclass
for method_name, method in methods.items():
if method_name != "__class__":
setattr(new_cls, method_name, method)

return new_cls


@dataclass(kw_only=True)
class BaselineConfig(RobotModelConfig):
"""Configuration for a generic baseline.

Typically, we want to modify some RobotModelConfig that has already been
instantiated with desirable properties. To do this, we will use the `from_cfg`
method of BaselineConfig to load all of the attributes of an existing config
into a baseline config that is the combination of the baseline attributes and
the original config attributes.
"""

@classmethod
def from_cfg(cls, config_cls: type, **kwargs) -> "BaselineConfig":
"""Creates a baseline config from an existing robot model config class."""
CombinedDataClass = combine_dataclasses(config_cls, cls)
return CombinedDataClass
119 changes: 119 additions & 0 deletions frogger/baselines/classifier/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# tyro YAML.
!dataclass:ClassifierConfig
checkpoint_workspace: !dataclass:CheckpointWorkspaceConfig
input_leaf_dir_name: null
output_leaf_dir_name: 75bottle_augmented_pose_HALTON_400_cnn-3d-xyz_l2_passed-eval_2024-03-12_16-20-12-513415
root_dir: !!python/object/apply:pathlib.PosixPath
- /
- home
- albert
- research
- frogger
- frogger
- baselines
- classifier
- Train_DexGraspNet_NeRF_Grasp_Metric_workspaces
data: !dataclass:ClassifierDataConfig
debug_shuffle_labels: false
frac_test: 0.1
frac_train: 0.8
frac_val: 0.1
max_num_data_points: null
nerf_density_threshold_value: null
use_random_rotations: true
dataloader: !dataclass:ClassifierDataLoaderConfig
batch_size: 256
load_grasp_labels_in_ram: false
load_grasp_transforms_in_ram: false
load_nerf_configs_in_ram: false
load_nerf_grid_inputs_in_ram: false
num_workers: 8
pin_memory: true
model_config: !dataclass:CNN_3D_XYZ_ModelConfig
conv_channels:
- 32
- 64
- 128
mlp_hidden_layers:
- 256
- 256
n_fingers: 4
name: 75bottle_augmented_pose_HALTON_400_cnn-3d-xyz_l2_passed-eval
nerfdata_config: !dataclass:GridNerfDataConfig
cameras_samples_chunk_size: 2000
config_dict_visualize_index: 0
dexgraspnet_data_root: !!python/object/apply:pathlib.PosixPath
- /
- home
dexgraspnet_meshdata_root: !!python/object/apply:pathlib.PosixPath
- /
- home
evaled_grasp_config_dicts_path: !!python/object/apply:pathlib.PosixPath
- /
- home
fingertip_config: !dataclass:EvenlySpacedFingertipConfig
distance_between_pts_mm: 2
finger_height_mm: 60.0
finger_width_mm: 60.0
grasp_depth_mm: 80.0
n_fingers: 4
num_pts_x: 31
num_pts_y: 31
num_pts_z: 41
grasp_visualize_index: 0
limit_num_configs: null
max_num_data_points_per_file: null
nerf_checkpoints_path: !!python/object/apply:pathlib.PosixPath
- /
- home
- albert
- research
- frogger
- frogger
- baselines
- nerf
output_filepath: null
plot_all_high_density_points: true
plot_alpha_images_each_finger: true
plot_alphas_each_finger_1D: true
plot_only_one: false
print_timing: true
ray_samples_chunk_size: 50
save_dataset: true
nerfdata_config_path: null
random_seed: 42
task_type: !enum:TaskType 'PASSED_EVAL'
test_dataset_filepath: null
train_dataset_filepath: !!python/object/apply:pathlib.PosixPath
- /
- scr
- tylerlum
- data
- 2024-03-10_75bottle_augmented_pose_HALTON_400
- grid_dataset
- train_dataset.h5
training: !dataclass:ClassifierTrainingConfig
betas: !!python/tuple
- 0.9
- 0.999
extra_punish_false_positive_factor: 0.0
grad_clip_val: 1.0
label_smoothing: 0.0
loss_fn: l2
lr: 0.0001
lr_scheduler_name: constant
lr_scheduler_num_warmup_steps: 0
n_epochs: 1000
save_checkpoint_freq: 1
save_checkpoint_on_epoch_0: false
val_freq: 5
val_on_epoch_0: false
weight_decay: 0.001
val_dataset_filepath: null
wandb: !dataclass:WandbConfig
entity: null
group: null
job_type: null
name: 75bottle_augmented_pose_HALTON_400_cnn-3d-xyz_l2_passed-eval_2024-03-12_16-20-12-513415
project: learned_metric
resume: never
Loading