From 977cd1c19df2a357765f9f013b9c9fd46d907f88 Mon Sep 17 00:00:00 2001 From: Kin Date: Mon, 26 Dec 2022 23:09:15 +0100 Subject: [PATCH 1/4] fix: if from other folder scripts running config --- pcdet/config.py | 5 ++++- requirements.txt | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pcdet/config.py b/pcdet/config.py index 539167822..1f834f6e8 100644 --- a/pcdet/config.py +++ b/pcdet/config.py @@ -49,8 +49,11 @@ def cfg_from_list(cfg_list, config): def merge_new_config(config, new_config): + # fix maybe? + import os + openpcdet_path = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..')) if '_BASE_CONFIG_' in new_config: - with open(new_config['_BASE_CONFIG_'], 'r') as f: + with open(os.path.join(openpcdet_path, 'tools', new_config['_BASE_CONFIG_']), 'r') as f: try: yaml_config = yaml.safe_load(f, Loader=yaml.FullLoader) except: diff --git a/requirements.txt b/requirements.txt index 40e445981..831f57bfb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,5 +9,3 @@ scikit-image tqdm torchvision SharedArray -json -cv2 From 0d3c1fa92636887266cce75f65da2d17323781d7 Mon Sep 17 00:00:00 2001 From: Kin Date: Wed, 4 Jan 2023 17:29:16 +0100 Subject: [PATCH 2/4] feat: update pcd2bin file to tools --- tools/pcd2bin.py | 127 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 tools/pcd2bin.py diff --git a/tools/pcd2bin.py b/tools/pcd2bin.py new file mode 100644 index 000000000..f5adff0d6 --- /dev/null +++ b/tools/pcd2bin.py @@ -0,0 +1,127 @@ +# +# Module: pcd2bin.py +# Description: .pcd to .bin converter +# +# Author: Yuseung Na (ys.na0220@gmail.com) origin link: https://github.com/Yuseung-Na/pcd2bin +# Version: 1.0 +# Date: January 19, 2021 +# +# Author: Kin ZHANG (https://kin-zhang.github.io/) +# Version: 2.0 +# Date: 2023-01-04 + +# Please run following to install the package: (TESTED on py37 py38), check issue: https://github.com/Yuseung-Na/pcd2bin/issues/8 +# pip uninstall pypcd +# pip install --upgrade git+https://github.com/klintan/pypcd.git + +# How to use: +# python3 pcd2bin.py --pcd_path /home/kin/test/data --bin_path /home/kin/test/data/bin + +import numpy as np +import os +import argparse +from pypcd import pypcd +import csv +from tqdm import tqdm + +def main(): + ## Add parser + parser = argparse.ArgumentParser(description="Convert .pcd to .bin") + parser.add_argument( + "--pcd_path", + help=".pcd file path.", + type=str, + default="/home/kin/test/data" + ) + parser.add_argument( + "--bin_path", + help=".bin file path.", + type=str, + default="/home/kin/test/data" + ) + parser.add_argument( + "--file_name", + help="File name.", + type=str, + default="file_name" + ) + args = parser.parse_args() + + ## Find all pcd files + pcd_files = [] + for (path, dir, files) in os.walk(args.pcd_path): + for filename in files: + # print(filename) + ext = os.path.splitext(filename)[-1] + if ext == '.pcd': + pcd_files.append(path + "/" + filename) + + ## Sort pcd files by file name + pcd_files.sort() + print("Finish to load point clouds!") + + ## Make bin_path directory + try: + if not (os.path.isdir(args.bin_path)): + os.makedirs(os.path.join(args.bin_path)) + except OSError as e: + if e.errno != errno.EEXIST: + print ("Failed to create directory!!!!!") + raise + + ## Generate csv meta file + csv_file_path = os.path.join(args.bin_path, "meta.csv") + csv_file = open(csv_file_path, "w") + meta_file = csv.writer( + csv_file, delimiter=",", quotechar="|", quoting=csv.QUOTE_MINIMAL + ) + ## Write csv meta file header + meta_file.writerow( + [ + "pcd file name", + "bin file name", + ] + ) + print("Finish to generate csv meta file") + + ## Converting Process + print("Converting Start!") + seq = 0 + for pcd_file in tqdm(pcd_files): + ## Get pcd file + pc = pypcd.PointCloud.from_path(pcd_file) + + pcd_file_name = pcd_file.split("/")[-1].split(".")[0] + ## Generate bin file name + bin_file_name = "{}.bin".format(pcd_file_name) + bin_file_path = os.path.join(args.bin_path, bin_file_name) + + ## Get data from pcd (x, y, z, intensity, ring, time) + np_x = (np.array(pc.pc_data['x'], dtype=np.float32)).astype(np.float32) + np_y = (np.array(pc.pc_data['y'], dtype=np.float32)).astype(np.float32) + np_z = (np.array(pc.pc_data['z'], dtype=np.float32)).astype(np.float32) + np_i = np.zeros_like(np_x) + if 'intensity' in pc.fields: + np_i = (np.array(pc.pc_data['intensity'], dtype=np.float32)).astype(np.float32)/256 + elif 'Intensity' in pc.fields: + np_i = (np.array(pc.pc_data['Intensity'], dtype=np.float32)).astype(np.float32)/256 + else: + print(f"The pt fields: {pc.fields}. Please check whether there is an intensity field and add to codes") + # np_r = (np.array(pc.pc_data['ring'], dtype=np.float32)).astype(np.float32) + # np_t = (np.array(pc.pc_data['time'], dtype=np.float32)).astype(np.float32) + + ## Stack all data + points_32 = np.transpose(np.vstack((np_x, np_y, np_z, np_i))) + + ## Save bin file + points_32.tofile(bin_file_path) + + ## Write csv meta file + meta_file.writerow( + [os.path.split(pcd_file)[-1], bin_file_name] + ) + + seq = seq + 1 + +if __name__ == "__main__": + main() \ No newline at end of file From 352fa6d562134fcdee70eef808d14bde5a630276 Mon Sep 17 00:00:00 2001 From: Kin Date: Wed, 4 Jan 2023 18:24:23 +0100 Subject: [PATCH 3/4] fix: monitor the file postfix and select the func also update the readme file --- .gitignore | 1 + README.md | 21 +++++ docker/Dockerfile | 86 +++++++------------ tools/cfgs/dataset_configs/kitti_dataset.yaml | 2 +- tools/demo.py | 8 +- 5 files changed, 60 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 9fd7ec8eb..ea15a62fe 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,6 @@ venv/ *.pkl *.zip *.bin +*.pcd output version.py diff --git a/README.md b/README.md index 6160a84ac..842f40da1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,22 @@ +This repo is modified by Kin, check the commit to see the modification. + + + +Tutorials: + +- **ROS Inference**: [https://github.com/Kin-Zhang/OpenPCDet_ros](https://github.com/Kin-Zhang/OpenPCDet_ros) + +- Chinese Video: [https://www.bilibili.com/video/BV1xe4y1j72q](https://www.bilibili.com/video/BV1xe4y1j72q) + +- Chiese Blog: [【点云检测】OpenPCDet 教程系列 安装 与 ROS运行](https://www.cnblogs.com/kin-zhang/p/17002980.html)) + + + +--- +
+ [Please check the official repo or below origin read for more detail] + + # OpenPCDet @@ -264,3 +283,5 @@ If you find this project useful in your research, please consider cite: Welcome to be a member of the OpenPCDet development team by contributing to this repo, and feel free to contact us for any potential contributions. + +
\ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 3f0114f70..04bf4f3f9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,55 +1,31 @@ -FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04 - -RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections - -# Install basics -RUN apt-get update -y \ - && apt-get install build-essential \ - && apt-get install -y apt-utils git curl ca-certificates bzip2 tree htop wget \ - && apt-get install -y libglib2.0-0 libsm6 libxext6 libxrender-dev bmon iotop g++ python3.7 python3.7-dev python3.7-distutils - -# Install cmake v3.13.2 -RUN apt-get purge -y cmake && \ - mkdir /root/temp && \ - cd /root/temp && \ - wget https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2.tar.gz && \ - tar -xzvf cmake-3.13.2.tar.gz && \ - cd cmake-3.13.2 && \ - bash ./bootstrap && \ - make && \ - make install && \ - cmake --version && \ - rm -rf /root/temp - -# Install python -RUN ln -sv /usr/bin/python3.7 /usr/bin/python -RUN wget https://bootstrap.pypa.io/get-pip.py && \ - python get-pip.py && \ - rm get-pip.py - -# Install python packages -RUN PIP_INSTALL="python -m pip --no-cache-dir install" && \ - $PIP_INSTALL numpy==1.19.3 llvmlite numba - -# Install torch and torchvision -# See https://pytorch.org/ for other options if you use a different version of CUDA -RUN pip install --user torch==1.6 torchvision==0.7.0 -f https://download.pytorch.org/whl/cu102/torch_stable.html - -# Install python packages -RUN PIP_INSTALL="python -m pip --no-cache-dir install" && \ - $PIP_INSTALL tensorboardX easydict pyyaml scikit-image tqdm SharedArray six - -WORKDIR /root - -# Install Boost geometry -RUN wget https://jaist.dl.sourceforge.net/project/boost/boost/1.68.0/boost_1_68_0.tar.gz && \ - tar xzvf boost_1_68_0.tar.gz && \ - cp -r ./boost_1_68_0/boost /usr/include && \ - rm -rf ./boost_1_68_0 && \ - rm -rf ./boost_1_68_0.tar.gz - -# A weired problem that hasn't been solved yet -RUN pip uninstall -y SharedArray && \ - pip install SharedArray - -RUN pip install spconv-cu102 \ No newline at end of file +FROM nvidia/cuda:11.3.0-devel-ubuntu20.04 +LABEL maintainer="Kin Zhang https://kin-zhang.github.io/" +# Just in case we need it +ENV DEBIAN_FRONTEND noninteractive + +RUN apt update && apt install -y --no-install-recommends git curl wget git zsh tmux vim g++ +# needs to be done before we can apply the patches +RUN git config --global user.email "kin_eng@163.com" +RUN git config --global user.name "kin-docker" + +# install zsh +RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.2/zsh-in-docker.sh)" -- \ + -t robbyrussell \ + -p git \ + -p ssh-agent \ + -p https://github.com/agkozak/zsh-z \ + -p https://github.com/zsh-users/zsh-autosuggestions \ + -p https://github.com/zsh-users/zsh-completions \ + -p https://github.com/zsh-users/zsh-syntax-highlighting + +# =========> INSTALL OpenPCDet <============= +RUN apt update && apt install -y python3-pip +RUN pip3 install torch==1.10.0+cu113 torchvision==0.11.0+cu113 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html +RUN pip3 install spconv-cu113 +RUN apt update && apt install -y python3-setuptools +RUN mkdir -p /home/kin/workspace +WORKDIR /home/kin/workspace +RUN git clone https://github.com/Kin-Zhang/OpenPCDet.git +RUN cd OpenPCDet && pip3 install -r requirements.txt +RUN pip3 install pyquaternion numpy==1.23 pillow==8.4 mayavi open3d +# RUN cd OpenPCDet && python3 setup.py develop # need run inside the container!!! \ No newline at end of file diff --git a/tools/cfgs/dataset_configs/kitti_dataset.yaml b/tools/cfgs/dataset_configs/kitti_dataset.yaml index b1529aa0a..98089d342 100644 --- a/tools/cfgs/dataset_configs/kitti_dataset.yaml +++ b/tools/cfgs/dataset_configs/kitti_dataset.yaml @@ -1,7 +1,7 @@ DATASET: 'KittiDataset' DATA_PATH: '../data/kitti' -POINT_CLOUD_RANGE: [0, -40, -3, 70.4, 40, 1] +POINT_CLOUD_RANGE: [-50, -50, -3, 70.4, 40, 1] DATA_SPLIT: { 'train': train, diff --git a/tools/demo.py b/tools/demo.py index 259d469f3..46585ca01 100644 --- a/tools/demo.py +++ b/tools/demo.py @@ -44,10 +44,14 @@ def __len__(self): return len(self.sample_file_list) def __getitem__(self, index): - if self.ext == '.bin': + file_postfix = self.sample_file_list[index].as_posix().split(".")[-1] + if file_postfix == 'bin': points = np.fromfile(self.sample_file_list[index], dtype=np.float32).reshape(-1, 4) - elif self.ext == '.npy': + elif file_postfix == 'npy': points = np.load(self.sample_file_list[index]) + elif file_postfix == 'pcd': + print("\033[93mPlease run the pcd2bin file first!\033[0m Check the file in this folder, \n\ror click here: https://github.com/Kin-Zhang/OpenPCDet/blob/master/tools/pcd2bin.py \n\r") + raise NotImplementedError else: raise NotImplementedError From 75f6fefa11d085279b665ab7926e16c4c6e65f31 Mon Sep 17 00:00:00 2001 From: Qingwen Zhang <35365764+Kin-Zhang@users.noreply.github.com> Date: Sat, 29 Mar 2025 07:44:44 +0000 Subject: [PATCH 4/4] hotfix: Update kitti_dataset.yaml related to this issue: https://github.com/Kin-Zhang/OpenPCDet_ros/issues/12 --- tools/cfgs/dataset_configs/kitti_dataset.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/cfgs/dataset_configs/kitti_dataset.yaml b/tools/cfgs/dataset_configs/kitti_dataset.yaml index 98089d342..f9cf23684 100644 --- a/tools/cfgs/dataset_configs/kitti_dataset.yaml +++ b/tools/cfgs/dataset_configs/kitti_dataset.yaml @@ -1,7 +1,9 @@ DATASET: 'KittiDataset' DATA_PATH: '../data/kitti' -POINT_CLOUD_RANGE: [-50, -50, -3, 70.4, 40, 1] +# FIXME: check why full view is not working. +# POINT_CLOUD_RANGE: [-50, -50, -3, 70.4, 40, 1] +POINT_CLOUD_RANGE: [0, -40, -3, 70.4, 40, 1] DATA_SPLIT: { 'train': train,