Skip to content

How to run the code

Takumi Moriya edited this page Apr 28, 2017 · 13 revisions

I developed voxelDCGAN using TensorFlow. TensorFlow is Google's machine learning library which is available mainly in Python (programming language).

Setup

Install Python

To run the code, you first need to install Python. I recommend that you install Python using pyenv because it is easy to manage Python versions. Please follow here for the installation of pyenv.

After you have installed pyenv, you can install Python with the following command:

$ pyenv install 2.7.12

If you don't get any error messages, Python has been successfully installed.

The next step is to install three Python packages:

The commands to install tensorflow and numpy are the following:

$ pip install tensorflow
$ pip install numpy

In case you run the code on GPUs, you need to install TensorFlow with GPU support:

$ pip install tensorflow-gpu

Any troubles with installing TensorFlow, please see official installation guide.

binvox-rw-py can not be installed using pip now. You can install this package by putting binvox_rw.py to your project folder or copying it to site-packages directory. In my case, I just put the file in voxel-dcgan folder and rename the file to binvox.py.

Install Binvox

Binvox is required when you convert mesh models (.obj, .stl, .ply, etc...) to volumetric models. Binvox installation is simple. If you are using macOS or Linux, please follow the steps below.

  1. download binvox from http://www.patrickmin.com/binvox/.
  2. move the downloaded file to /usr/local/bin.
$ sudo mv ~/Downloads/binvox /usr/local/bin
  1. run the following command:
$ binvox

--- [binvox] mesh voxelizer, version 1.22, build #624 on 2016/03/06 16:12:29
--- written by Patrick Min, 2004-2016
...

Success!

Dataset

I used ShapeNetCore dataset for training voxelDCGAN. 3D models are provided as .obj file format. Accordingly, I converted them to volumetric models using binvox.

For the conversion, the following code may be helpful.

import glob
import os
import subprocess
import sys

voxsize = 32
paths = glob.glob("path/to/dataset/*.obj")
print "number of data:", len(paths)

with open(os.devnull, 'w') as devnull:
    for i, path in enumerate(paths):
        cmd = "binvox -d {0} -cb -e {1}".format(voxsize, path)
        ret = subprocess.check_call(cmd.split(' '), stdout=devnull, stderr=devnull)
        if ret != 0:
            print "error", i, path
        else:
            print i, path

3D dataset list

Training

Once you have finished previous sections, next we train the generator and the discriminator.

To train the networks, you first specify dataset path in config.py

dataset_path = "path/to/dataset/*.binvox"
params_path = ""

and then run train.py

$ python train.py

It takes about 6 hours to get good results on NVIDIA GeForce GTX TITAN X GPU. Training time depends on your machine specs.

Visualization

Coming soon.

Clone this wiki locally