BRepNet: A topological message passing system for solid models

Overview

BRepNet: A topological message passing system for solid models

This repository contains the an implementation of BRepNet: A topological message passing system for solid models.

BRepNet kernel image

About BRepNet

BRepNet is a neural network specifically designed to operate on solid models. It uses additional topological information present in the boundary representation (B-Rep) data structure to perform convolutions in a way which is not possible for arbitrary graphs. As B-Reps describe manifolds, they contain additional topological information which includes the ordering of edges around faces as well as the face adjacency. The topology is defined using oriented edges called coedges. Each coedge maintains an adjacency relationship with the next and previous coedge around its parent face, the mating coedge on the adjacent face, the parent face and the parent edge.

B-Rep topology and topological walks

Using this information, we can identify faces, edges and coedges in the neighborhood of some starting coedge (red), using topological walks. A topological walk is a series of instructions we move us from the starting coedge to a nearby entity. In the figure above (B) the we show a walk from the red starting coedge to its mating coedge, to the next coedge in the loop, to mating coedge and finally to the parent face. Using multiple topological walks we can define a group of entities in the neighborhood of the starting coedge. The instructions which define the neighboring entities are marked in the figure (C). The BRepNet implementation allows you to define any group of entities using a kernel file. See here for an example of a kernel file for kernel entities shown above.

Convolution

The BRepNet convolution algorithm concatenates feature vectors from the entities defined in the kernel file relative to the starting coedge (red). The resulting vector is passed through an MLP and the output becomes the hidden state for this coedge in the next network layer. The procedure is repeated for each coedge in the model, then new hidden state vectors for the faces and edges are generated by pooling the coedge hidden states onto their parent faces and edges. See the paper for more details. The actual implementation of the BRepNet convolution can been seen in the BRepNetLayer.forward() method.

Citing this work

