Skip to content

Commit

Permalink
Fix random (#36)
Browse files Browse the repository at this point in the history
* pass random seed to get_data

* fix

* add setuptools

* Update train.py

* pin setuptools

* unmute Wandb

* unpin gym

* fix formatting

* change n_proc to n_proc_per_worker

---------

Co-authored-by: Ben Eisner <ben.a.eisner@gmail.com>
  • Loading branch information
liy1shu and beneisner authored Jul 24, 2023
1 parent ad05da9 commit db00a0e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
with:
python-version: '3.8'
##############################################
- name: Update pip and setuptools.
run: pip install --upgrade pip setuptools==57.1.0 wheel

- name: Install pyg special-like.
run: pip install pyg-lib torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.13.0+cpu.html

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
with:
python-version: '3.8'
##############################################
- name: Update pip and setuptools.
run: pip install --upgrade pip setuptools==57.1.0 wheel

- name: Install pyg special-like.
run: pip install pyg-lib torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.13.0+cpu.html
Expand Down
8 changes: 5 additions & 3 deletions flowbot3d/datasets/flow_dataset_pyg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(
randomize_joints: bool = True,
randomize_camera: bool = True,
n_points: Optional[int] = 1200,
seed: int = 42,
) -> None:
super().__init__()

Expand All @@ -33,21 +34,22 @@ def __init__(
randomize_camera,
n_points,
)
self.seed = seed

def len(self) -> int:
return len(self.dataset)

def get(self, index) -> tgd.Data:
return self.get_data(self.dataset._dataset._ids[index], seed=None)
return self.get_data(self.dataset._dataset._ids[index])

@staticmethod
def get_processed_dir(randomize_joints, randomize_camera):
joint_chunk = "rj" if randomize_joints else "sj"
camera_chunk = "rc" if randomize_camera else "sc"
return f"processed_{joint_chunk}_{camera_chunk}"

def get_data(self, obj_id: str, seed=None) -> Flowbot3DTGData:
data_dict = self.dataset.get_data(obj_id, seed)
def get_data(self, obj_id: str) -> Flowbot3DTGData:
data_dict = self.dataset.get_data(obj_id, self.seed)

data = tgd.Data(
id=data_dict["id"],
Expand Down
2 changes: 1 addition & 1 deletion flowbot3d/evaluate_flow_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def make_eval_dataset(
randomize_camera,
),
n_repeat=1,
n_proc=n_proc,
n_proc_per_worker=n_proc,
seed=42,
)

Expand Down
22 changes: 17 additions & 5 deletions flowbot3d/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def create_flowbot_datasets(
dataset: str,
n_proc=-1,
randomize_camera: bool = True,
seed=42,
) -> Tuple[tgd.Dataset, tgd.Dataset, tgd.Dataset]:
if dataset == "umpnet":
train_dset = CachedByKeyDataset(
Expand All @@ -50,6 +51,7 @@ def create_flowbot_datasets(
root=root / "raw",
split="umpnet-train-train",
randomize_camera=randomize_camera,
seed=seed,
),
data_keys=rpd.UMPNET_TRAIN_TRAIN_OBJ_IDS,
root=root,
Expand All @@ -58,7 +60,8 @@ def create_flowbot_datasets(
randomize_camera,
),
n_repeat=100,
n_proc=n_proc,
n_workers=32,
n_proc_per_worker=n_proc,
)

test_dset = CachedByKeyDataset(
Expand All @@ -67,6 +70,7 @@ def create_flowbot_datasets(
root=root / "raw",
split="umpnet-train-test",
randomize_camera=randomize_camera,
seed=seed,
),
data_keys=rpd.UMPNET_TRAIN_TEST_OBJ_IDS,
root=root,
Expand All @@ -75,7 +79,8 @@ def create_flowbot_datasets(
randomize_camera,
),
n_repeat=1,
n_proc=n_proc,
n_workers=32,
n_proc_per_worker=n_proc,
)

unseen_dset = CachedByKeyDataset(
Expand All @@ -84,6 +89,7 @@ def create_flowbot_datasets(
root=root / "raw",
split="umpnet-test",
randomize_camera=randomize_camera,
seed=seed,
),
data_keys=rpd.UMPNET_TEST_OBJ_IDS,
root=root,
Expand All @@ -92,7 +98,8 @@ def create_flowbot_datasets(
randomize_camera,
),
n_repeat=1,
n_proc=n_proc,
n_workers=32,
n_proc_per_worker=n_proc,
)
elif dataset == "single":
dset = CachedByKeyDataset(
Expand All @@ -101,6 +108,7 @@ def create_flowbot_datasets(
root=root / "raw",
split=["7179"],
randomize_camera=randomize_camera,
seed=seed,
),
data_keys=["7179"],
root=root,
Expand All @@ -109,7 +117,8 @@ def create_flowbot_datasets(
randomize_camera,
),
n_repeat=1,
n_proc=n_proc,
n_workers=32,
n_proc_per_worker=n_proc,
)
train_dset = dset
test_dset = dset
Expand Down Expand Up @@ -257,6 +266,7 @@ def train(
dataset,
n_proc,
randomize_camera=randomize_camera,
seed=seed,
)

train_loader = tgl.DataLoader(train_dset, batch_size, shuffle=True, num_workers=0)
Expand All @@ -276,6 +286,7 @@ def train(
project = "flowbot3d"
logger = plog.WandbLogger(
project=project,
entity="r-pad",
config={
"dataset": dataset,
"model": model_type,
Expand Down Expand Up @@ -306,7 +317,8 @@ def train(

# Create the trainer, which we'll train on only 1 gpu.
trainer = pl.Trainer(
gpus=1,
accelerator="gpu",
devices=[0],
logger=logger,
callbacks=cbs,
log_every_n_steps=log_every_n_steps,
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ authors = [
]
dependencies = [
"gif",
"gym <= 0.20.0",
# "gym <= 0.20.0", # This specific version is probably desired, but the CI no longer seems to build :( will fix later.
"gym",
"h5py",
"numpy <= 1.23.1",
"open3d",
Expand Down

0 comments on commit db00a0e

Please sign in to comment.