Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python version
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install -U clang-format==10.0.1.1 yapf==0.30.0 nbformat pydocstyle==6.0.0
python -m pip install -U clang-format==18.* yapf==0.43.* nbformat==5.10.* pydocstyle==6.0.0
- name: Run style check
run: |
python ci/check_style.py --verbose
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ permissions: {}
on:
workflow_dispatch:
push:
branches: [main, dev]
branches: [main]
pull_request:
types: [opened, reopened, synchronize]

Expand All @@ -19,7 +19,7 @@ jobs:
ubuntu:
permissions:
contents: read
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Set up Python version
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
# Pre-installed packages: https://github.com/actions/runner-images/tree/main/images
- name: Install ccache
run: |
Expand Down
82 changes: 33 additions & 49 deletions ci/check_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,11 @@
from functools import partial
import time
import sys

# Yapf requires python 3.6+
if not (sys.version_info.major == 3 and sys.version_info.minor >= 6):
raise RuntimeError(
"Requires Python 3.6+, currently using Python {}.{}.".format(
sys.version_info.major, sys.version_info.minor))

# Check and import yapf
# > not found: throw exception
# > version mismatch: throw exception
try:
import yapf
except:
raise ImportError(
"yapf not found. Install with `pip install yapf==0.30.0`.")
if yapf.__version__ != "0.30.0":
raise RuntimeError(
"yapf 0.30.0 required. Install with `pip install yapf==0.30.0`.")
print("Using yapf version {}".format(yapf.__version__))

# Check and import nbformat
# > not found: throw exception
try:
import nbformat
except:
raise ImportError(
"nbformat not found. Install with `pip install nbformat`.")
print("Using nbformat version {}".format(nbformat.__version__))
import yapf
import nbformat

PYTHON_FORMAT_DIRS = ["."]

JUPYTER_FORMAT_DIRS = ["."]

# Note: also modify CPP_FORMAT_DIRS in check_cpp_style.cmake.
CPP_FORMAT_DIRS = ["."]

Expand Down Expand Up @@ -86,8 +58,8 @@ def _apply_style(file_path, style_config):
style_config=style_config,
in_place=True)

def run(self, do_apply_style, no_parallel, verbose):
if do_apply_style:
def run(self, apply, no_parallel, verbose):
if apply:
print("Applying Python style...")
else:
print("Checking Python style...")
Expand All @@ -112,7 +84,7 @@ def run(self, do_apply_style, no_parallel, verbose):
for is_valid, file_path in zip(is_valid_files, self.file_paths):
if not is_valid:
changed_files.append(file_path)
if do_apply_style:
if apply:
self._apply_style(file_path, self.style_config)
print("Formatting takes {:.2f}s".format(time.time() - start_time))

Expand All @@ -126,7 +98,7 @@ def __init__(self, file_paths, style_config):
self.style_config = style_config

