Skip to content

Commit 5d89648

Browse files
committed
Merge remote-tracking branch 'kth-rpl/main'
2 parents 042c8f8 + 5046a00 commit 5d89648

51 files changed

Lines changed: 3032 additions & 128 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ cancel.sh
2525
# cuda build files
2626
*.egg-info
2727
build*
28-
dist*
28+
dist*
29+
30+
data
31+
*__pycache__

Dockerfile

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-devel
1+
# check more: https://hub.docker.com/r/nvidia/cuda
2+
FROM nvidia/cuda:11.7.1-devel-ubuntu20.04
23
ENV DEBIAN_FRONTEND noninteractive
34
LABEL maintainer="Qingwen Zhang <https://kin-zhang.github.io/>"
45

5-
RUN apt update && apt install -y git tmux curl vim rsync libgl1 libglib2.0-0 ca-certificates
6+
RUN apt update && apt install -y git curl vim rsync htop
7+
8+
RUN curl -o ~/miniforge3.sh -LO https://github.com/conda-forge/miniforge/releases/latest/download/miniforge3-Linux-x86_64.sh && \
9+
chmod +x ~/miniforge3.sh && \
10+
~/miniforge3.sh -b -p /opt/conda && \
11+
rm ~/miniforge3.sh && \
12+
/opt/conda/bin/conda clean -ya && /opt/conda/bin/conda init bash && /opt/conda/bin/conda init zsh
613

714
# install zsh and oh-my-zsh
815
RUN apt update && apt install -y wget git zsh tmux vim g++
@@ -14,23 +21,28 @@ RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/
1421
-p https://github.com/zsh-users/zsh-syntax-highlighting
1522

1623
RUN printf "y\ny\ny\n\n" | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Kin-Zhang/Kin-Zhang/main/scripts/setup_ohmyzsh.sh)"
17-
RUN /opt/conda/bin/conda init zsh
1824

1925
# change to conda env
2026
ENV PATH /opt/conda/bin:$PATH
21-
RUN /opt/conda/bin/conda config --set solver libmamba
2227

23-
RUN mkdir -p /home/kin/workspace && cd /home/kin/workspace && git clone https://github.com/Kin-Zhang/OpenSceneFlow
28+
RUN mkdir -p /home/kin/workspace && cd /home/kin/workspace && git clone https://github.com/KTH-RPL/OpenSceneFlow.git
2429
WORKDIR /home/kin/workspace/OpenSceneFlow
30+
RUN apt-get update && apt-get install libgl1 -y
2531

2632
# need read the gpu device info to compile the cuda extension
27-
RUN /opt/conda/bin/pip install -r /home/kin/workspace/OpenSceneFlow/requirements.txt
28-
RUN /opt/conda/bin/pip install FastGeodis --no-build-isolation
29-
RUN /opt/conda/bin/pip install --no-cache-dir -e ./assets/cuda/chamfer3D && /opt/conda/bin/pip install --no-cache-dir -e ./assets/cuda/mmcv
33+
RUN cd /home/kin/workspace/OpenSceneFlow && /opt/conda/bin/conda env create -f environment.yaml
34+
# To make images can run all methods in the codebase
35+
RUN /opt/conda/envs/opensf/bin/pip install torch-scatter -f https://data.pyg.org/whl/torch-2.0.0+cu117.html
36+
RUN /opt/conda/envs/opensf/bin/pip install FastGeodis --no-build-isolation --no-cache-dir
37+
RUN /opt/conda/envs/opensf/bin/pip install mmengine-lite && \
38+
/opt/conda/bin/conda install -n opensf -y pytorch3d -c pytorch3d
39+
40+
# custom cuda library
41+
RUN cd /home/kin/workspace/OpenSceneFlow/assets/cuda/mmcv && /opt/conda/envs/opensf/bin/python ./setup.py install
42+
RUN cd /home/kin/workspace/OpenSceneFlow/assets/cuda/chamfer3D && /opt/conda/envs/opensf/bin/python ./setup.py install
3043

