├── 3D Voxel Models Preprocessing.ipynb ├── 3D_GAN_AWS.ipynb ├── 3D_Voxel_Files ├── chair_000000000_1 ├── chair_000000001_1 ├── chair_000000002_1 ├── chair_000000005_1 ├── chair_000000010_1 ├── chair_000000013_1 ├── chair_000000014_1 ├── chair_000000015_1 ├── chair_000000016_1 ├── chair_000000021_1 ├── chair_000000023_1 ├── chair_000000024_1 ├── chair_000000029_1 ├── chair_000000030_1 ├── chair_000000031_1 ├── chair_000000032_1 ├── chair_000000033_1 ├── chair_000000035_1 ├── chair_000000036_1 ├── chair_000000037_1 ├── chair_000000038_1 ├── chair_000000039_1 ├── chair_000000040_1 ├── chair_000000041_1 ├── chair_000000042_1 ├── chair_000000045_1 ├── chair_000000047_1 ├── chair_000000049_1 ├── chair_000000052_1 ├── chair_000000053_1 ├── chair_000000054_1 ├── chair_000000055_1 ├── chair_000000056_1 ├── chair_000000057_1 ├── chair_000000059_1 ├── chair_000000061_1 ├── chair_000000066_1 ├── chair_000000068_1 ├── chair_000000069_1 ├── chair_000000072_1 ├── chair_000000074_1 ├── chair_000000075_1 ├── chair_000000078_1 ├── chair_000000079_1 ├── chair_000000082_1 ├── chair_000000086_1 ├── chair_000000087_1 ├── chair_000000089_1 ├── chair_000000093_1 ├── chair_000000094_1 ├── chair_000000096_1 ├── chair_000000097_1 ├── chair_000000099_1 ├── chair_000000100_1 ├── chair_000000101_1 ├── chair_000000103_1 ├── chair_000000108_1 ├── chair_000000111_1 ├── chair_000000115_1 ├── chair_000000118_1 ├── chair_000000121_1 ├── chair_000000122_1 ├── chair_000000123_1 ├── chair_000000124_1 ├── chair_000000125_1 ├── chair_000000126_1 ├── chair_000000127_1 ├── chair_000000128_1 ├── chair_000000129_1 ├── chair_000000130_1 ├── chair_000000131_1 ├── chair_000000132_1 ├── chair_000000134_1 ├── chair_000000136_1 ├── chair_000000137_1 ├── chair_000000139_1 ├── chair_000000140_1 ├── chair_000000141_1 ├── chair_000000143_1 ├── chair_000000144_1 ├── chair_000000148_1 ├── chair_000000150_1 ├── chair_000000153_1 ├── chair_000000154_1 ├── chair_000000156_1 ├── chair_000000159_1 ├── chair_000000160_1 ├── chair_000000161_1 ├── chair_000000162_1 ├── chair_000000163_1 ├── chair_000000165_1 ├── chair_000000166_1 ├── chair_000000167_1 ├── chair_000000173_1 ├── chair_000000174_1 ├── chair_000000176_1 ├── chair_000000177_1 ├── chair_000000179_1 └── chair_000000180_1 ├── README.md ├── chair_gif.gif └── generated_chair.png /3D Voxel Models Preprocessing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Preprocess 3D files to appropriate format for training" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 2, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [ 18 | "import numpy as np\n", 19 | "import os" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "### Do it once: read matlab voxel file (size = 30 by 30 by 30), turn into 3d array (size = 32 by 32 by 32), and save to local as binary ndarray\n", 27 | "
The Matlab voxel files can be downloaded from here.
" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 233, 33 | "metadata": { 34 | "collapsed": false 35 | }, 36 | "outputs": [], 37 | "source": [ 38 | "import scipy.io\n", 39 | "\n", 40 | "new_train_dir = '/Users/yuxuanzhang/3D_Voxel_Files/'\n", 41 | "train_dir = '/Users/yuxuanzhang/Downloads/3DShapeNets/volumetric_data/chair/30/train/'\n", 42 | "\n", 43 | "if not os.path.exists(new_train_dir):\n", 44 | " os.makedirs(new_train_dir)\n", 45 | "\n", 46 | "train_file_names = [f for f in os.listdir(train_dir) if f.endswith('_1.mat')]\n", 47 | "for f in train_file_names:\n", 48 | " voxel_matrix = scipy.io.loadmat(train_dir+f)['instance']\n", 49 | " # add padding to original matrix to make it 32*32*32\n", 50 | " voxel_matrix=np.pad(voxel_matrix,(1,1),'constant',constant_values=(0,0)) \n", 51 | " voxel_matrix.dump(new_train_dir+f[:-4])\n", 52 | "\n", 53 | "test_dir = '/Users/yuxuanzhang/Downloads/3DShapeNets/volumetric_data/chair/30/test/'\n", 54 | "test_file_names = [f for f in os.listdir(test_dir) if f.endswith('_1.mat')] \n", 55 | "for f in test_file_names:\n", 56 | " voxel_matrix = scipy.io.loadmat(test_dir+f)['instance']\n", 57 | " # add padding to original matrix to make it 32*32*32\n", 58 | " voxel_matrix=np.pad(voxel_matrix,(1,1),'constant',constant_values=(0,0)) \n", 59 | " voxel_matrix.dump(new_train_dir+f[:-4])" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": {}, 65 | "source": [ 66 | "### Turn a voxel 3d array into mesh" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 3, 72 | "metadata": { 73 | "collapsed": false 74 | }, 75 | "outputs": [], 76 | "source": [ 77 | "voxel_matrix = np.load('/Users/yuxuanzhang/3D_Voxel_Files/chair_000000000_1')" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 4, 83 | "metadata": { 84 | "collapsed": false 85 | }, 86 | "outputs": [], 87 | "source": [ 88 | "from skimage import measure\n", 89 | "from stl import mesh\n", 90 | "# Use marching cubes to obtain the surface mesh of these ellipsoids\n", 91 | "vertices, faces = measure.marching_cubes(voxel_matrix,0.0)\n", 92 | "\n", 93 | "# Create the mesh and save as STL\n", 94 | "chair = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))\n", 95 | "for i, f in enumerate(faces):\n", 96 | " for j in range(3):\n", 97 | " chair.vectors[i][j] = vertices[f[j],:]" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 285, 103 | "metadata": { 104 | "collapsed": true 105 | }, 106 | "outputs": [], 107 | "source": [ 108 | "# Write the mesh to STL file \n", 109 | "chair.save('matlab_chair.stl')" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 5, 115 | "metadata": { 116 | "collapsed": false 117 | }, 118 | "outputs": [ 119 | { 120 | "name": "stderr", 121 | "output_type": "stream", 122 | "text": [ 123 | "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/collections.py:446: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison\n", 124 | " if self._edgecolors == 'face':\n", 125 | "/Library/Python/2.7/site-packages/ipykernel/__main__.py:12: DeprecationWarning: Non-string object detected for the array ordering. Please pass in 'C', 'F', 'A', or 'K' instead\n", 126 | "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/mpl_toolkits/mplot3d/axes3d.py:890: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.\n", 127 | " if self.button_pressed in self._rotate_btn:\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "# Plot out the meshed object\n", 133 | "from mpl_toolkits import mplot3d\n", 134 | "from matplotlib import pyplot\n", 135 | "\n", 136 | "figure = pyplot.figure()\n", 137 | "axes = mplot3d.Axes3D(figure)\n", 138 | "\n", 139 | "# Load the STL files and add the vectors to the plot\n", 140 | "axes.add_collection3d(mplot3d.art3d.Poly3DCollection(chair.vectors))\n", 141 | "\n", 142 | "# Auto scale to the mesh size\n", 143 | "scale = chair.points.flatten(-1)\n", 144 | "axes.auto_scale_xyz(scale, scale, scale)\n", 145 | "\n", 146 | "# Show the plot to the screen\n", 147 | "pyplot.show()" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "### Read .OFF file and turn into STL format" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 1, 160 | "metadata": { 161 | "collapsed": true 162 | }, 163 | "outputs": [], 164 | "source": [ 165 | "from stl import mesh" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 72, 171 | "metadata": { 172 | "collapsed": false 173 | }, 174 | "outputs": [], 175 | "source": [ 176 | "vertices = [] # placeholder for x,y,z coordinates of the vertices\n", 177 | "faces = [] # placeholder for the indices of three vertices that form a trangular face\n", 178 | "\n", 179 | "f = open(\"chair_0461.off\",\"r\")\n", 180 | "line = f.readline()\n", 181 | "n = 0\n", 182 | "while line:\n", 183 | " if n>1:\n", 184 | " line = line.rstrip() # get rid of '\\n' at the end\n", 185 | " parsed_list = line.split(\" \")\n", 186 | " if len(parsed_list) == 3: \n", 187 | " vertices.append([float(coordinate) for coordinate in parsed_list])\n", 188 | " else:\n", 189 | " faces.append([int(index) for index in parsed_list[1:]])\n", 190 | " line = f.readline()\n", 191 | " n += 1\n", 192 | "f.close()\n", 193 | "\n", 194 | "vertices = np.array(vertices)\n", 195 | "faces = np.array(faces)\n", 196 | "#print vertices\n", 197 | "#print faces" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 74, 203 | "metadata": { 204 | "collapsed": false 205 | }, 206 | "outputs": [], 207 | "source": [ 208 | "# Create the mesh and save as STL\n", 209 | "chair = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))\n", 210 | "for i, f in enumerate(faces):\n", 211 | " for j in range(3):\n", 212 | " chair.vectors[i][j] = vertices[f[j],:]\n", 213 | "\n", 214 | "# Write the mesh to file \"chair.stl\"\n", 215 | "chair.save('dd.stl')" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": 98, 221 | "metadata": { 222 | "collapsed": false 223 | }, 224 | "outputs": [ 225 | { 226 | "name": "stderr", 227 | "output_type": "stream", 228 | "text": [ 229 | "/Library/Python/2.7/site-packages/ipykernel/__main__.py:12: DeprecationWarning: Non-string object detected for the array ordering. Please pass in 'C', 'F', 'A', or 'K' instead\n" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "# visualize a mesh\n", 235 | "from mpl_toolkits import mplot3d\n", 236 | "from matplotlib import pyplot\n", 237 | "\n", 238 | "# Create a new plot\n", 239 | "figure = pyplot.figure()\n", 240 | "axes = mplot3d.Axes3D(figure)\n", 241 | "\n", 242 | "# Load the STL files and add the vectors to the plot\n", 243 | "axes.add_collection3d(mplot3d.art3d.Poly3DCollection(chair.vectors))\n", 244 | "\n", 245 | "# Auto scale to the mesh size\n", 246 | "scale = chair.points.flatten(-1)\n", 247 | "axes.auto_scale_xyz(scale, scale, scale)\n", 248 | "\n", 249 | "# Show the plot to the screen\n", 250 | "pyplot.show()" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": null, 256 | "metadata": { 257 | "collapsed": true 258 | }, 259 | "outputs": [], 260 | "source": [] 261 | } 262 | ], 263 | "metadata": { 264 | "kernelspec": { 265 | "display_name": "Python 2", 266 | "language": "python", 267 | "name": "python2" 268 | }, 269 | "language_info": { 270 | "codemirror_mode": { 271 | "name": "ipython", 272 | "version": 2 273 | }, 274 | "file_extension": ".py", 275 | "mimetype": "text/x-python", 276 | "name": "python", 277 | "nbconvert_exporter": "python", 278 | "pygments_lexer": "ipython2", 279 | "version": "2.7.5" 280 | } 281 | }, 282 | "nbformat": 4, 283 | "nbformat_minor": 0 284 | } 285 | -------------------------------------------------------------------------------- /3D_GAN_AWS.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 3D-GAN" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": { 14 | "collapsed": false 15 | }, 16 | "outputs": [], 17 | "source": [ 18 | "import numpy as np\n", 19 | "import tensorflow as tf\n", 20 | "import tensorlayer as tl\n", 21 | "from tensorlayer.layers import *\n", 22 | "import os\n", 23 | "import time" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "### Configuration" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": { 37 | "collapsed": false 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "tf.reset_default_graph()\n", 42 | "np.random.seed(1) \n", 43 | "tf.set_random_seed(1)\n", 44 | "\n", 45 | "training_epochs = 20001 # num of epochs to train discriminator and generator jointly\n", 46 | "batch_size = 64 # batch size for training the model\n", 47 | "\n", 48 | "# ---- max layer 256 for generator ---#\n", 49 | "#alpha_g = 0.001\n", 50 | "#alpha_d = 0.000018\n", 51 | "\n", 52 | "# ---- max layer 512 for generator ---#\n", 53 | "# okay from 3k to 8k epochs\n", 54 | "alpha_g = 0.0015\n", 55 | "alpha_d = 0.000024\n", 56 | "\n", 57 | "beta1 = 0.5 # the fraction factor used in the first momentum term from Adam optimizer\n", 58 | "logs_path = \"./3d_gan_log\" # directory to save the training log to\n", 59 | "train_sample_directory = './3d_gan/train_sample/' # directory to save the generated 3d model during training\n", 60 | "model_directory = './3d_gan/models' # directory to save trained model" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "### Read training 3D arrays" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "metadata": { 74 | "collapsed": true 75 | }, 76 | "outputs": [], 77 | "source": [ 78 | "train_dir = './3D_Voxel_Files/'\n", 79 | "train_names = [f for f in os.listdir(train_dir) if f.endswith('_1')]\n", 80 | "\n", 81 | "chairs = []\n", 82 | "for f in train_names:\n", 83 | " chairs.append(np.load(train_dir+f)) # load the binary array files\n", 84 | "train_chairs = np.array(chairs)\n", 85 | "train_chairs=train_chairs.reshape([988,32,32,32,1]) # turn train_chairs into 5D tensor [batch, depth, height, width, channels]" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": { 92 | "collapsed": false 93 | }, 94 | "outputs": [], 95 | "source": [ 96 | "train_chairs.shape" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "### Declare helpful functions" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": { 110 | "collapsed": true 111 | }, 112 | "outputs": [], 113 | "source": [ 114 | "# get a batch of real 3D models\n", 115 | "def get_x(batch_size):\n", 116 | " indices = np.random.randint(len(train_chairs), size=batch_size) # random sample real images\n", 117 | " batch = train_chairs[indices] \n", 118 | " return batch" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "metadata": {}, 124 | "source": [ 125 | "## Define the Generative Adversarial Network" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "#### Generator network" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": { 139 | "collapsed": true 140 | }, 141 | "outputs": [], 142 | "source": [ 143 | "### Larger generator with 512 filters at the first deconvolutional layer\n", 144 | "\n", 145 | "\n", 146 | "# when is_train=False, do not perform batch normalization\n", 147 | "def generator(z, batch_size=batch_size, is_train=True, reuse=False):\n", 148 | " print '\\n Generator:'\n", 149 | " \n", 150 | " if reuse:\n", 151 | " tf.get_variable_scope().reuse_variables()\n", 152 | " tl.layers.set_name_reuse(reuse)\n", 153 | " \n", 154 | " # input of the network \n", 155 | " gen_in = tl.layers.InputLayer(inputs=z, name='g/in')\n", 156 | " # fully connected layer\n", 157 | " # n_units: number of nodes in FC layer\n", 158 | " gen_h0 = tl.layers.DenseLayer(layer=gen_in, n_units = 4*4*4*512,\n", 159 | " W_init = initializer,\n", 160 | " act = tf.identity, name='g/h0/lin')\n", 161 | " #print '!!!gen_h0.outputs before reshape:',gen_h0.outputs\n", 162 | " # reshape the fully connected layer to a 5D tensor [batch size, depth, height, width, channels]\n", 163 | " # output size: batch_size*4*4*4*512\n", 164 | " gen_h0 = tl.layers.ReshapeLayer(gen_h0, shape = [-1,4,4,4,512], name='g/h0/reshape')\n", 165 | " # batch normalize weight parameters\n", 166 | " gen_h0 = tl.layers.BatchNormLayer(gen_h0, is_train=is_train, gamma_init=tf.random_normal_initializer(1., 0.02), name='g/h0/batch_norm')\n", 167 | " # apply activation function\n", 168 | " gen_h0.outputs = tf.nn.relu(gen_h0.outputs, name='g/h0/relu')\n", 169 | " #print '!!!gen_h0.outputs after reshape:',gen_h0.outputs \n", 170 | " \n", 171 | " # shape: [kernel_depth, kernel_height, kernel_width, output_channels, input_channels]\n", 172 | " # output shape: [batch size, output_depth, output_height, output_width, output channels]\n", 173 | " # strides: [stride on batch, depth, height, width, channels]\n", 174 | " # act: activation function\n", 175 | " # output size: batch_size*8*8*8*256\n", 176 | " gen_h1 = tl.layers.DeConv3dLayer(layer=gen_h0,\n", 177 | " shape = [4,4,4,256,512],\n", 178 | " output_shape = [batch_size,8,8,8,256],\n", 179 | " strides=[1,2,2,2,1],\n", 180 | " W_init = initializer,\n", 181 | " act=tf.identity, name='g/h1/decon2d')\n", 182 | " gen_h1 = tl.layers.BatchNormLayer(gen_h1, is_train=is_train, gamma_init=tf.random_normal_initializer(1., 0.02), name='g/h1/batch_norm')\n", 183 | " gen_h1.outputs = tf.nn.relu(gen_h1.outputs, name='g/h1/relu')\n", 184 | " #print '!!!gen_h1.outputs:',gen_h1.outputs\n", 185 | "\n", 186 | " # output size: batch_size*16*16*16*128\n", 187 | " gen_h2 = tl.layers.DeConv3dLayer(layer=gen_h1,\n", 188 | " shape = [4,4,4,128,256],\n", 189 | " output_shape = [batch_size,16,16,16,128],\n", 190 | " strides=[1,2,2,2,1],\n", 191 | " W_init = initializer,\n", 192 | " act=tf.identity, name='g/h2/decon2d')\n", 193 | " gen_h2 = tl.layers.BatchNormLayer(gen_h2, is_train=is_train, gamma_init=tf.random_normal_initializer(1., 0.02), name='g/h2/batch_norm')\n", 194 | " gen_h2.outputs = tf.nn.relu(gen_h2.outputs, name='g/h2/relu')\n", 195 | " #print '!!!gen_h2.outputs:',gen_h2.outputs \n", 196 | " \n", 197 | " # output size: batch_size*32*32*32*1\n", 198 | " gen_h3 = tl.layers.DeConv3dLayer(layer=gen_h2,\n", 199 | " shape = [4,4,4,1,128],\n", 200 | " output_shape = [batch_size,32,32,32,1],\n", 201 | " strides=[1,2,2,2,1],\n", 202 | " W_init = initializer,\n", 203 | " act=tf.identity, name='g/h3/decon2d')\n", 204 | " gen_h3.outputs = tf.nn.sigmoid(gen_h3.outputs)\n", 205 | " #print '!!!gen_h3.outputs:',gen_h3.outputs\n", 206 | " \n", 207 | " return gen_h3 # return the generator network" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": null, 213 | "metadata": { 214 | "collapsed": true 215 | }, 216 | "outputs": [], 217 | "source": [ 218 | "### Smaller generator with 256 filters at the first deconvolutional layer\n", 219 | "\n", 220 | "# when is_train=False, do not perform batch normalization\n", 221 | "def generator1(z, batch_size=batch_size, is_train=True, reuse=False):\n", 222 | " print '\\n Generator:'\n", 223 | " \n", 224 | " if reuse:\n", 225 | " tf.get_variable_scope().reuse_variables()\n", 226 | " tl.layers.set_name_reuse(reuse)\n", 227 | " \n", 228 | " # input of the network \n", 229 | " gen_in = tl.layers.InputLayer(inputs=z, name='g/in')\n", 230 | " # fully connected layer\n", 231 | " # n_units: number of nodes in FC layer\n", 232 | " gen_h0 = tl.layers.DenseLayer(layer=gen_in, n_units = 4*4*4*256,\n", 233 | " W_init = initializer,\n", 234 | " act = tf.identity, name='g/h0/lin')\n", 235 | " #print '!!!gen_h0.outputs before reshape:',gen_h0.outputs\n", 236 | " # reshape the fully connected layer to a 5D tensor [batch size, depth, height, width, channels]\n", 237 | " # output size: batch_size*4*4*4*256\n", 238 | " gen_h0 = tl.layers.ReshapeLayer(gen_h0, shape = [-1,4,4,4,256], name='g/h0/reshape')\n", 239 | " # batch normalize weight parameters\n", 240 | " gen_h0 = tl.layers.BatchNormLayer(gen_h0, is_train=is_train, gamma_init=tf.random_normal_initializer(1., 0.02), name='g/h0/batch_norm')\n", 241 | " # apply activation function\n", 242 | " gen_h0.outputs = tf.nn.relu(gen_h0.outputs, name='g/h0/relu')\n", 243 | " #print '!!!gen_h0.outputs after reshape:',gen_h0.outputs \n", 244 | " \n", 245 | " # shape: [kernel_depth, kernel_height, kernel_width, output_channels, input_channels]\n", 246 | " # output shape: [batch size, output_depth, output_height, output_width, output channels]\n", 247 | " # strides: [stride on batch, depth, height, width, channels]\n", 248 | " # act: activation function\n", 249 | " # output size: batch_size*8*8*8*128\n", 250 | " gen_h1 = tl.layers.DeConv3dLayer(layer=gen_h0,\n", 251 | " shape = [4,4,4,128,256],\n", 252 | " output_shape = [batch_size,8,8,8,128],\n", 253 | " strides=[1,2,2,2,1],\n", 254 | " W_init = initializer,\n", 255 | " act=tf.identity, name='g/h1/decon2d')\n", 256 | " gen_h1 = tl.layers.BatchNormLayer(gen_h1, is_train=is_train, gamma_init=tf.random_normal_initializer(1., 0.02), name='g/h1/batch_norm')\n", 257 | " gen_h1.outputs = tf.nn.relu(gen_h1.outputs, name='g/h1/relu')\n", 258 | " #print '!!!gen_h1.outputs:',gen_h1.outputs\n", 259 | "\n", 260 | " # output size: batch_size*16*16*16*64\n", 261 | " gen_h2 = tl.layers.DeConv3dLayer(layer=gen_h1,\n", 262 | " shape = [4,4,4,64,128],\n", 263 | " output_shape = [batch_size,16,16,16,64],\n", 264 | " strides=[1,2,2,2,1],\n", 265 | " W_init = initializer,\n", 266 | " act=tf.identity, name='g/h2/decon2d')\n", 267 | " gen_h2 = tl.layers.BatchNormLayer(gen_h2, is_train=is_train, gamma_init=tf.random_normal_initializer(1., 0.02), name='g/h2/batch_norm')\n", 268 | " gen_h2.outputs = tf.nn.relu(gen_h2.outputs, name='g/h2/relu')\n", 269 | " #print '!!!gen_h2.outputs:',gen_h2.outputs \n", 270 | " \n", 271 | " # output size: batch_size*32*32*32*1\n", 272 | " gen_h3 = tl.layers.DeConv3dLayer(layer=gen_h2,\n", 273 | " shape = [4,4,4,1,64],\n", 274 | " output_shape = [batch_size,32,32,32,1],\n", 275 | " strides=[1,2,2,2,1],\n", 276 | " W_init = initializer,\n", 277 | " act=tf.identity, name='g/h3/decon2d')\n", 278 | " gen_h3.outputs = tf.nn.sigmoid(gen_h3.outputs)\n", 279 | " #print '!!!gen_h3.outputs:',gen_h3.outputs\n", 280 | " \n", 281 | " return gen_h3 # return the generator network" 282 | ] 283 | }, 284 | { 285 | "cell_type": "markdown", 286 | "metadata": {}, 287 | "source": [ 288 | "#### Discriminator network" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": null, 294 | "metadata": { 295 | "collapsed": true 296 | }, 297 | "outputs": [], 298 | "source": [ 299 | "# when is_train=False, do not perform batch normalization\n", 300 | "def discriminator(inputs, batch_size=batch_size, is_train=True, reuse=False):\n", 301 | " print '\\n Discriminator:'\n", 302 | " \n", 303 | " if reuse:\n", 304 | " tf.get_variable_scope().reuse_variables()\n", 305 | " tl.layers.set_name_reuse(reuse)\n", 306 | " \n", 307 | " # Inputs size: batch_size*32*32*32*1 \n", 308 | " dis_in = tl.layers.InputLayer(inputs, name='d/in')\n", 309 | " #print '!!!dis_in:',\n", 310 | " #dis_in.print_layers() \n", 311 | " \n", 312 | " # Creates 32 4*4*4 filters to convolve on the mini-batch of 32*32*32 chairs, also perform batch norm + leaky ReLU activation\n", 313 | " # Set reuse=True allows discriminator to evaluate both real samples and generated samples \n", 314 | " # shape: [kernel_depth, kernel_height, kernel_width, input_channels, output_channels]\n", 315 | " # strides: [stride on batch, depth, height, width, channels]\n", 316 | " # act: activation function\n", 317 | " # Outputs size: batch_size*16*16*16*32 \n", 318 | " dis_h0 = tl.layers.Conv3dLayer(dis_in, shape=[4,4,4,1,32],\n", 319 | " W_init = initializer,\n", 320 | " strides=[1,2,2,2,1], name='d/h0/conv2d')\n", 321 | " # alpha: degree of leakiness used in leaky ReLU\n", 322 | " dis_h0.outputs = tl.activation.leaky_relu(dis_h0.outputs, alpha=0.2, name='d/h0/lrelu')\n", 323 | " #print '!!!dis_h0.outputs:',dis_h0.outputs \n", 324 | " \n", 325 | " # outputs size: batch_size*8*8*8*64 \n", 326 | " dis_h1 = tl.layers.Conv3dLayer(dis_h0, shape=[4,4,4,32,64],\n", 327 | " W_init = initializer,\n", 328 | " strides=[1,2,2,2,1], name='d/h1/conv2d')\n", 329 | " dis_h1 = tl.layers.BatchNormLayer(dis_h1, is_train=is_train, name='d/h1/batch_norm')\n", 330 | " dis_h1.outputs = tl.activation.leaky_relu(dis_h1.outputs, alpha=0.2, name='d/h1/lrelu')\n", 331 | " #print '!!!dis_h1.outputs:',dis_h1.outputs \n", 332 | " \n", 333 | " # outputs size batch_size*4*4*4*128 \n", 334 | " dis_h2 = tl.layers.Conv3dLayer(dis_h1, shape=[4,4,4,64,128],\n", 335 | " W_init = initializer,\n", 336 | " strides=[1,2,2,2,1], name='d/h2/conv2d')\n", 337 | " dis_h2 = tl.layers.BatchNormLayer(dis_h2, is_train=is_train, name='d/h2/batch_norm')\n", 338 | " dis_h2.outputs = tl.activation.leaky_relu(dis_h2.outputs, alpha=0.2, name='d/h2/lrelu')\n", 339 | " #print '!!!dis_h2.outputs:',dis_h2.outputs \n", 340 | " \n", 341 | " # outputs size batch_size*2*2*2*256 \n", 342 | " dis_h3 = tl.layers.Conv3dLayer(dis_h2, shape=[4,4,4,128,256],\n", 343 | " W_init = initializer,\n", 344 | " strides=[1,2,2,2,1], name='d/h3/conv2d')\n", 345 | " dis_h3 = tl.layers.BatchNormLayer(dis_h3, is_train=is_train, name='d/h3/batch_norm')\n", 346 | " dis_h3.outputs = tl.activation.leaky_relu(dis_h3.outputs, alpha=0.2, name='d/h3/lrelu')\n", 347 | " #print '!!!dis_h3.outputs:',dis_h3.outputs \n", 348 | " \n", 349 | " # !!!!!! I have edited /Library/Python/2.7/site-packages/tensorlayer/layers.py to output dimension 2*2*2*256\n", 350 | " # !!!!!! Remember to change this to according values when the discriminator's structure changed\n", 351 | " #print '!!!',\n", 352 | " #dis_h3.print_layers() # print all information about dis_h3\n", 353 | " \n", 354 | " # flatten the tensor to [batch_size, 2*2*2*256]\n", 355 | " dis_flat = tl.layers.FlattenLayer(dis_h3, name='d/h4/flatten')\n", 356 | " \n", 357 | " # create a fully connect layer with dis_flat and just one node in the output layer\n", 358 | " # note there's no batch normalization at this layer\n", 359 | " # n_units: number of nodes in FC layer\n", 360 | " dis_output = tl.layers.DenseLayer(dis_flat, n_units=1, act=tf.identity,\n", 361 | " W_init=initializer,\n", 362 | " name='d/h4/lin_sigmoid')\n", 363 | " # outputs size: batch_size*1 \n", 364 | " logits = dis_output.outputs\n", 365 | " dis_output.outputs = tf.nn.sigmoid(dis_output.outputs) \n", 366 | " #print '!!!dis_output.outputs:',dis_output.outputs \n", 367 | " #print '!!!logits:',logits \n", 368 | " \n", 369 | " return dis_output, logits" 370 | ] 371 | }, 372 | { 373 | "cell_type": "markdown", 374 | "metadata": {}, 375 | "source": [ 376 | "### Connecting two networks together" 377 | ] 378 | }, 379 | { 380 | "cell_type": "code", 381 | "execution_count": null, 382 | "metadata": { 383 | "collapsed": false, 384 | "scrolled": true 385 | }, 386 | "outputs": [], 387 | "source": [ 388 | "z_size = 100 # size of initial noise vector that will be used for generator\n", 389 | "\n", 390 | "# initialize all parameters of the networks\n", 391 | "# weights were initialized from a zero-centered Normal distribution with standard deviation 0.02\n", 392 | "# tf.truncated_normal returns random values from a normal distribution and made sure no value exceeds 2 std\n", 393 | "initializer = tf.truncated_normal_initializer(stddev=0.02)\n", 394 | "\n", 395 | "# placeholders for inputs into the generator and discriminator, respectively.\n", 396 | "z_vector = tf.placeholder(shape=[batch_size,z_size],dtype=tf.float32, name='z_vectors') \n", 397 | "x_vector = tf.placeholder(shape=[batch_size,32,32,32,1],dtype=tf.float32, name='real_chairs') \n", 398 | "\n", 399 | "\n", 400 | "# ---- DCGAN ----\n", 401 | "net_g_train = generator(z_vector, is_train=True, reuse=False) # generated mini-batch of 3d models from noisy z vectors \n", 402 | "print 'generator: ',net_g_train\n", 403 | "#print 'generator outputs: ',net_g_train.outputs\n", 404 | "\n", 405 | "net_d, d_output_x = discriminator(x_vector, is_train=True, reuse=False) # probabilities for real 3d models !!! should have ,reuse=True when there's pre-training\n", 406 | "print 'discriminator: ',net_d\n", 407 | "d_output_x = tf.maximum(tf.minimum(d_output_x, 0.99), 0.01) # avoid inf and -inf\n", 408 | "summary_d_x_hist = tf.histogram_summary(\"d_prob_x\", d_output_x)\n", 409 | "\n", 410 | "net_d2, d_output_z = discriminator(net_g_train.outputs, is_train=True, reuse=True) # probabilities for generated 3d models\n", 411 | "d_output_z = tf.maximum(tf.minimum(d_output_z, 0.99), 0.01) # avoid inf and -inf\n", 412 | "summary_d_z_hist = tf.histogram_summary(\"d_prob_z\", d_output_z)\n", 413 | "\n", 414 | "d_loss = -tf.reduce_mean(tf.log(d_output_x) + tf.log(1-d_output_z)) # loss for discriminator\n", 415 | "summary_d_loss = tf.scalar_summary(\"d_loss\", d_loss)\n", 416 | "\n", 417 | "g_loss = -tf.reduce_mean(tf.log(d_output_z)) # loss for generator\n", 418 | "summary_g_loss = tf.scalar_summary(\"g_loss\", g_loss)\n", 419 | "\n", 420 | "# this is generator for evaluation, set is_train to False so that BatchNormLayer behave differently\n", 421 | "net_g_test = generator(z_vector, is_train=False, reuse=True)\n", 422 | "\n", 423 | "\n", 424 | "# the following parameter indices may change if the network structure changes\n", 425 | "para_g=list(np.array(tf.trainable_variables())[[0,1,4,5,8,9,12,13]])\n", 426 | "para_d=list(np.array(tf.trainable_variables())[[14,15,16,17,20,21,24,25,28,29]])\n", 427 | "\n", 428 | "# only update parameters in discriminator during pre-training\n", 429 | "#pre_optimizer = tf.train.AdamOptimizer(learning_rate=alpha_d,beta1=beta1).minimize(d_pre_loss,var_list=para_d)\n", 430 | "# only update the weights for the discriminator network\n", 431 | "optimizer_op_d = tf.train.AdamOptimizer(learning_rate=alpha_d,beta1=beta1).minimize(d_loss,var_list=para_d)\n", 432 | "# only update the weights for the generator network\n", 433 | "optimizer_op_g = tf.train.AdamOptimizer(learning_rate=alpha_g,beta1=beta1).minimize(g_loss,var_list=para_g)" 434 | ] 435 | }, 436 | { 437 | "cell_type": "markdown", 438 | "metadata": {}, 439 | "source": [ 440 | "### Train the GAN model" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": null, 446 | "metadata": { 447 | "collapsed": false 448 | }, 449 | "outputs": [], 450 | "source": [ 451 | "# create a log folder and save the graph structure, do this before training\n", 452 | "g_writer = tf.train.SummaryWriter(logs_path + '/generator', graph=tf.get_default_graph())\n", 453 | "d_writer = tf.train.SummaryWriter(logs_path + '/discriminator')\n", 454 | "\n", 455 | "# saver saves and loads variables of the model to and from checkpoints, \n", 456 | "# which are binary files that maps variable names to tensor values\n", 457 | "saver = tf.train.Saver(max_to_keep=50) \n", 458 | "\n", 459 | "with tf.Session() as sess: \n", 460 | " # set GPU memeory fraction\n", 461 | " tl.ops.set_gpu_fraction(sess=sess, gpu_fraction=0.99)\n", 462 | " \n", 463 | " # variables need to be initialized before we can use them\n", 464 | " sess.run(tf.initialize_all_variables())\n", 465 | " #print [v.name for v in tf.trainable_variables()] # print all variable names\n", 466 | " #print 'para_g:',[v.name for v in para_g]\n", 467 | " #print '\\n para_d:',[v.name for v in para_d]\n", 468 | " \n", 469 | " \n", 470 | " # -------- jointly training discriminator and generator --------\n", 471 | " start = time.time()\n", 472 | " \n", 473 | " # z noise vector that will be used to generate chairs to check the training progress\n", 474 | " #z_sample = np.random.uniform(-1.0,1.0,size=[batch_size,z_size]).astype(np.float32) # uniform distribution between [-1, 1]\n", 475 | " z_sample = np.random.normal(0, 0.33, size=[batch_size,z_size]).astype(np.float32) # gaussian distribution between [-1, 1]\n", 476 | " \n", 477 | " for epoch in range(training_epochs):\n", 478 | " # get a batch of real chairs, with range [-1 ,1]\n", 479 | " x = get_x(batch_size) \n", 480 | " # mini-batch of noise data from [-1, 1]\n", 481 | " #z = np.random.uniform(-1.0,1.0,size=[batch_size,z_size]).astype(np.float32)\n", 482 | " z = np.random.normal(0, 0.33, size=[batch_size,z_size]).astype(np.float32)\n", 483 | " \n", 484 | " # Update the discriminator and generator\n", 485 | " d_summary_merge = tf.merge_summary([summary_d_loss, summary_d_x_hist,summary_d_z_hist])\n", 486 | " summary_d,discriminator_loss = sess.run([d_summary_merge,d_loss],feed_dict={z_vector:z, x_vector:x})\n", 487 | " summary_g,genterator_loss = sess.run([summary_g_loss,g_loss],feed_dict={z_vector:z}) \n", 488 | " #print \"epoch: \", epoch\n", 489 | " #print 'd_loss:',discriminator_loss\n", 490 | " #print 'g_loss:',genterator_loss\n", 491 | " \n", 492 | " # only update the discriminator when its loss is larger than 10% !!!!! D may not get sufficiently trained if threshold is too high\n", 493 | " if discriminator_loss <= 4.6*0.1: \n", 494 | " sess.run([optimizer_op_g],feed_dict={z_vector:z})\n", 495 | " #print \"epoch: \",epoch,', d_loss:',discriminator_loss,'g_loss:',genterator_loss\n", 496 | " # only update the generator when its loss is larger than 10% !!!!! G may not get sufficiently trained if threshold is too high\n", 497 | " elif genterator_loss <= 4.6*0.1:\n", 498 | " sess.run([optimizer_op_d],feed_dict={z_vector:z, x_vector:x})\n", 499 | " #print \"epoch: \",epoch,', d_loss:',discriminator_loss,'g_loss:',genterator_loss\n", 500 | " else:\n", 501 | " sess.run([optimizer_op_d],feed_dict={z_vector:z, x_vector:x})\n", 502 | " sess.run([optimizer_op_g],feed_dict={z_vector:z})\n", 503 | " \n", 504 | " # add loss summary to tensorboard\n", 505 | " if epoch % 5 == 0:\n", 506 | " d_writer.add_summary(summary_d, epoch) \n", 507 | " g_writer.add_summary(summary_g, epoch)\n", 508 | " \n", 509 | " # print training progress\n", 510 | " if epoch % 100 == 0:\n", 511 | " time_lapse = time.time()-start\n", 512 | " start = time.time()\n", 513 | " print \"epoch: \", epoch,\", time spent: %.2fs\" % time_lapse\n", 514 | " \n", 515 | " # output generated chairs\n", 516 | " if epoch % 500 == 0:\n", 517 | " g_chairs = sess.run(net_g_test.outputs,feed_dict={z_vector:z_sample}) # get a generated chair, with range [-1, 1]\n", 518 | " # make a directory for generated chairs\n", 519 | " if not os.path.exists(train_sample_directory):\n", 520 | " os.makedirs(train_sample_directory)\n", 521 | " \n", 522 | " #Save sample generated chair arrays\n", 523 | " g_chairs.dump(train_sample_directory+'/'+str(epoch))\n", 524 | " \n", 525 | " # save model check point\n", 526 | " if epoch % 500 == 0:\n", 527 | " # make a directory for trained models\n", 528 | " if not os.path.exists(model_directory):\n", 529 | " os.makedirs(model_directory)\n", 530 | " \n", 531 | " # save the trained model at different epoch\n", 532 | " saver.save(sess, save_path = model_directory + '/' + str(epoch) + '.cptk')\n", 533 | " print \"Done\"" 534 | ] 535 | }, 536 | { 537 | "cell_type": "markdown", 538 | "metadata": { 539 | "collapsed": true 540 | }, 541 | "source": [ 542 | "### Continue training from the last checkpoint" 543 | ] 544 | }, 545 | { 546 | "cell_type": "code", 547 | "execution_count": null, 548 | "metadata": { 549 | "collapsed": false 550 | }, 551 | "outputs": [], 552 | "source": [ 553 | "saver = tf.train.Saver(max_to_keep=50)" 554 | ] 555 | }, 556 | { 557 | "cell_type": "code", 558 | "execution_count": null, 559 | "metadata": { 560 | "collapsed": false 561 | }, 562 | "outputs": [], 563 | "source": [ 564 | "ckpt = tf.train.get_checkpoint_state(model_directory)\n", 565 | "ckpt.all_model_checkpoint_paths" 566 | ] 567 | }, 568 | { 569 | "cell_type": "code", 570 | "execution_count": null, 571 | "metadata": { 572 | "collapsed": false 573 | }, 574 | "outputs": [], 575 | "source": [ 576 | "ckpt.all_model_checkpoint_paths[3]" 577 | ] 578 | }, 579 | { 580 | "cell_type": "code", 581 | "execution_count": null, 582 | "metadata": { 583 | "collapsed": false 584 | }, 585 | "outputs": [], 586 | "source": [ 587 | "print 'Loading models...might take a minute'\n", 588 | "saver = tf.train.Saver(max_to_keep=50)\n", 589 | "\n", 590 | "# create a log folder and save the graph structure, do this before training\n", 591 | "g_writer = tf.train.SummaryWriter(logs_path + '/generator', graph=tf.get_default_graph())\n", 592 | "d_writer = tf.train.SummaryWriter(logs_path + '/discriminator')\n", 593 | "\n", 594 | "with tf.Session() as sess: \n", 595 | " # set GPU memeory fraction\n", 596 | " tl.ops.set_gpu_fraction(sess=sess, gpu_fraction=0.99)\n", 597 | " \n", 598 | " ckpt = tf.train.get_checkpoint_state(model_directory)\n", 599 | " #model = ckpt.all_model_checkpoint_paths[3]\n", 600 | " model = ckpt.model_checkpoint_path\n", 601 | " saver.restore(sess, save_path=model)\n", 602 | " \n", 603 | " # -------- jointly training discriminator and generator --------\n", 604 | " start = time.time()\n", 605 | " \n", 606 | " # z noise vector that will be used to generate chairs to check the training progress\n", 607 | " #z_sample = np.random.uniform(-1.0,1.0,size=[batch_size,z_size]).astype(np.float32) # uniform distribution between [-1, 1]\n", 608 | " z_sample = np.random.normal(0, 0.33, size=[batch_size,z_size]).astype(np.float32) # gaussian distribution between [-1, 1]\n", 609 | " \n", 610 | " for epoch in range(4000, 25001):\n", 611 | " # get a batch of real chairs, with range [-1 ,1]\n", 612 | " x = get_x(batch_size) \n", 613 | " # mini-batch of noise data from [-1, 1]\n", 614 | " #z = np.random.uniform(-1.0,1.0,size=[batch_size,z_size]).astype(np.float32)\n", 615 | " z = np.random.normal(0, 0.33, size=[batch_size,z_size]).astype(np.float32)\n", 616 | " \n", 617 | " # Update the discriminator and generator\n", 618 | " d_summary_merge = tf.merge_summary([summary_d_loss, summary_d_x_hist,summary_d_z_hist])\n", 619 | " summary_d,discriminator_loss = sess.run([d_summary_merge,d_loss],feed_dict={z_vector:z, x_vector:x})\n", 620 | " summary_g,genterator_loss = sess.run([summary_g_loss,g_loss],feed_dict={z_vector:z}) \n", 621 | " #print \"epoch: \", epoch\n", 622 | " #print 'd_loss:',discriminator_loss\n", 623 | " #print 'g_loss:',genterator_loss\n", 624 | " \n", 625 | " # only update the discriminator when its loss is larger than 10% !!!!! D may not get sufficiently trained if threshold is too high\n", 626 | " if discriminator_loss <= 4.6*0.1: \n", 627 | " sess.run([optimizer_op_g],feed_dict={z_vector:z})\n", 628 | " #print \"epoch: \",epoch,', d_loss:',discriminator_loss,'g_loss:',genterator_loss\n", 629 | " # only update the generator when its loss is larger than 10% !!!!! G may not get sufficiently trained if threshold is too high\n", 630 | " elif genterator_loss <= 4.6*0.1:\n", 631 | " sess.run([optimizer_op_d],feed_dict={z_vector:z, x_vector:x})\n", 632 | " #print \"epoch: \",epoch,', d_loss:',discriminator_loss,'g_loss:',genterator_loss\n", 633 | " else:\n", 634 | " sess.run([optimizer_op_d],feed_dict={z_vector:z, x_vector:x})\n", 635 | " sess.run([optimizer_op_g],feed_dict={z_vector:z})\n", 636 | " \n", 637 | " # add loss summary to tensorboard\n", 638 | " if epoch % 10 == 0:\n", 639 | " d_writer.add_summary(summary_d, epoch) \n", 640 | " g_writer.add_summary(summary_g, epoch)\n", 641 | " \n", 642 | " # print training progress\n", 643 | " if epoch % 100 == 0:\n", 644 | " time_lapse = time.time()-start\n", 645 | " start = time.time()\n", 646 | " print \"epoch: \", epoch,\", time spent: %.2fs\" % time_lapse \n", 647 | " \n", 648 | " # output generated chairs\n", 649 | " if epoch % 500 == 0:\n", 650 | " g_chairs = sess.run(net_g_test.outputs,feed_dict={z_vector:z_sample}) # get a generated chair, with range [-1, 1]\n", 651 | " # make a directory for generated chairs\n", 652 | " if not os.path.exists(train_sample_directory):\n", 653 | " os.makedirs(train_sample_directory)\n", 654 | " \n", 655 | " #Save sample generated chair arrays\n", 656 | " g_chairs.dump(train_sample_directory+'/'+str(epoch))\n", 657 | " \n", 658 | " # save model check point\n", 659 | " if epoch % 500 == 0:\n", 660 | " # make a directory for trained models\n", 661 | " if not os.path.exists(model_directory):\n", 662 | " os.makedirs(model_directory)\n", 663 | " \n", 664 | " # save the trained model at different epoch\n", 665 | " saver.save(sess, save_path = model_directory + '/' + str(epoch) + '.cptk')\n", 666 | " print \"Done\"" 667 | ] 668 | }, 669 | { 670 | "cell_type": "code", 671 | "execution_count": null, 672 | "metadata": { 673 | "collapsed": true 674 | }, 675 | "outputs": [], 676 | "source": [] 677 | }, 678 | { 679 | "cell_type": "markdown", 680 | "metadata": { 681 | "collapsed": true 682 | }, 683 | "source": [ 684 | "### Read generated samples and Visualize" 685 | ] 686 | }, 687 | { 688 | "cell_type": "code", 689 | "execution_count": null, 690 | "metadata": { 691 | "collapsed": false 692 | }, 693 | "outputs": [], 694 | "source": [ 695 | "samples=np.load('8000')\n", 696 | "chair = samples[3]\n", 697 | "chair=chair.reshape([32,32,32])" 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "execution_count": null, 703 | "metadata": { 704 | "collapsed": false 705 | }, 706 | "outputs": [], 707 | "source": [ 708 | "chair.shape" 709 | ] 710 | }, 711 | { 712 | "cell_type": "code", 713 | "execution_count": null, 714 | "metadata": { 715 | "collapsed": false 716 | }, 717 | "outputs": [], 718 | "source": [ 719 | "print chair.min(),chair.max()" 720 | ] 721 | }, 722 | { 723 | "cell_type": "code", 724 | "execution_count": null, 725 | "metadata": { 726 | "collapsed": true 727 | }, 728 | "outputs": [], 729 | "source": [ 730 | "chair=chair.round() # round values to 0.0 or 1.0" 731 | ] 732 | }, 733 | { 734 | "cell_type": "markdown", 735 | "metadata": {}, 736 | "source": [ 737 | "#### Turn a voxel 3d array into mesh" 738 | ] 739 | }, 740 | { 741 | "cell_type": "code", 742 | "execution_count": null, 743 | "metadata": { 744 | "collapsed": true 745 | }, 746 | "outputs": [], 747 | "source": [ 748 | "from stl import mesh\n", 749 | "from skimage import measure\n", 750 | "# Use marching cubes to obtain the surface mesh of these ellipsoids\n", 751 | "# level is a float number between the min and max of chair\n", 752 | "# the lower the level is, the more detail of voxels are captured; the higher, the less noise in the volumetric model\n", 753 | "vertices, faces = measure.marching_cubes(chair,level=0.5)\n", 754 | "\n", 755 | "# Create the mesh and save as STL\n", 756 | "chair = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))\n", 757 | "for i, f in enumerate(faces):\n", 758 | " for j in range(3):\n", 759 | " chair.vectors[i][j] = vertices[f[j],:]" 760 | ] 761 | }, 762 | { 763 | "cell_type": "markdown", 764 | "metadata": {}, 765 | "source": [ 766 | "#### Visualize" 767 | ] 768 | }, 769 | { 770 | "cell_type": "code", 771 | "execution_count": null, 772 | "metadata": { 773 | "collapsed": false 774 | }, 775 | "outputs": [], 776 | "source": [ 777 | "# Plot out the meshed object\n", 778 | "from mpl_toolkits import mplot3d\n", 779 | "from matplotlib import pyplot\n", 780 | "\n", 781 | "figure = pyplot.figure()\n", 782 | "axes = mplot3d.Axes3D(figure)\n", 783 | "\n", 784 | "# Load the STL files and add the vectors to the plot\n", 785 | "axes.add_collection3d(mplot3d.art3d.Poly3DCollection(chair.vectors))\n", 786 | "\n", 787 | "# Auto scale to the mesh size\n", 788 | "scale = chair.points.flatten(-1)\n", 789 | "axes.auto_scale_xyz(scale, scale, scale)\n", 790 | "\n", 791 | "# Show the plot to the screen\n", 792 | "pyplot.show()" 793 | ] 794 | }, 795 | { 796 | "cell_type": "code", 797 | "execution_count": null, 798 | "metadata": { 799 | "collapsed": true 800 | }, 801 | "outputs": [], 802 | "source": [ 803 | "# Write the mesh to STL file \n", 804 | "chair.save('chair.stl')" 805 | ] 806 | }, 807 | { 808 | "cell_type": "markdown", 809 | "metadata": {}, 810 | "source": [ 811 | "### Use the trained generator to genrate chair models" 812 | ] 813 | }, 814 | { 815 | "cell_type": "code", 816 | "execution_count": null, 817 | "metadata": { 818 | "collapsed": true 819 | }, 820 | "outputs": [], 821 | "source": [ 822 | "model_directory = './3d_gan/models/' # directory to save trained model\n", 823 | "sample_inter_directory = './3d_gan/interpolation/' # directory to save the generated models from interpolation\n", 824 | "# make a directory for generated images\n", 825 | "if not os.path.exists(sample_inter_directory):\n", 826 | " os.makedirs(sample_inter_directory)" 827 | ] 828 | }, 829 | { 830 | "cell_type": "code", 831 | "execution_count": null, 832 | "metadata": { 833 | "collapsed": false 834 | }, 835 | "outputs": [], 836 | "source": [ 837 | "tf.reset_default_graph()\n", 838 | "# size of initial noise vector that will be used for generator\n", 839 | "z_size = 100 \n", 840 | "# placeholders for inputs into the generator\n", 841 | "# shape[0] is None means size could take any integer value\n", 842 | "z_vector = tf.placeholder(shape=[None,z_size],dtype=tf.float32, name='z_vectors')\n", 843 | "\n", 844 | "# initialize all parameters of the networks\n", 845 | "# weights were initialized from a zero-centered Normal distribution with standard deviation 0.02\n", 846 | "# tf.truncated_normal returns random values from a normal distribution and made sure no value exceeds 2 std\n", 847 | "initializer = tf.truncated_normal_initializer(stddev=0.02)\n", 848 | "\n", 849 | "net_g_test = generator(z_vector, is_train=False, reuse=False)\n", 850 | "\n", 851 | "print 'Loading Face models...might take a minute'\n", 852 | "saver = tf.train.Saver()\n", 853 | "print 'done.'" 854 | ] 855 | }, 856 | { 857 | "cell_type": "markdown", 858 | "metadata": {}, 859 | "source": [ 860 | "### Interpolation" 861 | ] 862 | }, 863 | { 864 | "cell_type": "code", 865 | "execution_count": null, 866 | "metadata": { 867 | "collapsed": true 868 | }, 869 | "outputs": [], 870 | "source": [ 871 | "from stl import mesh\n", 872 | "from skimage import measure\n", 873 | " \n", 874 | "# spherical interpolation between pointA and pointB, each is a ndarray\n", 875 | "# val is a value between [0,1], where 0 returns pointA, 1 returns pointB\n", 876 | "def slerp(val, pointA, pointB):\n", 877 | " omega = np.arccos(np.clip(np.dot(pointA/np.linalg.norm(pointA), pointB/np.linalg.norm(pointB)), -1, 1))\n", 878 | " so = np.sin(omega)\n", 879 | " if so == 0:\n", 880 | " return (1.0-val) * pointA + val * pointB # L'Hopital's rule/LERP\n", 881 | " return np.sin((1.0-val)*omega) / so * pointA + np.sin(val*omega) / so * pointB" 882 | ] 883 | }, 884 | { 885 | "cell_type": "code", 886 | "execution_count": null, 887 | "metadata": { 888 | "collapsed": false 889 | }, 890 | "outputs": [], 891 | "source": [ 892 | "with tf.Session() as sess:\n", 893 | "\n", 894 | " # reload the trained model.\n", 895 | " ckpt = tf.train.get_checkpoint_state(model_directory)\n", 896 | " model = ckpt.model_checkpoint_path # read the model saved at epoch 8000\n", 897 | " print 'load model: ', model\n", 898 | " # restore model variables\n", 899 | " saver.restore(sess, save_path=model)\n", 900 | "\n", 901 | " # z noise vector that will be used to generate image to check the training progress\n", 902 | " z_sample = np.random.normal(0, 0.33, size=[batch_size,z_size]).astype(np.float32) # gaussian distribution between [-1, 1]\n", 903 | " #print z_sample.shape\n", 904 | " # linear interpolation\n", 905 | " #z_sample_one = z_sample[:1]\n", 906 | " #print z_sample_one.shape\n", 907 | " \n", 908 | " g_chairs = sess.run(net_g_test.outputs,feed_dict={z_vector:z_sample}) # get a generated chair, with range [-1, 1]" 909 | ] 910 | }, 911 | { 912 | "cell_type": "code", 913 | "execution_count": null, 914 | "metadata": { 915 | "collapsed": false 916 | }, 917 | "outputs": [], 918 | "source": [ 919 | "g_chairs.shape" 920 | ] 921 | }, 922 | { 923 | "cell_type": "code", 924 | "execution_count": null, 925 | "metadata": { 926 | "collapsed": true 927 | }, 928 | "outputs": [], 929 | "source": [ 930 | "chair = g_chairs[3].reshape([32,32,32])" 931 | ] 932 | }, 933 | { 934 | "cell_type": "code", 935 | "execution_count": null, 936 | "metadata": { 937 | "collapsed": false 938 | }, 939 | "outputs": [], 940 | "source": [ 941 | "# turn voxel into mesh\n", 942 | "# Use marching cubes to obtain the surface mesh of these ellipsoids\n", 943 | "# level is a float number between the min and max of chair\n", 944 | "# the lower the level is, the more detail of voxels are captured; the higher, the less noise in the volumetric model\n", 945 | "vertices, faces = measure.marching_cubes(chair,level=0.5)\n", 946 | "\n", 947 | "# Create the mesh and save as STL\n", 948 | "chair = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))\n", 949 | "for i, f in enumerate(faces):\n", 950 | " for j in range(3):\n", 951 | " chair.vectors[i][j] = vertices[f[j],:]" 952 | ] 953 | }, 954 | { 955 | "cell_type": "code", 956 | "execution_count": null, 957 | "metadata": { 958 | "collapsed": false 959 | }, 960 | "outputs": [], 961 | "source": [ 962 | "# Plot out the meshed object\n", 963 | "from mpl_toolkits import mplot3d\n", 964 | "from matplotlib import pyplot\n", 965 | "\n", 966 | "figure = pyplot.figure()\n", 967 | "axes = mplot3d.Axes3D(figure)\n", 968 | "\n", 969 | "# Load the STL files and add the vectors to the plot\n", 970 | "axes.add_collection3d(mplot3d.art3d.Poly3DCollection(chair.vectors))\n", 971 | "\n", 972 | "# Auto scale to the mesh size\n", 973 | "scale = chair.points.flatten(-1)\n", 974 | "axes.auto_scale_xyz(scale, scale, scale)\n", 975 | "\n", 976 | "# Show the plot to the screen\n", 977 | "pyplot.show()" 978 | ] 979 | }, 980 | { 981 | "cell_type": "code", 982 | "execution_count": null, 983 | "metadata": { 984 | "collapsed": true 985 | }, 986 | "outputs": [], 987 | "source": [] 988 | } 989 | ], 990 | "metadata": { 991 | "kernelspec": { 992 | "display_name": "Python 2", 993 | "language": "python", 994 | "name": "python2" 995 | }, 996 | "language_info": { 997 | "codemirror_mode": { 998 | "name": "ipython", 999 | "version": 2 1000 | }, 1001 | "file_extension": ".py", 1002 | "mimetype": "text/x-python", 1003 | "name": "python", 1004 | "nbconvert_exporter": "python", 1005 | "pygments_lexer": "ipython2", 1006 | "version": "2.7.5" 1007 | } 1008 | }, 1009 | "nbformat": 4, 1010 | "nbformat_minor": 0 1011 | } 1012 | -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000000_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000000_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000001_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000001_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000002_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000002_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000005_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000005_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000010_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000010_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000013_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000013_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000014_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000014_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000015_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000015_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000016_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000016_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000021_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000021_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000023_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000023_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000024_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000024_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000029_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000029_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000030_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000030_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000031_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000031_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000032_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000032_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000033_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000033_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000035_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000035_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000036_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000036_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000037_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000037_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000038_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000038_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000039_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000039_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000040_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000040_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000041_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000041_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000042_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000042_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000045_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000045_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000047_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000047_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000049_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000049_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000052_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000052_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000053_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000053_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000054_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000054_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000055_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000055_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000056_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000056_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000057_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000057_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000059_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000059_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000061_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000061_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000066_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000066_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000068_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000068_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000069_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000069_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000072_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000072_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000074_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000074_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000075_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000075_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000078_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000078_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000079_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000079_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000082_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000082_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000086_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000086_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000087_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000087_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000089_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000089_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000093_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000093_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000094_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000094_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000096_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000096_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000097_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000097_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000099_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000099_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000100_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000100_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000101_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000101_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000103_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000103_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000108_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000108_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000111_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000111_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000115_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000115_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000118_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000118_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000121_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000121_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000122_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000122_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000123_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000123_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000124_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000124_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000125_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000125_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000126_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000126_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000127_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000127_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000128_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000128_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000129_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000129_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000130_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000130_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000131_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000131_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000132_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000132_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000134_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000134_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000136_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000136_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000137_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000137_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000139_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000139_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000140_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000140_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000141_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000141_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000143_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000143_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000144_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000144_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000148_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000148_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000150_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000150_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000153_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000153_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000154_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000154_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000156_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000156_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000159_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000159_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000160_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000160_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000161_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000161_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000162_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000162_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000163_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000163_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000165_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000165_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000166_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000166_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000167_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000167_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000173_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000173_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000174_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000174_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000176_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000176_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000177_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000177_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000179_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000179_1 -------------------------------------------------------------------------------- /3D_Voxel_Files/chair_000000180_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timzhang642/3d_gan_tensorflow/4426cdce0bb40e24f62e06e90a151c2f52b60ed2/3D_Voxel_Files/chair_000000180_1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Generating 3D Voxel Models with Generative Adversarial Networks - Implemented in Tensorflow 2 | 3 | A generated chair sample: 4 |