• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The procedure and the code to run shap-e sample code locally.

Shap-E-local

The code to run shap-e text-to-3d sample code locally.
The original code is available at (https://github.com/openai/shap-e/blob/main/shap_e/examples/sample_text_to_3d.ipynb)

Why I make this project?

One nice thing about being able to run code locally is that 3D models can be generated without an Internet connection.

For this reason, I created this project as a sample for those who want to generate 3D models offline, or for those who are looking for a place to boast their ample GPU power.

Demo

I imported the 3D models (.obj) generated by the following prompts into Blender and rendered them:

  • an apple
  • a shark
  • a table

The walls and the floor is blender's built-in plane object. shap-e_test

Environments

OS: Ubuntu 20.04.5 LTS
CPU: Intel(R) Core(TM) i7-6800K CPU @ 3.40GHz
GPU: NVIDIA GeForce RTX 3090
Cuda version: 12.1
pip version: 23.1.2
conda version: 23.5.0

Procedure

1. Download this project as a zip folder, then unzip it

2. Create a virtual environment using Anaconda, then activate it

conda create -n shap-e python=3.10
conda activate shap-e

3. Change your current directory to unzipped folder

// example
cd shap-e-local-main

4. Install required libraries

pip install -e .
pip install pyyaml ipywidgets fvcore iopath

5. Run testTorch.py to confirm torch is recognizing cuda

python testTorch.py

If the output of this program looks like this, you are okay to go:

PyTorch is using: cuda  
PyTorch version: 2.0.1+cu117  
Result of tensor operation: tensor([ 8., 15.], device='cuda:0')  

6. Run pytorch3dPrep.py to check suitable version of pytorch3d

python pytorch3dPrep.py

This program output a string ("py310_cu117_pyt201", for example)
Remember this string.

7. Install pytorch3d library

pip install --no-index --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/{output string}/download.html

// example
pip install --no-index --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py310_cu117_pyt201/download.html

8. Finally, let's generate a 3D model!

Before running the code below, you can edit textTo3D.py to change the input text prompt, batch_size, etc.

python textTo3D.py

This program outputs some .obj files and .ply files according to the batch_size you specified.

9. For those who want to see a preview of generated 3D models..

First install required libraries to display 3D objects.

pip install vedo
pip install open3d

Then, use the commands below to inspect generated files.
(command line argument "filepath" is the path of a file except file extension part.
e.g. you type "python displayPly.py output/mesh_0" to inspect "output/mesh_0.ply" file.)

python displayObj.py {filepath}
python displayPly.py {filepath}