@inproceedings{lambourne2021brepnet,
 title = {BRepNet: A Topological Message Passing System for Solid Models},
 author = {Joseph G. Lambourne and Karl D.D. Willis and Pradeep Kumar Jayaraman and Aditya Sanghi and Peter Meltzer and Hooman Shayani},
 eprint = {2104.00706},
 eprinttype = {arXiv},
 eprintclass = {cs.LG},
 booktitle = {IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
 year = {2021}
}

Quickstart

Setting up the environment

git clone https://github.com/AutodeskAILab/BRepNet.git
cd BRepNet
conda env create -f environment.yml
conda activate brepnet

For GPU training you will need to change the pytorch install to include your cuda version. i.e.

conda install pytorch cudatoolkit=11.1 -c pytorch -c conda-forge

For training with multiple workers you may hit errors of the form OSError: [Errno 24] Too many open files. In this case you need to increase the number of available file handles on the machine using

ulimit -Sn 10000

I find I need to set the limit to 10000 for 10 worker threads.

Download the dataset

You can download the step distribution of the Fusion 360 Gallery segmentation dataset from this link. The zip is 3.2Gb. Alternatively download using curl

cd /path/to/where_you_keep_data/
curl https://fusion-360-gallery-dataset.s3-us-west-2.amazonaws.com/segmentation/s2.0.0/s2.0.0.zip -o s2.0.0.zip
unzip s2.0.0.zip

If you are interested in building your own dataset using other step files then the procedure is documented here

Processing the STEP data

Run the quickstart script to extract topology and geometry information from the step data ready to train the network.

cd BRepNet/
python -m pipeline.quickstart --dataset_dir /path/to/where_you_keep_data/s2.0.0 --num_workers 5

This may take up to 10 minutes to complete.

Training the model

You are then ready to train the model. The quickstart script should exit telling you a default command to use which should be something like

python -m train.train \
  --dataset_file /path/to/where_you_keep_data/s2.0.0/processed/dataset.json \
  --dataset_dir  /path/to/where_you_keep_data/s2.0.0/processed/ \
  --max_epochs 50

You may want to adjust the --num_workers and --gpus parameters to match your machine. The model runs with the pytorch-lightning ddp-spawn mode, so you can choose either 1 worker thread and multiple gpus or multiple threads and a single gpu. The options and hyper-parameters for BRepNet can be seen in BRepNet.add_model_specific_args in brepnet.py. For a full list of all hyper-parameters including those defined in pytorch-lightning see

python -m train.train --help

Monitoring the loss, accuracy and IoU

By default BRepNet will log data to tensorboard in a folder called logs. Each time you run the model the logs will be placed in a separate folder inside the logs directory with paths based on the date and time. At the start of training the path to the log folder will be printed into the shell. To monitory the process you can use

cd BRepNet
tensorboard --logdir logs

A trained model is also saved every time the validation loss reaches a minimum. The model will be in the same folder as the tensorboard logs

./logs/<date>/<time>/checkpoints

Testing the network

python -m eval.test \
  --dataset_file /path/to/dataset_file.json \
  --dataset_dir /path/to/data_dir \
  --model BRepNet/logs/<day>/<time>/checkpoints/epoch=x-step=x.ckpt

Visualizing the segmentation data

You can visualize the segmentation data using a Jupyter notebook and the tools in the visualization folder. An example of how to view the segmentation information in the dataset is here.

Evaluating the segmentation on your own STEP data

To evaluate the model on you own step data you can use the script evaluate_folder.py

python -m eval.evaluate_folder  \
  --dataset_dir ./example_files/step_examples
  --dataset_file ./example_files/feature_standardization/s2.0.0_step_all_features.json \
  --model ./example_files/pretrained_models/pretrained_s2.0.0_step_all_features_0519_073100.ckpt

This will loop over all step or stp files in ./example_files/step_examples and create "logits" files in example_files/step_examples/temp_working/logits. The logits files contain one row for each face in the step data. The columns give the probabilities that the corresponding face belongs to a given segment.

The notebook find_and_display_segmentation.ipynb runs through the entire process of evaluating the model and displaying the predicted segmentation.

Running the tests

If you need to run the tests then this can be done using

python -m unittest

The new data-pipeline based on Open Cascade

The original BRepNet pipeline used proprietary code to process data from solid models and convert these to network input. In an effort to make this BRepNet as reusable as possible we have converted this pipeline to work with Open Cascade and python OCC. As with any kind of translation between solid model formats, the translation to step introduces some differences in the data. These are documented here. When training with the default options given above you will obtain very similar numbers to the ones published.

License

Shield: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

Comments
  • Fix reference and typo errors

    Fix reference and typo errors

    Fixed DGL Reference errors for NNconv and MaxPooling in uvnet_encoders.py Fixed import error for unittest in test_dataloader.py and test_dataloaders_equivalent.py Fixed typo errors in quickstart.py and build_dataset_file.py

    opened by gmshashank 6
  • How to visualize the brep data?

    How to visualize the brep data?

    Hi, sorry to bother, firstly thanks for your outstanding works. The visualization results in your paper are very vivid as follows: 87a259f7f2ef84dfc3ec90a45ec6e4d So i am wondering how to draw this kind of rendering images. Any softwares or public codes could be utilized to get them? Thanks in advance :)

    opened by StevenZzz07 2
  • fixed typo error.

    fixed typo error.

    Hi Team, I have done the following changes: pipeline/build_dataset_file.py --> updated sys.exit(1) pipeline/quickstart.py --> updated sys.exit(1) tests/test_dataloader.py --> resolved unittest import error tests/test_dataloaders_equivalent.py --> resolved unittest import error

    Could you please review and merge this Pull Request

    opened by gmshashank 1
  • Hi @zeroright,

    Hi @zeroright,

        Hi @zeroright,
    

    Could you try

    conda install -c lambouj -c conda-forge occwl
    

    and let me know if it works. The source code will be published soon

    Originally posted by @JoeLambourne in https://github.com/AutodeskAILab/BRepNet/issues/1#issuecomment-918109206

    opened by sanweishuwu100 0
  • Update code for latest occwl version

    Update code for latest occwl version

    Why?

    In #11 and #12 we see that updates to the occwl library introduced breaking changes which were not spotted in the example notebooks. Thank you to @cteqeu for reporting the issues and @akashaero for sharing the workaround.

    This PR addresses the problems

    What?

    • A new version of occwl is released see here. We now fix the version of occwl to this version to avoid further unexpected breakage.
    • In jupyter_segmentation_viewer.py we remove the calls to the removed functions.
    • All the notebooks are rerun and retested.
    • Some warnings were firing in pytorch-lightning. To ensure that all metrics are computed correctly we pass the number of faces to the logger as the batch size. Notice that the IoU and accuracy metrics reported in the paper are per-face rather than per solid.
    • In scale_utils.py we make use of the scaling function in occwl rather than re-implementing it here.
    opened by JoeLambourne 0
  • when I used

    when I used "scale_utils.scale_solid_to_unit_box(solid)" process the model ,I found a problem

    Dear Author: I want to scale the model to the same size before processing the model , after I use "scale_utiles.scale_solid_to_unit_box(solid)" to process the model, there is a bug when I use "pipeline\extract_brepnet_data_from_step.py"!

          "assert edge.topods_shape().Location().Transformation().Form() == gp_Identity
          AssertionError"
          
          and "scale the model to the same size" is a good step for train and test? Thanks for your any  opinion!
          I know that the features will be normalized when processing data, but the test results may become worse when the size of the test model is not in the training domain, so it is better to scale the model to the same size in advance?
    
    opened by guozhengyue 0
  • Remove unused UV-Net code

    Remove unused UV-Net code

    Why?

    When I added support for the recommended UV-Net feature set to the BRepNet codebase, several functions were included which are not actually used. This makes the code more complicated than it needs to be.

    What?

    In this PR I am removing

    • _MLP
    • _EdgeConv
    • _NodeConv
    • UVNetGraphEncoder

    If you need this functionality then it is recommended to work directly with the main UV-Net repository

    opened by JoeLambourne 0
  • a bug when Training the model

    a bug when Training the model

    File "E:\3DCSGNET\BRepNet\models\brepnet.py", line 697, in validation_step self.log("validation/loss", output["loss"].item(), on_step=False, on_epoch=True, sync_dist=True, prog_bar=False) File "D:\aconda\envs\3DCSG\lib\site-packages\torch\nn\modules\module.py", line 1131, in getattr type(self).name, name)) AttributeError: 'BRepNet' object has no attribute 'log'

    opened by guozhengyue 0
  • a bug happen when Processing the STEP data

    a bug happen when Processing the STEP data

    python -m pipeline.quickstart --dataset_dir s2.0.0 --num_workers 0 0%| | 0/35680 [00:00<?, ?it/s] Traceback (most recent call last): File "D:\aconda\envs\3DCSG\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "D:\aconda\envs\3DCSG\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "E:\3DCSGNET\BRepNet\pipeline\quickstart.py", line 84, in num_workers=args.num_workers File "E:\3DCSGNET\BRepNet\pipeline\extract_brepnet_data_from_step.py", line 939, in extract_brepnet_data_from_step extract_brepnet_features(file, output_path, feature_schema, mesh_dir, seg_dir) File "E:\3DCSGNET\BRepNet\pipeline\extract_brepnet_data_from_step.py", line 893, in extract_brepnet_features extractor.process() File "E:\3DCSGNET\BRepNet\pipeline\extract_brepnet_data_from_step.py", line 89, in process coedge_point_grids = self.extract_coedge_point_grids(body, entity_mapper) File "E:\3DCSGNET\BRepNet\pipeline\extract_brepnet_data_from_step.py", line 474, in extract_coedge_point_grids coedge_grids.append(self.extract_coedge_point_grid(occwl_oriented_edge, faces)) File "E:\3DCSGNET\BRepNet\pipeline\extract_brepnet_data_from_step.py", line 494, in extract_coedge_point_grid coedge_data = EdgeDataExtractor(coedge, faces, num_samples=num_u, use_arclength_params=True) File "D:\aconda\envs\3DCSG\lib\site-packages\occwl\edge_data_extractor.py", line 45, in init self.left_face, self.right_face = edge.find_left_and_right_faces(faces) File "D:\aconda\envs\3DCSG\lib\site-packages\occwl\edge.py", line 365, in find_left_and_right_faces assert face2.is_left_of(self) AssertionError

    why the AssertionError happen?

    opened by guozhengyue 0
  • Add UV-Net features to BRepNet

    Add UV-Net features to BRepNet

    Why?

    The original BRepNet architecture described in BRepNet: A topological message passing system for solid models used only very simple input features like curve and surface types, face areas, edges lengths and B-Rep data structure flags. A better way to get curve and surface data into a neural network is described in UV-Net: Learning from Boundary Representations. This PR makes use of these preferred input features in BRepNet.

    What?

    • The BRepNet data extraction pipeline has been enhanced to add UV-grids for faces and edges
    • The BRepNet dataloader now passes this information through to the network
    • The BRepNet model now optionally uses the face and edge grid information
    • The pre-trained model has been updated to operate with the UV grid features
    • Embeddings for each face can now be saved from the model
    • A jupyter notebook shows how these embeddings can be used to search for similar faces and edges
    • Dropout is added, yielding improved results
    • Reproducing the results in the paper can still be achieved using the train/reproduce_paper_results.sh script to set the hyper-parameters
    opened by JoeLambourne 0
  • Solving environment: failed with initial frozen solve. Retrying with flexible solve. Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.

    Solving environment: failed with initial frozen solve. Retrying with flexible solve. Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.

    hi @zeroright

    Could you try

    conda install -c lambouj -c conda-forge occwl
    

    and let me know if it works. The source code will be published soon

    Originally posted by @JoeLambourne in https://github.com/AutodeskAILab/BRepNet/issues/1#issuecomment-918109206

    opened by sanweishuwu100 2
  • JupyterSegmentationViewer using outdated Solid class method 'topods_solid()'

    JupyterSegmentationViewer using outdated Solid class method 'topods_solid()'

    As per the title,

    the JuputerSegmentationViewer class uses the topods_solid() method, which was deprecated and then deleted.

    topods_shape() should be used instead.

    opened by Danelrf 2
  • find_and_display_segmentation.ipynb => AttributeError

    find_and_display_segmentation.ipynb => AttributeError


    AttributeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_23316/310475324.py in 6 file_stem = step_file_stems[example_index] 7 print(f"Viewing example {file_stem}") ----> 8 viewer = JupyterSegmentationViewer(file_stem, step_folder, seg_folder=step_folder, logit_folder=logits_folder)

    ~\BRepNet\visualization\jupyter_segmentation_viewer.py in init(self, file_stem, step_folder, seg_folder, logit_folder) 76 assert len(solids) == 1, "Expect only 1 solid" 77 self.solid = solids[0] ---> 78 self.entity_mapper = EntityMapper(self.solid.topods_solid()) 79 80 self.seg_folder = seg_folder

    AttributeError: 'Solid' object has no attribute 'topods_solid'

    opened by cteqeu 2
