Skip to content

Commit 4e96193

Browse files
committed
update 2rd training
1 parent 67b0d63 commit 4e96193

34 files changed

+2547
-28
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Jie Tang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

augs.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
# @Filename: augs.py
4+
# @Project: BP-Net
5+
# @Author: jie
6+
# @Time: 2021/3/14 8:27 PM
7+
8+
9+
import numpy as np
10+
11+
__all__ = [
12+
'Compose',
13+
'Norm',
14+
'Jitter',
15+
'Flip',
16+
]
17+
18+
19+
class Compose(object):
20+
"""
21+
Sequential operations on input images, (i.e. rgb, lidar and depth).
22+
"""
23+
24+
def __init__(self, transforms):
25+
self.transforms = transforms
26+
27+
def __call__(self, rgb, disp, lidar, depth, K_cam):
28+
for t in self.transforms:
29+
rgb, disp, lidar, depth, K_cam = t(rgb, disp, lidar, depth, K_cam)
30+
return rgb, disp, lidar, depth, K_cam
31+
32+
33+
class Norm(object):
34+
"""
35+
normalize rgb image.
36+
"""
37+
38+
def __init__(self, mean, std):
39+
self.mean = np.array(mean)
40+
self.std = np.array(std)
41+
42+
def __call__(self, rgb, disp, lidar, depth, K_cam):
43+
rgb = (rgb - self.mean) / self.std
44+
disp = disp / 255
45+
return rgb, disp, lidar, depth, K_cam
46+
47+
class Jitter(object):
48+
"""
49+
borrow from https://github.com/kujason/avod/blob/master/avod/datasets/kitti/kitti_aug.py
50+
"""
51+
52+
def __call__(self, rgb, disp, lidar, depth, K_cam):
53+
pca = compute_pca(rgb)
54+
rgb = add_pca_jitter(rgb, pca)
55+
return rgb, disp, lidar, depth, K_cam
56+
57+
58+
59+
class Flip(object):
60+
"""
61+
random horizontal flip of images.
62+
"""
63+
64+
def __call__(self, rgb, disp, lidar, depth, CamK):
65+
width = rgb.shape[1]
66+
flip = bool(np.random.randint(2))
67+
if flip:
68+
rgb = rgb[:, ::-1, :]
69+
lidar = lidar[:, ::-1, :]
70+
depth = depth[:, ::-1, :]
71+
CamK[0, 2] = (width - 1) - CamK[0, 2]
72+
return rgb, disp, lidar, depth, CamK
73+
74+
75+
def compute_pca(image):
76+
"""
77+
calculate PCA of image
78+
"""
79+
80+
reshaped_data = image.reshape(-1, 3)
81+
reshaped_data = (reshaped_data / 255.0).astype(np.float32)
82+
covariance = np.cov(reshaped_data.T)
83+
e_vals, e_vecs = np.linalg.eigh(covariance)
84+
pca = np.sqrt(e_vals) * e_vecs
85+
return pca
86+
87+
88+
def add_pca_jitter(img_data, pca):
89+
"""
90+
add a multiple of principle components with Gaussian noise
91+
"""
92+
new_img_data = np.copy(img_data).astype(np.float32) / 255.0
93+
magnitude = np.random.randn(3) * 0.1
94+
noise = (pca * magnitude).sum(axis=1)
95+
96+
new_img_data = new_img_data + noise
97+
np.clip(new_img_data, 0.0, 1.0, out=new_img_data)
98+
new_img_data = (new_img_data * 255).astype(np.uint8)
99+
100+
return new_img_data

checkpoints/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

configs/config.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
defaults:
2+
- hydra
3+
- optim: AdamW
4+
- sched/lr: NoiseOneCycleCosMo
5+
- data: KITTI
6+
- net: PMP
7+
- loss: MSMSE
8+
- metric: RMSE
9+
- _self_
10+
#
11+
12+
nepoch: 30
13+
test_epoch: 25
14+
test_iter: 1000
15+
lr: 0.001
16+
gpus:
17+
- 0
18+
train_batch_size: 2
19+
test_batch_size: 2
20+
num_workers: 4
21+
manual_seed: 1
22+
vis_iter: 100
23+
start_epoch: 0
24+
gpu_id: ???
25+
name: ???
26+
device:
27+
_target_: torch.device
28+
device: cuda:${gpu_id}

