Skip to content

Commit b0da0e6

Browse files
committed
update scripts
1 parent 2824896 commit b0da0e6

21 files changed

+59
-74
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ conda create --name von --file pkg_specs.txt
5959
source activate von
6060
```
6161

62-
- Compile the rendering kernel by the following:
62+
- Compile our rendering kernel by running the following:
6363
```bash
6464
./install.sh
6565
```
6666

6767

68-
- (Optional) Install [blender](https://www.blender.org/) for visualizing generated 3D shapes. After installation, please add blender to your PATH environment variable.
68+
- (Optional) Install [blender](https://www.blender.org/) for visualizing generated 3D shapes. After installation, please add blender to the PATH environment variable.
6969

7070
### Generate 3D shapes, 2.5D sketches, and images
7171
- Download our pretrained models:

clean.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# remove the old built files
12
cd render_module
23
echo "clean calc_prob directory"
34
bash ./calc_prob/clean.sh

data/base_dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __len__(self):
2525

2626
def get_transform(opt, has_mask=False, no_flip=None, no_normalize=False):
2727
transform_list = []
28-
if opt.color_jitter and not has_mask:
28+
if hasattr(opt, 'color_jitter') and opt.color_jitter and not has_mask:
2929
transform_list.append(transforms.ColorJitter(hue=0.1))
3030
if opt.resize_or_crop == 'resize_and_crop':
3131
osize = [opt.load_size, opt.load_size]

data/images_dataset.py

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def initialize(self, opt):
4949
@staticmethod
5050
def modify_commandline_options(parser, is_train=True):
5151
parser.add_argument('--random_shift', action='store_true', help='add random shift to real images and rendered ones')
52+
parser.add_argument('--color_jitter', action='store_true', help='jitter the hue of loaded images')
5253
# type of pose pool to sample from:
5354
parser.add_argument('--pose_type', type=str, default='hack', choices=['hack'], help='select which pool of poses to sample from')
5455
parser.add_argument('--pose_align', action='store_true', help='choose to shuffle pose or not. not shuffling == paired pose')

models/base_model.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,16 @@ def get_current_losses(self):
216216
if hasattr(var, 'requires_grad'):
217217
if var.requires_grad:
218218
var = var.item()
219-
losses_ret[name] = var # getattr(self, 'loss_' + name)
219+
losses_ret[name] = var
220220
return losses_ret
221221

222222
def check_nan_inf(self):
223223
losses = self.get_current_losses()
224224
for k, v in losses.items():
225225
if np.isnan(v):
226226
print('%s is nan!' % k)
227-
import pdb
228-
pdb.set_trace()
229227
elif np.isinf(v):
230228
print('s is inf!' % k)
231-
import pdb
232-
pdb.set_trace()
233229
else:
234230
continue
235231

@@ -276,7 +272,6 @@ def get_depth(self, voxel, rot_mat, use_df=False, flipped=False):
276272
max_depth = depth.data.max()
277273
# normalize the depth to [-1, 1]
278274
depth2 = 1 - (depth - min_depth) / (max_depth - min_depth) * 2
279-
# sil2 = silhouette * 2 - 1
280275
return silhouette, depth2
281276

282277
def move_to_cuda(self, gpu_idx=0):
@@ -340,7 +335,6 @@ def safe_render(self, netG, batch_size, nz, flipped=None):
340335
success = False
341336
MAX_RETRY = 10
342337
cnt = 0
343-
# print('safe render')
344338
while not success and cnt < MAX_RETRY:
345339
try:
346340
z_shape = self.get_z_random(batch_size, nz).view(batch_size, nz, 1, 1, 1).to(self.device)

models/basics.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import functools
55
from torch.optim import lr_scheduler
66

7+
78
###############################################################################
89
# Functions
910
###############################################################################
10-
11-
1211
def init_weights(net, init_type='normal', init_param=0.02):
1312
def init_func(m):
1413
classname = m.__class__.__name__

models/networks.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import math
44
from .basics import get_norm_layer, get_non_linearity, init_net
55

6+
67
###############################################################################
78
# Functions
89
###############################################################################
9-
10-
1110
def _cal_kl(mu, logvar, lambda_kl):
1211
if lambda_kl > 0.0:
1312
logvar = torch.clamp(logvar, max=10.0) # to prevent nan
@@ -742,7 +741,6 @@ def __init__(self, n_downsample, input_dim, dim, style_dim, norm, activ, vae=Fal
742741

743742
self.model = nn.Sequential(*self.model)
744743
self.output_dim = dim
745-
# import pdb; pdb.set_trace()
746744

747745
def forward(self, x):
748746
if self.vae:

models/networks_3d.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ def deconvBlock(input_nc, output_nc, bias, norm_layer=None, nl='relu'):
3636
return nn.Sequential(*layers)
3737

3838

39-
def toRGB(input_nc, rgb_nc, bias, zero_mean=False, sig=True):
40-
layers = [nn.ConvTranspose3d(input_nc, rgb_nc, 4, 2, 1, bias=bias)]
39+
# the last layer of a generator
40+
def toRGB(input_nc, output_nc, bias, zero_mean=False, sig=True):
41+
layers = [nn.ConvTranspose3d(input_nc, output_nc, 4, 2, 1, bias=bias)]
4142
if sig:
4243
layers += [nn.Sigmoid()]
4344
return nn.Sequential(*layers)
@@ -114,6 +115,7 @@ def forward(self, input):
114115
return output.view(-1, 1).squeeze(1)
115116

116117

118+
# the first layer of a discriminator
117119
def fromRGB(input_nc, output_nc, bias):
118120
layers = []
119121
layers += [nn.Conv3d(input_nc, output_nc, 4, 2, 1, bias=bias)]

models/test_model.py

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def set_posepool(self, posepool):
6565
if not self.random_view:
6666
self.elevation = (posepool[:, 0] // 3) * 3
6767
self.azimuth = (posepool[:, 1] // 5) * 5
68-
# import pdb; pdb.set_trace()
6968
views = np.zeros((self.n_views, 2))
7069
hist, bins = np.histogram(self.azimuth, bins=range(-90, 91, 5))
7170
sort_ids = hist.argsort()[::-1][: self.n_views]

options/base_options.py

+22-26
Original file line numberDiff line numberDiff line change
@@ -21,59 +21,55 @@ def initialize(self, parser):
2121
parser.add_argument('--output_nc', type=int, default=3, help='# of output image channels')
2222
parser.add_argument('--nz_texture', type=int, default=8, help='#latent vector')
2323
parser.add_argument('--nz_shape', type=int, default=200, help='#latent vector')
24-
25-
parser.add_argument('--nef', type=int, default=64, help='# of encoder filters in first conv layer')
26-
parser.add_argument('--ngf', type=int, default=64, help='# of gen filters in first conv layer')
27-
parser.add_argument('--ndf', type=int, default=64, help='# of discrim filters in first conv layer')
28-
parser.add_argument('--ngf_3d', type=int, default=64, help='# of gen filters in first conv layer')
29-
parser.add_argument('--ndf_3d', type=int, default=64, help='# of discrim filters in first conv layer')
30-
3124
parser.add_argument('--gpu_ids', type=str, default='0', help='gpu ids: e.g. 0 0,1,2, 0,2, -1 for CPU mode')
3225
parser.add_argument('--name', type=str, default='experiment_name', help='name of the experiment. It decides where to store samples and models')
33-
parser.add_argument('--resize_or_crop', type=str, default='crop_real_im', help='crop_real_im | resize_and_crop | crop | scale_width | scale_width_and_crop')
34-
35-
parser.add_argument('--dataset_mode', type=str, default='base', help='base')
3626
parser.add_argument('--model', type=str, default='stage', help='chooses which model to use. bicycle,, ...')
27+
parser.add_argument('--epoch', type=str, default='latest', help='which epoch to load? set to latest to use latest cached model')
28+
parser.add_argument('--phase', type=str, default='val', help='train, val, test, etc')
3729
parser.add_argument('--num_threads', default=6, type=int, help='# sthreads for loading data')
3830
parser.add_argument('--checkpoints_dir', type=str, default='../../results_texture/', help='models are saved here')
39-
40-
parser.add_argument('--serial_batches', action='store_true', help='if true, takes images in order to make batches, otherwise takes them randomly')
31+
# display
4132
parser.add_argument('--display_winsize', type=int, default=128, help='display window size')
42-
parser.add_argument('--use_dropout', action='store_true', help='use dropout for the generator')
33+
# dataset
34+
parser.add_argument('--dataset_mode', type=str, default='base', help='base')
35+
parser.add_argument('--resize_or_crop', type=str, default='crop_real_im', help='crop_real_im | resize_and_crop | crop | scale_width | scale_width_and_crop')
36+
parser.add_argument('--serial_batches', action='store_true', help='if true, takes images in order to make batches, otherwise takes them randomly')
4337
parser.add_argument('--max_dataset_size', type=int, default=float("inf"), help='Maximum number of samples allowed per dataset. If the dataset directory contains more than max_dataset_size, only a subset is loaded.')
44-
4538
# models
4639
parser.add_argument('--num_Ds', type=int, default=2, help='the number of discrminators')
47-
parser.add_argument('--gan_mode', type=str, default='lsgan', help='dcgan | lsgan | wgangp | hinge') # for 2D texture network; not for 3D; use gan_mode_3D for 3D shape
4840
parser.add_argument('--netD', type=str, default='multi', help='selects model to use for netD')
4941
parser.add_argument('--netG', type=str, default='resnet_cat', help='selects model to use for netG')
42+
parser.add_argument('--use_dropout', action='store_true', help='use dropout for the generator')
5043
parser.add_argument('--netE', type=str, default='adaIN', help='selects model to use for netE')
44+
parser.add_argument('--where_add', type=str, default='all', help='where to add z in the network G: input | all | middle')
5145
parser.add_argument('--netG_3D', type=str, default='G0', help='selects model to use for netG_3D')
5246
parser.add_argument('--netD_3D', type=str, default='D0', help='selects model to use for netD_3D')
5347
parser.add_argument('--norm', type=str, default='inst', help='instance normalization or batch normalization')
5448
parser.add_argument('--nl', type=str, default='relu', help='non-linearity activation: relu | lrelu | elu')
5549
parser.add_argument('--G_norm_3D', type=str, default='batch3d', help='normalization layer for G: inst3d | batch3d | none')
5650
parser.add_argument('--D_norm_3D', type=str, default='none', help='normalization layer for D: inst3d | batch3d | none')
57-
51+
# number of channels in our networks
52+
parser.add_argument('--nef', type=int, default=64, help='# of encoder filters in first conv layer')
53+
parser.add_argument('--ngf', type=int, default=64, help='# of gen filters in first conv layer')
54+
parser.add_argument('--ndf', type=int, default=64, help='# of discrim filters in first conv layer')
55+
parser.add_argument('--ngf_3d', type=int, default=64, help='# of gen filters in first conv layer')
56+
parser.add_argument('--ndf_3d', type=int, default=64, help='# of discrim filters in first conv layer')
5857
# extra parameters
59-
parser.add_argument('--where_add', type=str, default='all', help='input|all|middle; where to add z in the network G')
58+
parser.add_argument('--gan_mode', type=str, default='lsgan', help='dcgan | lsgan | wgangp | hinge') # for 2D texture network; not for 3D; use gan_mode_3D for 3D shape
6059
parser.add_argument('--init_type', type=str, default='kaiming', help='network initialization [normal|xavier|kaiming|orth]')
6160
parser.add_argument('--init_param', type=float, default=0.02, help='gain')
62-
parser.add_argument('--no_largest', action='store_true', help='skip findind largest connected component during rendering')
63-
parser.add_argument('--color_jitter', action='store_true', help='jitter the hue of loaded images')
64-
65-
# 3dgan paramters:
61+
# 3D paramters:
6662
parser.add_argument('--voxel_res', type=int, default=128, help='voxel res')
6763
parser.add_argument('--class_3d', type=str, default='car', choices=['car', 'chair', 'mug', 'lamp'], help='3d model class')
68-
parser.add_argument('--suffix', default='', type=str, help='suffix')
69-
parser.add_argument('--verbose', action='store_true', help='if specified, print more debugging information')
7064
parser.add_argument('--model3D_dir', type=str, default=None, help='directory to store pretrained 3D model')
7165
parser.add_argument('--model2D_dir', type=str, default=None, help='directory to store pretrained 2D model')
72-
parser.add_argument('--print_grad', action='store_true', help='if print grad for 2D and 3D gan loss')
73-
parser.add_argument('--epoch', type=str, default='latest', help='which epoch to load? set to latest to use latest cached model')
74-
parser.add_argument('--phase', type=str, default='val', help='train, val, test, etc')
7566
parser.add_argument('--use_df', action='store_true', help='use distance function (DF) representation')
7667
parser.add_argument('--df_th', type=float, default=0.90, help='threshold for rendering df')
68+
# misc
69+
parser.add_argument('--no_largest', action='store_true', help='skip findind largest connected component during rendering')
70+
parser.add_argument('--suffix', default='', type=str, help='suffix')
71+
parser.add_argument('--verbose', action='store_true', help='if specified, print more debugging information')
72+
parser.add_argument('--print_grad', action='store_true', help='if print grad for 2D and 3D gan loss')
7773
parser.add_argument('--seed', type=int, default=0, help='seed')
7874

7975
# special tasks

options/test_options.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ def initialize(self, parser):
77
parser.add_argument('--results_dir', type=str, default='../results/', help='saves results here.')
88
parser.add_argument('--n_shapes', type=int, default=10, help='#shapes')
99
parser.add_argument('--n_views', type=int, default=10, help='#views')
10-
parser.add_argument('--aspect_ratio', type=float, default=1.0, help='aspect ratio for the results')
11-
parser.add_argument('--th', default=0.01, type=float, help='thresholding for isosurface')
12-
# new parameters
1310
parser.add_argument('--reset_shape', action='store_true', help='sample a different shape')
1411
parser.add_argument('--reset_texture', action='store_true', help='sample a different texture')
1512
parser.add_argument('--real_shape', action='store_true', help='use real voxels')
@@ -21,6 +18,8 @@ def initialize(self, parser):
2118
parser.add_argument('--show_rec', action='store_true', help='show reconstruction image')
2219
parser.add_argument('--interp_shape', action='store_true', help='interpolate in shape space')
2320
parser.add_argument('--interp_texture', action='store_true', help='interpolate in texture space')
21+
parser.add_argument('--aspect_ratio', type=float, default=1.0, help='aspect ratio for the results')
22+
parser.add_argument('--ios_th', default=0.01, type=float, help='thresholding for isosurface')
2423

2524
self.isTrain = False
2625
return parser

options/train_options.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
class TrainOptions(BaseOptions):
55
def initialize(self, parser):
66
BaseOptions.initialize(self, parser)
7+
# display and print
78
parser.add_argument('--display_freq', type=int, default=400, help='frequency of showing training results on screen')
89
parser.add_argument('--display_id', type=int, default=1, help='window id of the web display')
910
parser.add_argument('--display_port', type=int, default=2005, help='visdom display port')
10-
1111
parser.add_argument('--update_html_freq', type=int, default=4000, help='frequency of saving training results to html')
1212
parser.add_argument('--print_freq', type=int, default=400, help='frequency of showing training results on console')
13+
parser.add_argument('--no_html', action='store_true', help='do not save intermediate training results to [opt.checkpoints_dir]/[opt.name]/web/')
14+
# saving and training models
1315
parser.add_argument('--save_latest_freq', type=int, default=10000, help='frequency of saving the latest results')
1416
parser.add_argument('--save_epoch_freq', type=int, default=10, help='frequency of saving checkpoints at the end of epochs')
1517
parser.add_argument('--continue_train', action='store_true', help='continue training: load the latest model')
1618
parser.add_argument('--niter', type=int, default=100, help='# of iter at starting learning rate')
1719
parser.add_argument('--niter_decay', type=int, default=100, help='# of iter to linearly decay learning rate to zero')
1820
parser.add_argument('--epoch_count', type=int, default=1, help='the starting epoch count, we save the model by <epoch_count>, <epoch_count>+<save_latest_freq>, ...')
19-
parser.add_argument('--beta1', type=float, default=0.5, help='momentum term of adam')
20-
parser.add_argument('--no_html', action='store_true', help='do not save intermediate training results to [opt.checkpoints_dir]/[opt.name]/web/')
2121
# learning rate
22+
parser.add_argument('--beta1', type=float, default=0.5, help='momentum term of adam')
2223
parser.add_argument('--lr', type=float, default=0.0002, help='initial learning rate for adam')
2324
parser.add_argument('--lr_policy', type=str, default='lambda', help='learning rate policy: lambda|step|plateau')
2425
parser.add_argument('--pool_size', type=int, default=50, help='the size of image buffer that stores previously generated images')

render_module/calc_prob/calc_prob/functions/calc_prob.py

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ def backward(ctx, grad_in):
2828
calc_prob_lib.calc_prob_backward(prob_in, stop_prob_weighted, grad_out)
2929
if torch.isnan(grad_out).any():
3030
print('nan gradient found')
31-
import pdb
32-
pdb.set_trace()
3331
elif torch.isinf(grad_out).any():
3432
print('inf gradient found')
35-
import pdb
36-
pdb.set_trace()
3733
return grad_out

scripts/figures.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# misc
22
set -ex
33
GPU_IDS=${1} # 0
4-
CLASS=${2} # car, chair
5-
DATASET=${3} # df, voxel
4+
CLASS=${2} # car | chair
5+
DATASET=${3} # df | voxel
66
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
77
ROOT_DIR=${SCRIPTPATH}/..
88
# models

scripts/test_shape.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ set -ex
22
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
33
PROJ_ROOT="$SCRIPTPATH/../"
44
GPU_IDS=${1}
5-
DATASET_MODE=${2} # voxel or df
6-
MODEL_NAME=${3} # model name
5+
DATASET_MODE=${2} # df | voxel
6+
MODEL_NAME=${3} # model's full name, not only the class name
77

88

99

scripts/test_texture.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# misc
22
set -ex
33
GPU_IDS=${1}
4-
CLASS=${2}
5-
DATASET=${3}
4+
CLASS=${2} # car | chair
5+
DATASET=${3} # df | voxel
66

77
# models
88
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

scripts/train_full.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
set -ex
22

33
GPU_IDS=${1}
4-
CLASS=${2}
5-
DATASET=${3}
4+
CLASS=${2} # car | chair
5+
DATASET=${3} # df | voxel
66
DISPLAY_ID=${4}
77
DATE=`date +%Y-%m-%d`
88

@@ -22,7 +22,6 @@ python train.py --gpu_ids ${GPU_IDS} \
2222
--checkpoints_dir ${CHECKPOINTS_DIR} \
2323
--model2D_dir ${MODEL2D_DIR} \
2424
--model3D_dir ${MODEL3D_DIR} \
25-
--random_shift \
26-
--color_jitter \
25+
--random_shift --color_jitter \
2726
--lambda_GAN_3D 0.05 \
2827
--suffix {model}_{class_3d}_${DATASET}

scripts/train_shape.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
set -ex
22

33
GPU_IDS=${1}
4-
CLASS=${2} # car or chair
5-
DATASET=${3} # df or voxel
4+
CLASS=${2} # car | chair
5+
DATASET=${3} # df | voxel
66
DATE=`date +%Y-%m-%d`
77
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
88
ROOT_DIR=${SCRIPTPATH}/..

scripts/train_stage2.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
set -ex
22

33
GPU_IDS=${1}
4-
CLASS=${2}
5-
DATASET=${3}
4+
CLASS=${2} # car | chair
5+
DATASET=${3} # voxel | df
66
DISPLAY_ID=${4}
77
DATE=`date +%Y-%m-%d`
88
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

scripts/train_stage2_real.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
set -ex
22

33
GPU_IDS=${1}
4-
CLASS=${2}
5-
DATASET=${3}
4+
CLASS=${2} # car | chair
5+
DATASET=${3} # df | voxel
66
DISPLAY_ID=${4}
77
DATE=`date +%Y-%m-%d`
88

0 commit comments

Comments
 (0)