31-
# environment for dataprocessing includes data-api
32-
RUN /opt/conda/bin/conda env create -f envsftool.yaml
44+
RUN cd /home/kin/workspace/OpenSceneFlow && /opt/conda/bin/conda env create -f envsftool.yaml
3345
RUN /opt/conda/envs/sftool/bin/pip install numpy==1.22
3446

3547
# clean up apt cache
36-
RUN rm -rf /var/lib/apt/lists/* && rm -rf /root/.cache/pip
48+
RUN rm -rf /var/lib/apt/lists/* && rm -rf /root/.cache/pip && /opt/conda/bin/conda clean -ya

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Stay tuned and feel free to star ⭐ this repository to get notified when we pub
2020
- 2025/08/24: I'm updating some codes for early release.
2121
- [x] 2025/08/24: Updating train data augmentation as illustrated in the DeltaFlow paper.
2222
- [x] 2025/08/25: Updating paper preprint link.
23+
- [x] 2025/09/05: Merged the latest commit from OpenSceneFlow codebase to DeltaFlow for afterward unified merged.
2324
- [ ] DeltaFlow Model python file.
2425
- [ ] pre-trained weights upload.
2526
- [ ] DeltaFlow Loss fn.
@@ -36,4 +37,4 @@ Stay tuned and feel free to star ⭐ this repository to get notified when we pub
3637
}
3738
```
3839

39-
This work was partially supported by the Wallenberg AI, Autonomous Systems and Software Program (WASP) funded by the Knut and Alice Wallenberg Foundation and Prosense (2020-02963) funded by Vinnova.
40+
This work was partially supported by the Wallenberg AI, Autonomous Systems and Software Program (WASP) funded by the Knut and Alice Wallenberg Foundation and Prosense (2020-02963) funded by Vinnova.

assets/cuda/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Faster our code in CUDA.
55

66
- chamfer3D: 3D chamfer distance within two point cloud, by Qingwen Zhang involved when she was working on SeFlow.
77
- mmcv: directly from mmcv, not our code.
8+
- mmdet: only python file, no need to compile
9+
- histlib: from Yancong's [ICP-Flow](https://github.com/yanconglin/ICP-Flow) project.
810

911
---
1012

assets/cuda/chamfer3D/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def dis_res(self, input0, input1):
7474
dist0, dist1, _, _ = ChamferDis.apply(input0, input1)
7575
return dist0, dist1
7676

77-
def truncated_dis(self, input0, input1):
77+
def truncated_dis(self, input0, input1, truncate_dist=2):
7878
# nsfp: truncated distance way is set >= 2 to 0 but not nanmean
7979
cham_x, cham_y = self.dis_res(input0, input1)
80-
cham_x[cham_x >= 2] = 0.0
81-
cham_y[cham_y >= 2] = 0.0
80+
cham_x[cham_x >= truncate_dist] = 0.0
81+
cham_y[cham_y >= truncate_dist] = 0.0
8282
return torch.mean(cham_x) + torch.mean(cham_y)
8383

8484
def disid_res(self, input0, input1):

assets/cuda/histlib/__init__.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from torch import nn
2+
from torch.autograd import Function
3+
import torch
4+
import importlib
5+
6+
import os, time
7+
import hist
8+
9+
def histf(X, Y, min_x, min_y, min_z, max_x, max_y, max_z, len_x, len_y, len_z, mini_batch=8):
10+
# print('hist cuda params: ', X.shape, Y.shape,
11+
# min_x, min_y, min_z,
12+
# max_x, max_y, max_z,
13+
# len_x, len_y, len_z,
14+
# )
15+
histogram = hist.hist(X.contiguous(), Y.contiguous(),
16+
min_x, min_y, min_z,
17+
max_x, max_y, max_z,
18+
len_x, len_y, len_z,
19+
mini_batch
20+
)
21+
return histogram
22+
23+
24+
torch.manual_seed(2022)
25+
26+
########################
27+
def run_test():
28+
pts = torch.randn(3, 1000, 3)
29+
indicators = torch.randint(0, 2, size=(3, 1000, 1))
30+
pts1 = torch.cat([pts, indicators], dim=-1)
31+
pts2 = pts1.clone()
32+
pts2[:, :,0] += 5.
33+
pts2[:, :,1] += -3.
34+
pts2[:, :,2] += -0.2
35+
36+
range_x = 10.
37+
range_y = 10.
38+
range_z = 0.5
39+
thres =0.1
40+
# bins_x = torch.linspace(-range_x, range_x, int(2*range_x/thres)+1)
41+
# bins_y = torch.linspace(-range_y, range_y, int(2*range_y/thres)+1)
42+
# bins_z = torch.linspace(-range_z, range_z, int(2*range_z/thres)+1)
43+
bins_x = torch.arange(-range_x, range_x+thres, thres)
44+
bins_y = torch.arange(-range_y, range_y+thres, thres)
45+
bins_z = torch.arange(-range_z, range_z+thres, thres)
46+
print('bins_x: ', bins_x)
47+
print('bins_z: ', bins_z)
48+
pts1 = pts1.cuda()
49+
pts2 = pts2.cuda()
50+
bins_x = bins_x.cuda()
51+
bins_y = bins_y.cuda()
52+
bins_z = bins_z.cuda()
53+
54+
t_hists = histf(pts1, pts2,
55+
-range_x, -range_y, -range_z,
56+
range_x, range_y, range_z,
57+
len(bins_x), len(bins_y), len(bins_z),
58+
)
59+
print('output shape: ', t_hists.shape)
60+
b, h, w, d = t_hists.shape
61+
for t_hist in t_hists:
62+
t_argmax = torch.argmax(t_hist)
63+
print(f't_argmax: {t_argmax}, {t_hist.max()} {h}, {w}, {d}, {t_argmax//d//w%h}, {t_argmax//d%w}, {t_argmax%d}')
64+
print('t_argmax', t_argmax//d//w%h, t_argmax//d%w, t_argmax%d, bins_x[t_argmax//d//w%h], bins_y[t_argmax//d%w], bins_z[t_argmax%d])
65+
66+
if __name__ == '__main__':
67+
68+
print("Pytorch version: ", torch.__version__)
69+
print("GPU version: ", torch.cuda.get_device_name())
70+
71+
run_test()

assets/cuda/histlib/hist.cu

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <vector>
2+
#include "hist_cuda_core.cuh"
3+
4+
#include <ATen/ATen.h>
5+
#include <ATen/cuda/CUDAContext.h>
6+
#include <cuda.h>
7+
#include <cuda_runtime.h>
8+
9+
// #include <THC/THC.h>
10+
// #include <THC/THCAtomics.cuh>
11+
// #include <THC/THCDeviceUtils.cuh>
12+
13+
// extern THCState *state;
14+
15+
// author: Charles Shang
16+
// https://github.com/torch/cunn/blob/master/lib/THCUNN/generic/SpatialConvolutionMM.cu
17+
18+
19+
at::Tensor
20+
hist_cuda(const at::Tensor &X, const at::Tensor &Y,
21+
const float min_x, const float min_y, const float min_z,
22+
const float max_x, const float max_y, const float max_z,
23+
const int len_x, const int len_y, const int len_z,
24+
const int mini_batch
25+
)
26+
{
27+
// THCAssertSameGPU(THCudaTensor_checkGPU(state, 5, input, weight, bias, offset, mask));
28+
29+
AT_ASSERTM(X.is_contiguous(), "input tensor has to be contiguous");
30+
AT_ASSERTM(Y.is_contiguous(), "input tensor has to be contiguous");
31+
32+
AT_ASSERTM(X.type().is_cuda(), "input must be a CUDA tensor");
33+
AT_ASSERTM(Y.type().is_cuda(), "input must be a CUDA tensor");
34+
35+
const int batch = X.size(0);
36+
const int num_X = X.size(1);
37+
const int dim = X.size(2);
38+
const int num_Y = Y.size(1);
39+
40+
AT_ASSERTM((X.size(0) == Y.size(0)), "batch_X (%d) != batch_Y (%d).", X.size(0), Y.size(0));
41+
AT_ASSERTM((X.size(2) == Y.size(2)), "dim_X (%d) != dim_Y (%d).", X.size(2), Y.size(2));
42+
43+
AT_ASSERTM((dim == 4), "dim (%d) != 4; 3 for (x, y, z); 1 for indicator,padded or not.", dim);
44+
45+
// printf("len: %d %d %f \n", len_x, len_y, len_z);
46+
// printf("hist cuda coord: %f, %f, %f; %f, %f, %f; %f, %f, %f. \n", val_x, val_y, val_z, p_x, p_y, p_z, len_x, len_y, len_z);
47+
48+
// auto bins = at::zeros({batch, len_x, len_y, len_z}, X.options());
49+
// AT_DISPATCH_FLOATING_TYPES(X.type(), "hist_cuda_core", ([&] {
50+
// hist_cuda_core(at::cuda::getCurrentCUDAStream(),
51+
// X.data<scalar_t>(), Y.data<scalar_t>(),
52+
// batch, dim, num_X, num_Y,
53+
// min_x, min_y, min_z,
54+
// max_x, max_y, max_z,
55+
// len_x, len_y, len_z,
56+
// bins.data<scalar_t>());
57+
// }));
58+
59+
auto bins = at::zeros({batch, len_x, len_y, len_z}, X.options());
60+
61+
int iters = batch / mini_batch;
62+
if (batch % mini_batch != 0)
63+
{
64+
iters += 1;
65+
}
66+
67+
for (int i=0; i<iters; ++i)
68+
{
69+
int mini_batch_ = mini_batch;
70+
if ((i+1) * mini_batch > batch)
71+
{
72+
mini_batch_ = batch - i * mini_batch;
73+
}
74+
// printf("iter: %d %d %d %d %d \n", i, iters, mini_batch_, mini_batch, batch);
75+
AT_DISPATCH_FLOATING_TYPES(X.type(), "hist_cuda_core", ([&] {
76+
hist_cuda_core(at::cuda::getCurrentCUDAStream(),
77+
X.data<scalar_t>() + i*mini_batch*num_X*dim,
78+
Y.data<scalar_t>() + i*mini_batch*num_Y*dim,
79+
mini_batch_, dim, num_X, num_Y,
80+
min_x, min_y, min_z,
81+
max_x, max_y, max_z,
82+
len_x, len_y, len_z,
83+
bins.data<scalar_t>()+i*mini_batch*len_x*len_y*len_z);
84+
}));
85+
}
86+
87+
88+
89+
return bins;
90+
}

assets/cuda/histlib/hist.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
#include <torch/extension.h>
3+
4+
at::Tensor
5+
hist(const at::Tensor &X, const at::Tensor &Y,
6+
const float min_x, const float min_y, const float min_z,
7+
const float max_x, const float max_y, const float max_z,
8+
const int len_x, const int len_y, const int len_z,
9+
const int mini_batch
10+
);
11+
12+
13+

assets/cuda/histlib/hist_cuda.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "hist.h"
2+
#include "hist_cuda.h"
3+
4+
at::Tensor
5+
hist(const at::Tensor &X, const at::Tensor &Y,
6+
const float min_x, const float min_y, const float min_z,
7+
const float max_x, const float max_y, const float max_z,
8+
const int len_x, const int len_y, const int len_z,
9+
const int mini_batch
10+
)
11+
{
12+
13+
if (X.type().is_cuda() && Y.type().is_cuda())
14+
{
15+
return hist_cuda(X, Y,
16+
min_x, min_y, min_z,
17+
max_x, max_y, max_z,
18+
len_x, len_y, len_z,
19+
mini_batch
20+
);
21+
}
22+
AT_ERROR("Not implemented on the CPU");
23+
}
24+
25+
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
26+
m.def("hist", &hist, "hist");
27+
}

assets/cuda/histlib/hist_cuda.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
#include <torch/extension.h>
3+
4+
at::Tensor
5+
hist_cuda(const at::Tensor &X, const at::Tensor &Y,
6+
const float min_x, const float min_y, const float min_z,
7+
const float max_x, const float max_y, const float max_z,
8+
const int len_x, const int len_y, const int len_z,
9+
const int mini_batch
10+
);

0 commit comments

Comments
 (0)