@staticmethod
def _check_or_apply_style(file_path, style_config, do_apply_style):
def _check_or_apply_style(file_path, style_config, apply):
"""Returns true if style is valid.

Since there are common code for check and apply style, the two functions
Expand All @@ -142,27 +114,39 @@ def _check_or_apply_style(file_path, style_config, do_apply_style):
if cell["cell_type"] != "code":
continue
src = cell["source"]
if not src.strip(): # Ignore empty cells.
continue
lines = src.split("\n")
if len(lines) <= 0 or "# noqa" in lines[0]:
if "# noqa" in lines[0]:
continue
# Ignore cells starting with shell commands or jupyter magics.
# These are not valid python code and yapf will fail.
if src.lstrip().startswith(('!', '%')):
continue

# yapf will puts a `\n` at the end of each cell, and if this is the
# only change, cell_changed is still False.
formatted_src, cell_changed = yapf.yapflib.yapf_api.FormatCode(
src, style_config=style_config)
try:
formatted_src, cell_changed = yapf.yapflib.yapf_api.FormatCode(
src, style_config=style_config)
except Exception:
# This may happen for cells with valid python and magics/shell
# commands mixed. We will just ignore formatting for these cells.
continue
if formatted_src.endswith("\n"):
formatted_src = formatted_src[:-1]
if cell_changed:
cell["source"] = formatted_src
changed = True

if do_apply_style:
if apply:
with open(file_path, "w") as f:
nbformat.write(notebook, f, version=nbformat.NO_CONVERT)

return not changed

def run(self, do_apply_style, no_parallel, verbose):
if do_apply_style:
def run(self, apply, no_parallel, verbose):
if apply:
print("Applying Jupyter style...")
else:
print("Checking Jupyter style...")
Expand All @@ -177,22 +161,22 @@ def run(self, do_apply_style, no_parallel, verbose):
is_valid_files = map(
partial(self._check_or_apply_style,
style_config=self.style_config,
do_apply_style=False), self.file_paths)
apply=False), self.file_paths)
else:
with multiprocessing.Pool(multiprocessing.cpu_count()) as pool:
is_valid_files = pool.map(
partial(self._check_or_apply_style,
style_config=self.style_config,
do_apply_style=False), self.file_paths)
apply=False), self.file_paths)

changed_files = []
for is_valid, file_path in zip(is_valid_files, self.file_paths):
if not is_valid:
changed_files.append(file_path)
if do_apply_style:
if apply:
self._check_or_apply_style(file_path,
style_config=self.style_config,
do_apply_style=True)
apply=True)
print("Formatting takes {:.2f}s".format(time.time() - start_time))

return changed_files
Expand All @@ -207,8 +191,8 @@ def run(self, do_apply_style, no_parallel, verbose):

parser = argparse.ArgumentParser()
parser.add_argument(
"--do_apply_style",
dest="do_apply_style",
"--apply",
dest="apply",
action="store_true",
default=False,
help="Apply style to files in-place.",
Expand Down Expand Up @@ -242,16 +226,16 @@ def run(self, do_apply_style, no_parallel, verbose):

changed_files = []
changed_files.extend(
python_formatter.run(do_apply_style=args.do_apply_style,
python_formatter.run(apply=args.apply,
no_parallel=args.no_parallel,
verbose=args.verbose))
changed_files.extend(
jupyter_formatter.run(do_apply_style=args.do_apply_style,
jupyter_formatter.run(apply=args.apply,
no_parallel=args.no_parallel,
verbose=args.verbose))

if len(changed_files) != 0:
if args.do_apply_style:
if args.apply:
print("Style applied to the following files:")
print("\n".join(changed_files))
else:
Expand Down
12 changes: 5 additions & 7 deletions ci/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail

NPROC=${NPROC:?'env var must be set to number of available CPUs.'}
PIP_VER="23.2.1"
PIP_VER="24.3.1"

echo 1. Prepare the Open3D-ML repo and install dependencies
echo
Expand All @@ -13,15 +13,15 @@ echo "$PATH_TO_OPEN3D_ML"
git checkout -b main || true
python -m pip install -U pip==$PIP_VER
python -m pip install -r requirements.txt \
-r requirements-torch.txt
# -r requirements-tensorflow.txt # TF disabled on Linux (Open3D PR#6288)
-r requirements-torch.txt \
-r requirements-tensorflow.txt
# -r requirements-openvino.txt # Numpy version conflict with TF 2.8.2
cd ..
python -m pip install -U Cython

echo 2. clone Open3D and install dependencies
echo
git clone --branch main https://github.com/isl-org/Open3D.git
git clone --branch main --depth 1 https://github.com/isl-org/Open3D.git

./Open3D/util/install_deps_ubuntu.sh assume-yes
python -m pip install -r Open3D/python/requirements.txt \
Expand All @@ -32,11 +32,9 @@ echo 3. Configure for bundling the Open3D-ML part
echo
mkdir Open3D/build
pushd Open3D/build
# TF disabled on Linux (Open3D PR#6288)
cmake -DBUNDLE_OPEN3D_ML=ON \
-DOPEN3D_ML_ROOT="${PATH_TO_OPEN3D_ML}" \
-DGLIBCXX_USE_CXX11_ABI=OFF \
-DBUILD_TENSORFLOW_OPS=OFF \
-DBUILD_TENSORFLOW_OPS=ON \
-DBUILD_PYTORCH_OPS=ON \
-DBUILD_GUI=ON \
-DBUILD_UNIT_TESTS=OFF \
Expand Down
8 changes: 4 additions & 4 deletions ml3d/datasets/utils/dataprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ def remove_outside_points(points, world_cam, cam_img, image_shape):
pts_cam = DataProcessing.world2cam(points[:, :3], world_cam)
pts_img, depth = DataProcessing.cam2img(pts_cam, cam_img)

val_flag_1 = np.logical_and(pts_img[:, 0] >= 0,
pts_img[:, 0] < image_shape[1])
val_flag_2 = np.logical_and(pts_img[:, 1] >= 0,
pts_img[:, 1] < image_shape[0])
val_flag_1 = np.logical_and(pts_img[:, 0] >= 0, pts_img[:, 0]
< image_shape[1])
val_flag_2 = np.logical_and(pts_img[:, 1] >= 0, pts_img[:, 1]
< image_shape[0])
val_flag_merge = np.logical_and(val_flag_1, val_flag_2)
valid = np.logical_and(val_flag_merge, depth >= 0)

Expand Down
6 changes: 3 additions & 3 deletions ml3d/metrics/mAP.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def precision_3d(pred,
axis=1).astype("float32")

# identify all matches (filtered preds vs filtered targets)
match_cond = np.any(
overlap_label[pred_idx][:, target_idx] >= min_overlap[i],
axis=-1)
match_cond = np.any(overlap_label[pred_idx][:, target_idx]
>= min_overlap[i],
axis=-1)
tp = np.zeros((len(pred_idx),))

# all matches first fp
Expand Down
1 change: 1 addition & 0 deletions ml3d/tf/dataloaders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dataloader for TensorFlow."""

