Giter Club home page Giter Club logo

hnc-cad's Introduction

Hierarchical Neural Coding for Controllable CAD Model Generation (ICML 2023)

arXiv webpage Youtube

Xiang Xu, Pradeep Kumar Jayaraman, Joseph G. Lambourne, Karl D.D. Willis, Yasutaka Furukawa

alt HNCode

We present a novel generative model for Computer Aided Design (CAD) that 1) represents high-level design concepts of a CAD model as a three-level hierarchical tree of neural codes, from global part arrangement down to local curve geometry; and 2) controls the generation of CAD models by specifying the target design using a code tree. Our method supports diverse and higher-quality generation; novel user controls while specifying design intent; and autocompleting a partial CAD model under construction.

Requirements

Environment

  • Linux
  • Python 3.8
  • CUDA >= 11.4
  • GPU with 24 GB ram recommended

Dependencies

  • PyTorch >= 1.10
  • Install pythonocc following the instruction here (use mamba if conda is too slow).
  • Install other dependencies with pip install -r requirements.txt

We also provide the docker image. Note: only tested on CUDA 11.4.

Dataset

We use the dataset from DeepCAD for training and evaluation.

The sketch-and-extrude sequences need to be first converted to our obj format following the steps from SkexGen.

Run the following script to download our post-processed DeepCAD data in obj format

python scripts/download.py

After the data is downloaded, run this script to get the solid, profile, loop and CAD model data

sh scripts/process.sh

Run the deduplication script, this will output post-filtered data as train_deduplicate.pkl

sh scripts/deduplicate.sh

Download the ready-to-use post-deduplicate data.

Usage

Codebook

Train the three-level codebook with

sh scripts/codebook.sh

Download our pretrained codebook module from here.

After the codebooks are trained, extract the neural codes corresponding to each training data with

sh scripts/extract_code.sh

Extracted codes from the pretrained model are available here.

Random Generation

Run the following script to train the code-tree generator and model generator for unconditional generation

sh scripts/gen_uncond.sh

Download our pretrained unconditional generation module from here.

For testing, run this script to generate 1000 CAD samples and visualize the results

sh scripts/sample_uncond.sh

For evaluation, uncomment the eval script in sample_uncond.sh, this would generate > 10,000 samples. Then compute JSD, MMD, and COV scores using eval.sh. Warning: this step can be very slow.

sh scripts/eval.sh

Please also download the test data and unzip it inside the data folder. This is required for computing the evaluation metrics.

Conditional Generation

Train the full model including model encoder for conditional CAD generation

sh scripts/gen_cond.sh

For testing (e.g CAD autocomplete), run this script to generate full CAD model from partial extruded profiles.

sh scripts/sample_cond.sh

Acknowledgement

This research is partially supported by NSERC Discovery Grants with Accelerator Supplements and DND/NSERC Discovery Grant Supplement, NSERC Alliance Grants, and John R. Evans Leaders Fund (JELF).

Citation

If you find our work useful in your research, please cite the following paper

@article{xu2023hierarchical,
  title={Hierarchical Neural Coding for Controllable CAD Model Generation},
  author={Xu, Xiang and Jayaraman, Pradeep Kumar and Lambourne, Joseph G and Willis, Karl DD and Furukawa, Yasutaka},
  journal={arXiv preprint arXiv:2307.00149},
  year={2023}
}

Misc

  • If you encounter the issue of "No loop matching the specified signature", try downgrading numpy to 1.23.

hnc-cad's People

Contributors

samxuxiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hnc-cad's Issues

Training in DistributedDataParallel

Hi, Sam.

Fantastic work on CAD conditional Generation!

I just wonder if i train the model using DistributedDataParallel, will the codebook on each GPU remain the same? I tried to use your update code on multiple GPUs using DistributedDataParallel, but it seems that the number of updated codes on each GPU is not the same when I uncomment the print code.

I know the training data will be shuffled across GPUs during training, but such reinitialization scheme made me doubt whether the codebook will remain the same after several epochs.

Worse still, when I asked New Bing about whether the codebook will remain the same after backward of each batch. New Bing tells me No.....

Now I really have no idea about how the reinitialization scheme and the codebook works on DDP.

Any idea helps. And, happy Moon Festival!

Weijian.

How to sample cond with onshape models

I don't understand how we're supposed to sample conditionally from our own onshape model, even with a trained conditional generator.

I tried to use it to complete my onshape creations, following the procedure from skexgen:

  • I first download the json file with DeepCAD onshape parser
  • transformed the json files into obj files and normalize then with your SkexGen procedure.
  • finally, I applied the data_process/convert.py file from this repo (with format 'model').

The problem comes from the fact that to be used, the data must have all its solid_uid, profile_uids and loop_uids in the codebook. From what I could understand, the solid_uid is just the order in which the model appears in the DeepCAD dataset and the others uids derive directly from it.

I tried to force the uids to be contained in the codebooks but obviously the results are not great even with a mid-trained model (~125 epochs).

What is the correct procedure to complete our own OnShape models? I'd be very interested in knowing if such a procedure exists.

Could you provide a conditional pre-trained model?

We are very interested in the CAD autocomplete you have developed.
But we don't want to retrain the model in the short term.
So could you provide a conditional pre-trained model?
Thank you again, and sorry for the trouble.

pythonocc visualization error

Thank you for your amazing work. When visualizing sample results, the following error appears. Is it possible to identify the cause? Also, could you provide the version of pythonocc?

##### 3D rendering pipe initialisation #####
Display3d class initialization starting ...
  0%|                                                                             | 0/730 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/media/data/hnc-cad/gen/cad_img.py", line 72, in <module>
    main()
  File "/media/data/hnc-cad/gen/cad_img.py", line 68, in main
    render(shape, output_path.joinpath(fn.stem + ".png"), args.width, args.height)
  File "/media/data/hnc-cad/gen/cad_img.py", line 15, in render
    viewer = Viewer3d()
  File "/home/.conda/envs/pyoccenv/lib/python3.9/site-packages/OCC/Display/OCCViewer.py", line 145, in __init__
    Display3d.__init__(self)
  File "/home/.conda/envs/pyoccenv/lib/python3.9/site-packages/OCC/Core/Visualization.py", line 180, in __init__
    _Visualization.Display3d_swiginit(self, _Visualization.new_Display3d())
RuntimeError: Aspect_DisplayConnectionDefinitionErrorCan not connect to the server "" raised from method Display3d of class Display3d
  File "/Users/Desktop/Code/gpus/hnc-cad/gen/cad_img.py", line 72, in <module>
    main()
  File "/Users/Desktop/Code/gpus/hnc-cad/gen/cad_img.py", line 68, in main
    render(shape, output_path.joinpath(fn.stem + ".png"), args.width, args.height)
  File "/Users/Desktop/Code/gpus/hnc-cad/gen/cad_img.py", line 16, in render
    viewer.Create(phong_shading=True, create_default_lights=True)
  File "/Users/miniconda3/envs/pyoccenv/lib/python3.9/site-packages/OCC/Display/OCCViewer.py", line 216, in Create
    self.InitOffscreen(640, 480)
  File "/Users/miniconda3/envs/pyoccenv/lib/python3.9/site-packages/OCC/Core/Visualization.py", line 215, in InitOffscreen
    return _Visualization.Display3d_InitOffscreen(self, size_x, size_y)
RuntimeError: Aspect_WindowDefinitionErrorCocoa application should be instantiated before window raised from method InitOffscreen of class Display3d

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.