Owner
Autodesk AI Lab
Autodesk AI Lab
A PyTorch implementation of "Pathfinder Discovery Networks for Neural Message Passing"

A PyTorch implementation of "Pathfinder Discovery Networks for Neural Message Passing" (WebConf 2021). Abstract In this work we propose Pathfind

Benedek Rozemberczki 49 Dec 1, 2022
Official implementation of Rethinking Graph Neural Architecture Search from Message-passing (CVPR2021)

Rethinking Graph Neural Architecture Search from Message-passing Intro The GNAS can automatically learn better architecture with the optimal depth of

Shaofei Cai 48 Sep 30, 2022
Message Passing on Cell Complexes

CW Networks This repository contains the code used for the papers Weisfeiler and Lehman Go Cellular: CW Networks (Under review) and Weisfeiler and Leh

Twitter Research 108 Jan 5, 2023
Neural Message Passing for Computer Vision

Neural Message Passing for Quantum Chemistry Implementation of different models of Neural Networks on graphs as explained in the article proposed by G

Pau Riba 310 Nov 7, 2022
SSL_SLAM2: Lightweight 3-D Localization and Mapping for Solid-State LiDAR (mapping and localization separated) ICRA 2021

SSL_SLAM2 Lightweight 3-D Localization and Mapping for Solid-State LiDAR (Intel Realsense L515 as an example) This repo is an extension work of SSL_SL

