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

Update code for latest occwl version #13

Merged
merged 5 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
- scikit-learn
- pytorch-lightning
- xlsxwriter
- occwl
- occwl=1.0.0
- jupyter
- pythreejs
- tensorboard
Expand Down
118 changes: 105 additions & 13 deletions models/brepnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,37 @@ def brepnet_step(self, batch, batch_idx, save_segmentation_output):
def training_step(self, batch, batch_idx):
save_segmentation_output = False
output = self.brepnet_step(batch, batch_idx, save_segmentation_output)


# The batch size is the number of faces
num_faces = self.num_faces_in_batch(batch)

# Log some data to tensorboard
self.log("loss", output["loss"].item(), on_step=True, on_epoch=False)
self.log("train/loss", output["loss"].item(), on_step=False, on_epoch=True, sync_dist=True, prog_bar=False)
self.log("train/accuracy", output["accuracy"], on_step=False, on_epoch=True, sync_dist=True, prog_bar=False)
self.log(
"loss",
output["loss"].item(),
batch_size=num_faces,
on_step=True,
on_epoch=False
)

self.log(
"train/loss",
output["loss"].item(),
batch_size=num_faces,
on_step=False,
on_epoch=True,
sync_dist=True,
prog_bar=False
)
self.log(
"train/accuracy",
output["accuracy"],
batch_size=num_faces,
on_step=False,
on_epoch=True,
sync_dist=True,
prog_bar=False
)
return output["loss"]


Expand All @@ -694,7 +720,19 @@ def validation_step(self, batch, batch_idx):
"""
save_segmentation_output = False
output = self.brepnet_step(batch, batch_idx, save_segmentation_output)
self.log("validation/loss", output["loss"].item(), on_step=False, on_epoch=True, sync_dist=True, prog_bar=False)

# The batch size is the number of faces
num_faces = self.num_faces_in_batch(batch)

self.log(
"validation/loss",
output["loss"].item(),
batch_size=num_faces,
on_step=False,
on_epoch=True,
sync_dist=True,
prog_bar=False
)
return output


Expand Down Expand Up @@ -729,7 +767,8 @@ def collate_epoch_outputs(self, outputs):
return {
"accuracy": accuracy,
"mean_iou": mean_iou,
"per_class_iou": per_class_iou
"per_class_iou": per_class_iou,
"total_num_faces": total_num_faces
}


Expand All @@ -738,16 +777,41 @@ def validation_epoch_end(self, outputs):
Collate information from all validation batches
"""
output = self.collate_epoch_outputs(outputs)
self.log("validation/accuracy", output["accuracy"], on_step=False, on_epoch=True, sync_dist=True, prog_bar=False)
self.log("validation/mean_iou", output["mean_iou"], on_step=False, on_epoch=True, sync_dist=True, prog_bar=False)
num_faces = output["total_num_faces"]
self.log(
"validation/accuracy",
output["accuracy"],
batch_size=num_faces,
on_step=False,
on_epoch=True,
sync_dist=True,
prog_bar=False
)
self.log(
"validation/mean_iou",
output["mean_iou"],
batch_size=num_faces,
on_step=False,
on_epoch=True,
sync_dist=True,
prog_bar=False
)

# If the segment names information is provided then log the
# per-class IoU
if self.segment_names is not None:
assert len(self.segment_names) == len(output["per_class_iou"])
for name, iou in zip(self.segment_names, output["per_class_iou"]):
log_name = f"validation/{name}_iou"
self.log(log_name, iou, on_step=False, on_epoch=True, sync_dist=True, prog_bar=False)
self.log(
log_name,
iou,
batch_size=num_faces,
on_step=False,
on_epoch=True,
sync_dist=True,
prog_bar=False
)

def test_step(self, batch, batch_idx):
"""
Expand All @@ -762,9 +826,26 @@ def test_epoch_end(self, outputs):
Collate the results from all test batches
"""
output = self.collate_epoch_outputs(outputs)

