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)
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.
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.
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
conda create -n shap-e python=3.10
conda activate shap-e
// example
cd shap-e-local-main
pip install -e .
pip install pyyaml ipywidgets fvcore iopath
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')
python pytorch3dPrep.py
This program output a string ("py310_cu117_pyt201", for example)
Remember this string.
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
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.
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}