configs/data/KITTI.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
mean:
2+
- 90.9950
3+
- 96.2278
4+
- 94.3213
5+
std:
6+
- 79.2382
7+
- 80.5267
8+
- 82.1483
9+
train_sample_size: 85898
10+
test_sample_size: 1000
11+
height: 256
12+
width: 1216
13+
14+
trainset:
15+
_target_: datasets.KITTI
16+
mode: 'train'
17+
RandCrop: true
18+
path: ${data.path}
19+
height: ${data.height}
20+
width: ${data.width}
21+
mean: ${data.mean}
22+
std: ${data.std}
23+
24+
testset:
25+
_target_: datasets.KITTI
26+
mode: 'selval'
27+
RandCrop: false
28+
path: ${data.path}
29+
height: ${data.height}
30+
width: ${data.width}
31+
mean: ${data.mean}
32+
std: ${data.std}
33+
34+
path: datas/kitti
35+
mul_factor: 1.0

configs/data/NYU.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
mean:
2+
- 117.
3+
- 97.
4+
- 91.
5+
std:
6+
- 70.
7+
- 71.
8+
- 74.
9+
train_sample_size: 47584
10+
test_sample_size: 654
11+
height: 256
12+
width: 320
13+
14+
15+
trainset:
16+
_target_: datasets.NYU
17+
mode: 'train'
18+
path: ${data.path}
19+
num_sample: ${data.npoints}
20+
mul_factor: ${data.mul_factor}
21+
num_mask: ${data.num_mask}
22+
scale_kcam: true
23+
24+
25+
testset:
26+
_target_: datasets.NYU
27+
mode: 'val'
28+
path: ${data.path}
29+
num_sample: ${data.npoints}
30+
mul_factor: ${data.mul_factor}
31+
num_mask: ${data.num_mask}
32+
scale_kcam: false
33+
34+
35+
path: datas/nyu
36+
npoints: 500
37+
mul_factor: 10.0
38+
num_mask: 1

configs/hydra.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
hydra:
2+
run:
3+
dir: outputs/${name}/${now:%Y-%m-%d_%H-%M-%S}
4+
output_subdir: .
5+
job:
6+
chdir: false
7+
# job_logging:
8+
# handlers:
9+
# file:
10+
# filename: ${name}.log

configs/loss/MSMSE.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_target_: criteria.MSMSE

configs/metric/MetricALL.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_target_: criteria.MetricALL
2+
mul_factor: ${data.mul_factor}

configs/metric/RMSE.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_target_: criteria.RMSE
2+
mul_factor: ${data.mul_factor}

configs/net/PMP.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Propagation Field Baseline Relu6 Clip EMA
2+
3+
name: PMP
4+
5+
model:
6+
_target_: models.Pre_MF_Post
7+
8+
9+
ema:
10+
_target_: models.EMA
11+
decay: 0.9999
12+
13+
14+
clip:
15+
_target_: utils.clip_grad_norm_
16+
max_norm: 0.1

configs/optim/AdamW.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
_target_: optimizers.AdamW
2+
lr: ${lr}
3+
weight_decay: 0.05
4+
betas:
5+
- 0.9
6+
- 0.999
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#Noise One Cycle Cos With cycle_momentum
2+
policy:
3+
_target_: schedulers.NoiseLR
4+
lr_sched: OneCycleLR
5+
anneal_strategy: cos
6+
epochs: ${nepoch}
7+
div_factor: 40.0
8+
final_div_factor: 0.1
9+
last_epoch: -1
10+
max_lr: ${lr}
11+
cycle_momentum: true
12+
base_momentum: 0.85
13+
max_momentum: 0.95
14+
pct_start: 0.1
15+
noise_pct: 0.1
16+
steps_per_epoch: ${sched.lr.steps_per_epoch}
17+
18+
iter: true
19+
20+
steps_per_epoch:
21+
_target_: utils.FloorDiv
22+
_args_:
23+
- _target_: utils.CeilDiv
24+
_args_:
25+
- ${data.train_sample_size}
26+
- _target_: builtins.len
27+
_args_:
28+
- ${gpus}
29+
- ${train_batch_size}

0 commit comments

Comments
 (0)