Wang Han 王晗 1.3k Jan 8, 2023
Project Aquarium is a SUSE-sponsored open source project aiming at becoming an easy to use, rock solid storage appliance based on Ceph.

Project Aquarium Project Aquarium is a SUSE-sponsored open source project aiming at becoming an easy to use, rock solid storage appliance based on Cep

Aquarist Labs 73 Jul 21, 2022
Automatic Calibration for Non-repetitive Scanning Solid-State LiDAR and Camera Systems

ACSC Automatic extrinsic calibration for non-repetitive scanning solid-state LiDAR and camera systems. System Architecture 1. Dependency Tested with U

KINO 192 Dec 13, 2022
FIRA: Fine-Grained Graph-Based Code Change Representation for Automated Commit Message Generation

FIRA is a learning-based commit message generation approach, which first represents code changes via fine-grained graphs and then learns to generate commit messages automatically.

Van 21 Dec 30, 2022
Torchlight2 lan game server tool - A message forwarding tool for Torchlight 2 lan game

Torchlight 2 Lan Game Server Tool A message forwarding tool for Torchlight 2 lan

Huaijun Jiang 3 Nov 1, 2022
Complete system for facial identity system. Include one-shot model, database operation, features visualization, monitoring

Complete system for facial identity system. Include one-shot model, database operation, features visualization, monitoring