self.log("test/accuracy", output["accuracy"], on_step=False, on_epoch=True, sync_dist=True, prog_bar=False)
self.log("test/mean_iou", output["mean_iou"], on_step=False, on_epoch=True, sync_dist=True, prog_bar=False)
num_faces = output["total_num_faces"]

self.log(
"test/accuracy",
output["accuracy"],
batch_size=num_faces,
on_step=False,
on_epoch=True,
sync_dist=True,
prog_bar=False
)
self.log(
"test/mean_iou",
output["mean_iou"],
batch_size=num_faces,
on_step=False,
on_epoch=True,
sync_dist=True,
prog_bar=False
)

# If the segment names information is provided then log the
# per-class IoU
Expand Down Expand Up @@ -916,4 +997,15 @@ def test_dataloader(self):


def configure_optimizers(self):
return torch.optim.Adam(self.parameters(), lr = self.opts.learning_rate)
return torch.optim.Adam(self.parameters(), lr = self.opts.learning_rate)


def num_faces_in_batch(self, batch):
"""
Find the number of B-Rep faces in this batch
"""
Xf = batch["face_features"]
labels = batch["labels"]
num_faces = labels.size(0)
assert num_faces == Xf.size(0), "Xf tensor must have size equal to num_faces"
return num_faces
62 changes: 23 additions & 39 deletions notebooks/brepnet_input_features_similarity_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 5,
"id": "68fd06c7",
"metadata": {},
"outputs": [],
Expand All @@ -171,7 +171,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 6,
"id": "88f6c24a",
"metadata": {
"scrolled": false
Expand All @@ -187,7 +187,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "388371b520d849e5bcbee05f505b5d7d",
"model_id": "46ed98da437a4ab59fdf88273da9ef8c",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -208,7 +208,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 8,
"id": "2d6321f8",
"metadata": {},
"outputs": [],
Expand All @@ -218,7 +218,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 9,
"id": "72336c63",
"metadata": {
"scrolled": false
Expand All @@ -240,7 +240,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 10,
"id": "b5d63d32",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -284,15 +284,15 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 11,
"id": "664c4f00",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Interval [0.0, 11.654363636270176]\n"
"Interval [0.0, 21.304689088927404]\n"
]
}
],
Expand All @@ -313,7 +313,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 12,
"id": "5390a62a",
"metadata": {
"scrolled": false
Expand All @@ -330,7 +330,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c9ea2ff4959643c9b789c6ad8601b140",
"model_id": "e6116f9fdf0647c88f044a18bda8c6f0",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -345,14 +345,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"19\n",
"Close file 52890_dc92327c_3\n"
"0\n",
"Close file 21492_8bd34fc1_15\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "58a6f6b2f5a3421b86f75f6e2a4cb716",
"model_id": "ab77ba55c8a54e38b94bd35e87e60d47",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -367,14 +367,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"7\n",
"Close file 30274_ca0d10b2_1\n"
"9\n",
"Close file 56436_2a8fc254_3\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7a5c1ea406524e2b862a772e182d48df",
"model_id": "1539d1dd803c4b5cb8303b648f70176e",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -389,14 +389,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"14\n",
"Close file 148082_8b644daf_0\n"
"10\n",
"Close file 37117_89aac9d4_9\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "02fb24f9c41645fd9099f1851b0c7fda",
"model_id": "9d0c888ba4de463c9a279d00773dcd9a",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -411,14 +411,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"11\n",
"Close file 134103_d89213ee_0\n"
"20\n",
"Close file 44647_d83249a9_0\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f864c150434e49708d2dc4fa8653bbe6",
"model_id": "699f75403047422e96ea520910127174",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -441,22 +441,6 @@
" dists_to_view = min_dists_for_each_face[index]\n",
" close_viewer.display_faces_with_heatmap(dists_to_view, interval)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5ea0cc1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe4bcfd5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -475,7 +459,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"version": "3.7.12"
}
},
"nbformat": 4,
Expand Down
Loading