from .tf_dataloader import TFDataloader

__all__ = ['TFDataloader']
8 changes: 4 additions & 4 deletions ml3d/tf/models/point_pillars.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ def preprocess(self, data, attr):
max_val = np.array(self.point_cloud_range[3:])

points = points[np.where(
np.all(np.logical_and(points[:, :3] >= min_val,
points[:, :3] < max_val),
np.all(np.logical_and(points[:, :3] >= min_val, points[:, :3]
< max_val),
axis=-1))]

data['point'] = points
Expand All @@ -264,8 +264,8 @@ def preprocess(self, data, attr):
max_val = np.array(self.point_cloud_range[3:])

points = points[np.where(
np.all(np.logical_and(points[:, :3] >= min_val,
points[:, :3] < max_val),
np.all(np.logical_and(points[:, :3] >= min_val, points[:, :3]
< max_val),
axis=-1))]

new_data['full_point'] = points
Expand Down
8 changes: 4 additions & 4 deletions ml3d/tf/models/point_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ def batcher():
for lab in labels:
max_lab = max(max_lab, lab.shape[0])

if 'labels' in batch[
0] and labels[0].shape[0] != points.shape[1]:
if 'labels' in batch[0] and labels[0].shape[0] != points.shape[
1]:
pad_labels = np.ones(
(len(labels), max_lab), dtype=np.int32) * (-1)
for j in range(len(labels)):
Expand Down Expand Up @@ -774,8 +774,8 @@ def __init__(
self.SA_modules = []
for i in range(len(SA_config["npoints"])):
mlps = [in_channels] + SA_config["mlps"][i]
npoint = SA_config["npoints"][
i] if SA_config["npoints"][i] != -1 else None
npoint = SA_config["npoints"][i] if SA_config["npoints"][
i] != -1 else None
self.SA_modules.append(
PointnetSAModule(npoint=npoint,
radius=SA_config["radius"][i],
Expand Down
8 changes: 4 additions & 4 deletions ml3d/tf/models/pvcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ def preprocess(self, data, attr):

feat = np.concatenate([x, y, z, feat, norm_x, norm_y, norm_z], axis=-1)

choices = np.random.choice(
points.shape[0],
self.cfg.num_points,
replace=(points.shape[0] < self.cfg.num_points))
choices = np.random.choice(points.shape[0],
self.cfg.num_points,
replace=(points.shape[0]
< self.cfg.num_points))
points = points[choices]
feat = feat[choices]
labels = labels[choices]
Expand Down
4 changes: 2 additions & 2 deletions ml3d/tf/modules/pointnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def __init__(
self.FP_modules = []

for i in range(len(fp_mlps)):
pre_channel = fp_mlps[
i + 1][-1] if i + 1 < len(fp_mlps) else out_channels
pre_channel = fp_mlps[i + 1][-1] if i + 1 < len(
fp_mlps) else out_channels
self.FP_modules.append(
PointnetFPModule(mlp=[pre_channel + skip_channel_list[i]] +
fp_mlps[i],
Expand Down
2 changes: 1 addition & 1 deletion ml3d/torch/dataloaders/torch_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self,
continue
data = dataset.get_data(idx)
# cache the data
self.cache_convert(name, data, attr)
self.cache_convert(name, data, attr)

self.transform = transform

Expand Down
Loading
Loading