Skip to content

Commit e1e7e3d

Browse files
author
Phuc Le
committed
Fix evaluation distance code.
1 parent 8054d1a commit e1e7e3d

File tree

6 files changed

+35
-30
lines changed

6 files changed

+35
-30
lines changed

data.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,20 @@ def collate_fn(self, batch):
6363
batch: (list) [chunkSize, ]
6464
each element of list batch has shape
6565
[viewN, height, width, channels]
66-
Return: {}
67-
inputImage: [batchSize, height, width, channels]
66+
Return: Tensor
67+
inputImage: [batchSize, channels, height, width]
6868
targetTrans: [batchSize, novelN, 4]
69-
depthGT: [batchSize, novelN, height, width, 1]
70-
maskGT: [batchSize, novelN, height, width, 1]
69+
depthGT: [batchSize, novelN, 1, height, width]
70+
maskGT: [batchSize, novelN, 1, height, width]
7171
"""
7272
# Shape: [chunkSize, viewN, height, width, channels]
7373
batch_n = {key: np.array([d[key] for d in batch]) for key in batch[0]}
7474
# Shape: [batchSize,]
7575
modelIdx = np.random.permutation(self.cfg.chunkSize)[:self.cfg.batchSize]
7676
# Shape: [batchSize, novelN]
7777
modelIdxTile = np.tile(modelIdx, [self.cfg.novelN, 1]).T
78-
# 24 is the number of rendered images for a single CAD models
7978
# Shape: [batchSize,]
80-
angleIdx = np.random.randint(24, size=[self.cfg.batchSize])
79+
angleIdx = np.random.randint(self.cfg.inputViewN, size=[self.cfg.batchSize])
8180
# Shape: [batchSize, novelN]
8281
sampleIdx = np.random.randint(
8382
self.cfg.sampleN, size=[self.cfg.batchSize, self.cfg.novelN])

scripts/evaluate.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# --chunkSize 32 --batchSize 32 \
44
# --gpu 0
55

6-
python evaluate.py --model ORIG_STG2 --experiment sgd_trueWD_restart \
7-
--loadPath ORIG_STG2_sgd_trueWD_restart \
6+
python evaluate.py --model ORIG_STG2 --experiment sgd_trueWD_restart_cont \
7+
--loadPath ORIG_STG2_sgd_trueWD_restart_cont \
88
--chunkSize 32 --batchSize 32 \
99
--gpu 0

scripts/evaluate_dist.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# --loadPath ORIG_STG2_adam_trueWD_cyclical \
33
# --chunkSize 32 --batchSize 32
44

5-
# python evaluate_dist.py --model ORIG_STG2 --experiment sgd_trueWD_restart \
6-
# --loadPath ORIG_STG2_sgd_trueWD_restart \
7-
# --chunkSize 32 --batchSize 32 \
8-
# --gpu 0
9-
10-
python evaluate_dist.py --model ORIG_STG2 --experiment orig_tf \
11-
--loadPath "~/3D-point-cloud-generation/results_0/orig-ft_it100000" \
5+
python evaluate_dist.py --model ORIG_STG2 --experiment sgd_trueWD_restart_cont \
6+
--loadPath ORIG_STG2_sgd_trueWD_restart_cont \
127
--chunkSize 32 --batchSize 32 \
13-
--gpu 1
8+
--gpu 0
9+
10+
# python evaluate_dist.py --model ORIG_STG2 --experiment orig_tf \
11+
# --loadPath "~/3D-point-cloud-generation/results_0/orig-ft_it100000" \
12+
# --chunkSize 32 --batchSize 32 \
13+
# --gpu 1

scripts/train_stg2.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
# --gpu 1
3636

3737
# Continue training
38-
python train_stg2.py --model ORIG_STG2 --experiment sgd_trueWD_restart_cont \
39-
--loadPath ORIG_STG2_sgd_trueWD_restart_cont \
40-
--chunkSize 32 --batchSize 32 --saveEpoch 10 \
38+
python train_stg2.py --model ORIG_STG2 --experiment sgd_trueWD_restart_cont1 \
39+
--loadPath ORIG_STG1_sgd_trueWD_restart \
40+
--chunkSize 100 --batchSize 32 --saveEpoch 10 \
4141
--optim sgd --trueWD 1e-4 --lr 1e-1 \
4242
--lrSched restart --T_0 5 --T_mult 2 --lrBase 5e-3 \
4343
--gpu 1

trainer.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -487,17 +487,18 @@ def eval(self, model):
487487
XYZid, ML = transform.fuse3D(
488488
self.cfg, XYZ, maskLogit, fuseTrans) # [B,3,VHW],[B,1,VHW]
489489

490+
XYZid, ML = XYZid.permute([0, 2, 1]), ML.squeeze()
490491
for a in range(self.cfg.inputViewN):
491-
xyz = XYZid[a].transpose(0,1) #[VHW, 3]
492-
ml = ML[a].reshape([-1]) #[VHW]
492+
xyz = XYZid[a] #[VHW, 3]
493+
ml = ML[a] #[VHW]
493494
points24[a, 0] = (xyz[ml > 0]).detach().cpu().numpy()
494495

495-
pointMeanN = np.array([len(p) for p in points24]).mean()
496+
pointMeanN = np.array([len(p) for p in points24[:, 0]]).mean()
496497
scipy.io.savemat(
497498
f"{self.result_path}/{self.CADs[i]}.mat",
498499
{"image": cad["image_in"], "pointcloud": points24})
499500

500-
print(f"Save pointcloud to {self.result_path}/{self.CADs[i]}.mat")
501+
print(f"{pointMeanN:.2f} points save to {self.result_path}/{self.CADs[i]}.mat")
501502
self.history.append(
502503
{"cad": self.CADs[i], "average points": pointMeanN})
503504

transform.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,23 @@ def render2D(cfg, XYZid, ML, renderTrans): # [B,1,VHW]
116116
_, MLnewInvis = torch.unbind(invisFloat, dim=1) # [U-U']
117117

118118
# map to upsampled inverse depth and mask (visible)
119-
scatterIdx = torch.stack(
120-
[batchIdxVis, novelIdxVis, YnewVis, XnewVis], dim=1) # [U,4]
119+
# scatterIdx = torch.stack(
120+
# [batchIdxVis, novelIdxVis, YnewVis, XnewVis], dim=1) # [U,4]
121121
upNewiZMLCnt = torch.zeros([cfg.batchSize, cfg.novelN, 3,
122122
cfg.H*cfg.upscale, cfg.W*cfg.upscale]
123123
).to(cfg.device) #[B,N,3,uH,uW]
124124
countOnes = torch.ones_like(iZnewVis)
125125
scatteriZMLCnt = torch.stack([iZnewVis, MLnewVis, countOnes], dim=1) #[U,3]
126-
upNewiZMLCnt[scatterIdx[:,0],
127-
scatterIdx[:,1],
126+
# upNewiZMLCnt[scatterIdx[:,0],
127+
# scatterIdx[:,1],
128+
# :,
129+
# scatterIdx[:,2],
130+
# scatterIdx[:,3]] = scatteriZMLCnt
131+
upNewiZMLCnt[batchIdxVis,
132+
novelIdxVis,
128133
:,
129-
scatterIdx[:,2],
130-
scatterIdx[:,3]] = scatteriZMLCnt
134+
YnewVis,
135+
XnewVis] = scatteriZMLCnt
131136
upNewiZMLCnt = upNewiZMLCnt.reshape([cfg.batchSize * cfg.novelN,
132137
3,
133138
cfg.H * cfg.upscale,
@@ -145,7 +150,7 @@ def render2D(cfg, XYZid, ML, renderTrans): # [B,1,VHW]
145150
upNewML = torch.zeros([cfg.batchSize, cfg.novelN, 1,
146151
cfg.H*cfg.upscale, cfg.W*cfg.upscale]
147152
).to(cfg.device) # [B,N,1,uH,uW]
148-
scatterML = torch.stack([MLnewInvis], dim=1) # [U,1]
153+
scatterML = MLnewInvis.unsqueeze(-1) # [U,1]
149154
upNewML[scatterIdx[:,0],
150155
scatterIdx[:,1],
151156
:,

0 commit comments

Comments
 (0)