null 2 Dec 28, 2021
Complete system for facial identity system

Complete system for facial identity system. Include one-shot model, database operation, features visualization, monitoring

null 4 May 2, 2022
Face-Recognition-based-Attendance-System - An implementation of Attendance System in python.

Face-Recognition-based-Attendance-System A real time implementation of Attendance System in python. Pre-requisites To understand the implentation of F

Muhammad Zain Ul Haque 1 Dec 31, 2021
Face-Recognition-Attendence-System - This face recognition Attendence system using Python

Face-Recognition-Attendence-System I have developed this face recognition Attend

Riya Gupta 4 May 10, 2022
Simple-System-Convert--C--F - Simple System Convert With Python

Simple-System-Convert--C--F REQUIREMENTS Python version : 3 HOW TO USE Run the c

Jonathan Santos 2 Feb 16, 2022
Real-Time-Student-Attendence-System - Real Time Student Attendence System

Real-Time-Student-Attendence-System The Student Attendance Management System Pro

Rounak Das 1 Feb 15, 2022
E2e music remastering system - End-to-end Music Remastering System Using Self-supervised and Adversarial Training

End-to-end Music Remastering System This repository includes source code and pre

Junghyun (Tony) Koo 37 Dec 15, 2022
UT-Sarulab MOS prediction system using SSL models

UTMOS: UTokyo-SaruLab MOS Prediction System Official implementation of "UTMOS: UTokyo-SaruLab System for VoiceMOS Challenge 2022" submitted to INTERSP

sarulab-speech 58 Nov 22, 2022