Skip to content

Commit 9a73b2f

Browse files
committed
add pre-commit
1 parent 2b2b431 commit 9a73b2f

File tree

10 files changed

+136
-52
lines changed

10 files changed

+136
-52
lines changed

.isort.cfg

Lines changed: 0 additions & 7 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
repos:
2+
- repo: https://gitlab.com/pycqa/flake8.git
3+
rev: 3.8.3
4+
hooks:
5+
- id: flake8
6+
- repo: https://github.com/asottile/seed-isort-config
7+
rev: v2.2.0
8+
hooks:
9+
- id: seed-isort-config
10+
- repo: https://github.com/timothycrosley/isort
11+
rev: 4.3.21
12+
hooks:
13+
- id: isort
14+
- repo: https://github.com/pre-commit/mirrors-yapf
15+
rev: v0.30.0
16+
hooks:
17+
- id: yapf
18+
- repo: https://github.com/pre-commit/pre-commit-hooks
19+
rev: v3.1.0
20+
hooks:
21+
- id: trailing-whitespace
22+
- id: check-yaml
23+
- id: end-of-file-fixer
24+
- id: requirements-txt-fixer
25+
- id: double-quote-string-fixer
26+
- id: check-merge-conflict
27+
- id: fix-encoding-pragma
28+
args: ["--remove"]
29+
- id: mixed-line-ending
30+
args: ["--fix=lf"]
31+
- repo: https://github.com/myint/docformatter
32+
rev: v1.3.1
33+
hooks:
34+
- id: docformatter
35+
args: ["--in-place", "--wrap-descriptions", "100"]

.style.yapf

Lines changed: 0 additions & 5 deletions
This file was deleted.

setup.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[isort]
2+
line_length = 100
3+
multi_line_output = 0
4+
known_standard_library = setuptools
5+
known_third_party = data,model,munch,numpy,pandas,plyfile,scannet_util,scipy,sklearn,spconv,tensorboardX,torch,tqdm,yaml
6+
no_lines_before = STDLIB,LOCALFOLDER
7+
default_section = THIRDPARTY
8+
9+
[yapf]
10+
BASED_ON_STYLE = pep8
11+
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = true
12+
SPLIT_BEFORE_EXPRESSION_AFTER_OPENING_PAREN = true
13+
COLUMN_LIMIT = 100

softgroup/data/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from torch.utils.data import DataLoader
2+
13
from .s3dis import S3DISDataset
24
from .scannetv2 import ScanNetDataset
3-
from torch.utils.data import DataLoader
45

56
__all__ = ['S3DISDataset', 'ScanNetDataset', 'build_dataset']
67

softgroup/data/s3dis.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
from .custom import CustomDataset
2-
import torch
3-
import numpy as np
4-
from glob import glob
51
import os.path as osp
2+
from glob import glob
3+
4+
import numpy as np
5+
import torch
66

77
from ..lib.softgroup_ops import voxelization_idx
8+
from .custom import CustomDataset
89

910

1011
class S3DISDataset(CustomDataset):
1112

12-
CLASSES = ("ceiling", "floor", "wall", "beam", "column", "window", "door", "chair", "table",
13-
"bookcase", "sofa", "board", "clutter")
13+
CLASSES = ('ceiling', 'floor', 'wall', 'beam', 'column', 'window', 'door', 'chair', 'table',
14+
'bookcase', 'sofa', 'board', 'clutter')
1415

1516
def get_filenames(self):
1617
if isinstance(self.prefix, str):

softgroup/lib/softgroup_ops/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from setuptools import setup
2+
23
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
34

45
setup(

softgroup/model/blocks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from collections import OrderedDict
2+
13
import spconv
4+
import torch
25
from spconv.modules import SparseModule
36
from torch import nn
4-
from collections import OrderedDict
5-
import torch
67

78

89
class ResidualBlock(SparseModule):

softgroup/util/logger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from .dist import get_dist_info
21
import logging
32

3+
from .dist import get_dist_info
4+
45

56
def get_root_logger(log_file=None, log_level=logging.INFO):
67
logger = logging.getLogger('pc-seg')

visualization.py

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import argparse
2+
import os
3+
from operator import itemgetter
4+
15
import numpy as np
2-
import os, glob, argparse
36
import torch
4-
from operator import itemgetter
5-
import cv2
6-
import glob
77

8+
# yapf:disable
89
COLOR_DETECTRON2 = np.array(
910
[
1011
0.000, 0.447, 0.741,
@@ -82,10 +83,14 @@
8283
0.857, 0.857, 0.857,
8384
# 1.000, 1.000, 1.000
8485
]).astype(np.float32).reshape(-1, 3) * 255
86+
# yapf:enable
8587

8688
SEMANTIC_IDXS = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 24, 28, 33, 34, 36, 39])
87-
SEMANTIC_NAMES = np.array(['wall', 'floor', 'cabinet', 'bed', 'chair', 'sofa', 'table', 'door', 'window', 'bookshelf', 'picture', 'counter',
88-
'desk', 'curtain', 'refridgerator', 'shower curtain', 'toilet', 'sink', 'bathtub', 'otherfurniture'])
89+
SEMANTIC_NAMES = np.array([
90+
'wall', 'floor', 'cabinet', 'bed', 'chair', 'sofa', 'table', 'door', 'window', 'bookshelf',
91+
'picture', 'counter', 'desk', 'curtain', 'refridgerator', 'shower curtain', 'toilet', 'sink',
92+
'bathtub', 'otherfurniture'
93+
])
8994
CLASS_COLOR = {
9095
'unannotated': [0, 0, 0],
9196
'floor': [143, 223, 142],
@@ -109,21 +114,43 @@
109114
'sink': [110, 128, 143],
110115
'otherfurniture': [80, 83, 160]
111116
}
112-
SEMANTIC_IDX2NAME = {1: 'wall', 2: 'floor', 3: 'cabinet', 4: 'bed', 5: 'chair', 6: 'sofa', 7: 'table', 8: 'door', 9: 'window', 10: 'bookshelf', 11: 'picture',
113-
12: 'counter', 14: 'desk', 16: 'curtain', 24: 'refridgerator', 28: 'shower curtain', 33: 'toilet', 34: 'sink', 36: 'bathtub', 39: 'otherfurniture'}
117+
SEMANTIC_IDX2NAME = {
118+
1: 'wall',
119+
2: 'floor',
120+
3: 'cabinet',
121+
4: 'bed',
122+
5: 'chair',
123+
6: 'sofa',
124+
7: 'table',
125+
8: 'door',
126+
9: 'window',
127+
10: 'bookshelf',
128+
11: 'picture',
129+
12: 'counter',
130+
14: 'desk',
131+
16: 'curtain',
132+
24: 'refridgerator',
133+
28: 'shower curtain',
134+
33: 'toilet',
135+
34: 'sink',
136+
36: 'bathtub',
137+
39: 'otherfurniture'
138+
}
114139

115140

116141
def get_coords_color(opt):
117142
if opt.dataset == 's3dis':
118143
assert opt.data_split in ['Area_1', 'Area_2', 'Area_3', 'Area_4', 'Area_5', 'Area_6'],\
119144
'data_split for s3dis should be one of [Area_1, Area_2, Area_3, Area_4, Area_5, Area_6]'
120-
input_file = os.path.join('dataset', opt.dataset, 'preprocess', opt.room_name + '_inst_nostuff.pth')
145+
input_file = os.path.join('dataset', opt.dataset, 'preprocess',
146+
opt.room_name + '_inst_nostuff.pth')
121147
assert os.path.isfile(input_file), 'File not exist - {}.'.format(input_file)
122148
xyz, rgb, label, inst_label, _, _ = torch.load(input_file)
123149
# update variable to match scannet format
124150
opt.data_split = os.path.join('val', opt.data_split)
125151
else:
126-
input_file = os.path.join('dataset', opt.dataset, opt.data_split, opt.room_name + '_inst_nostuff.pth')
152+
input_file = os.path.join('dataset', opt.dataset, opt.data_split,
153+
opt.room_name + '_inst_nostuff.pth')
127154
assert os.path.isfile(input_file), 'File not exist - {}.'.format(input_file)
128155
if opt.data_split == 'test':
129156
xyz, rgb = torch.load(input_file)
@@ -136,26 +163,30 @@ def get_coords_color(opt):
136163
assert opt.data_split != 'test'
137164
label = label.astype(np.int)
138165
label_rgb = np.zeros(rgb.shape)
139-
label_rgb[label >= 0] = np.array(itemgetter(*SEMANTIC_NAMES[label[label >= 0]])(CLASS_COLOR))
166+
label_rgb[label >= 0] = np.array(
167+
itemgetter(*SEMANTIC_NAMES[label[label >= 0]])(CLASS_COLOR))
140168
rgb = label_rgb
141169

142170
elif (opt.task == 'semantic_pred'):
143171
assert opt.data_split != 'train'
144-
semantic_file = os.path.join(opt.prediction_path, opt.data_split, 'semantic', opt.room_name + '.npy')
172+
semantic_file = os.path.join(opt.prediction_path, opt.data_split, 'semantic',
173+
opt.room_name + '.npy')
145174
assert os.path.isfile(semantic_file), 'No semantic result - {}.'.format(semantic_file)
146175
label_pred = np.load(semantic_file).astype(np.int) # 0~19
147176
label_pred_rgb = np.array(itemgetter(*SEMANTIC_NAMES[label_pred])(CLASS_COLOR))
148177
rgb = label_pred_rgb
149178

150179
elif (opt.task == 'offset_semantic_pred'):
151180
assert opt.data_split != 'train'
152-
semantic_file = os.path.join(opt.prediction_path, opt.data_split, 'semantic', opt.room_name + '.npy')
181+
semantic_file = os.path.join(opt.prediction_path, opt.data_split, 'semantic',
182+
opt.room_name + '.npy')
153183
assert os.path.isfile(semantic_file), 'No semantic result - {}.'.format(semantic_file)
154184
label_pred = np.load(semantic_file).astype(np.int) # 0~19
155185
label_pred_rgb = np.array(itemgetter(*SEMANTIC_NAMES[label_pred])(CLASS_COLOR))
156186
rgb = label_pred_rgb
157187

158-
offset_file = os.path.join(opt.prediction_path, opt.data_split, 'coords_offsets', opt.room_name + '.npy')
188+
offset_file = os.path.join(opt.prediction_path, opt.data_split, 'coords_offsets',
189+
opt.room_name + '.npy')
159190
assert os.path.isfile(offset_file), 'No offset result - {}.'.format(offset_file)
160191
offset_coords = np.load(offset_file)
161192
xyz = offset_coords[:, :3] + offset_coords[:, 3:]
@@ -164,16 +195,16 @@ def get_coords_color(opt):
164195
elif (opt.task == 'instance_gt'):
165196
assert opt.data_split != 'test'
166197
inst_label = inst_label.astype(np.int)
167-
print("Instance number: {}".format(inst_label.max() + 1))
198+
print('Instance number: {}'.format(inst_label.max() + 1))
168199
inst_label_rgb = np.zeros(rgb.shape)
169-
object_idx = (inst_label >= 0)
170200
ins_num = inst_label.max() + 1
171201
ins_pointnum = np.zeros(ins_num)
172202
for _ins_id in range(ins_num):
173203
ins_pointnum[_ins_id] = (inst_label == _ins_id).sum()
174204
sort_idx = np.argsort(ins_pointnum)[::-1]
175205
for _sort_id in range(ins_num):
176-
inst_label_rgb[inst_label == sort_idx[_sort_id] ] = COLOR_DETECTRON2[_sort_id % len(COLOR_DETECTRON2)]
206+
inst_label_rgb[inst_label == sort_idx[_sort_id]] = COLOR_DETECTRON2[
207+
_sort_id % len(COLOR_DETECTRON2)]
177208
rgb = inst_label_rgb
178209

179210
# same color order according to instance pointnum
@@ -201,17 +232,19 @@ def get_coords_color(opt):
201232
continue
202233
mask = np.loadtxt(mask_path).astype(np.int)
203234
if opt.dataset == 'scannet':
204-
print('{} {}: {} pointnum: {}'.format(i, masks[i], SEMANTIC_IDX2NAME[int(masks[i][1])], mask.sum()))
235+
print('{} {}: {} pointnum: {}'.format(i,
236+
masks[i], SEMANTIC_IDX2NAME[int(masks[i][1])],
237+
mask.sum()))
205238
else:
206239
print('{} {}: pointnum: {}'.format(i, masks[i], mask.sum()))
207240
ins_pointnum[i] = mask.sum()
208-
inst_label[mask == 1] = i
241+
inst_label[mask == 1] = i
209242
sort_idx = np.argsort(ins_pointnum)[::-1]
210243
for _sort_id in range(ins_num):
211-
inst_label_pred_rgb[inst_label == sort_idx[_sort_id] ] = COLOR_DETECTRON2[_sort_id % len(COLOR_DETECTRON2)]
244+
inst_label_pred_rgb[inst_label == sort_idx[_sort_id]] = COLOR_DETECTRON2[
245+
_sort_id % len(COLOR_DETECTRON2)]
212246
rgb = inst_label_pred_rgb
213247

214-
215248
if opt.data_split != 'test':
216249
sem_valid = (label != -100)
217250
xyz = xyz[sem_valid]
@@ -240,23 +273,33 @@ def write_ply(verts, colors, indices, output_file):
240273
file.write('property list uchar uint vertex_indices\n')
241274
file.write('end_header\n')
242275
for vert, color in zip(verts, colors):
243-
file.write('{:f} {:f} {:f} {:d} {:d} {:d}\n'.format(
244-
vert[0], vert[1], vert[2], int(color[0] * 255),
245-
int(color[1] * 255), int(color[2] * 255)))
276+
file.write('{:f} {:f} {:f} {:d} {:d} {:d}\n'.format(vert[0], vert[1], vert[2],
277+
int(color[0] * 255),
278+
int(color[1] * 255),
279+
int(color[2] * 255)))
246280
for ind in indices:
247281
file.write('3 {:d} {:d} {:d}\n'.format(ind[0], ind[1], ind[2]))
248282
file.close()
249283

250284

251285
if __name__ == '__main__':
252286
parser = argparse.ArgumentParser()
253-
parser.add_argument('--dataset', choices=['scannet', 's3dis'], help='dataset for visualization', default='scannet')
254-
parser.add_argument('--prediction_path', help='path to the prediction results',
255-
default='./exp/scannetv2/softgroup/softgroup_default_scannet/result')
256-
parser.add_argument('--data_split', help='train/val/test for scannet or Area_ID for s3dis', default='val')
287+
parser.add_argument(
288+
'--dataset',
289+
choices=['scannet', 's3dis'],
290+
help='dataset for visualization',
291+
default='scannet')
292+
parser.add_argument(
293+
'--prediction_path',
294+
help='path to the prediction results',
295+
default='./exp/scannetv2/softgroup/softgroup_default_scannet/result')
296+
parser.add_argument(
297+
'--data_split', help='train/val/test for scannet or Area_ID for s3dis', default='val')
257298
parser.add_argument('--room_name', help='room_name', default='scene0011_00')
258-
parser.add_argument('--task', help='input / semantic_gt / semantic_pred / offset_semantic_pred / instance_gt / instance_pred',
259-
default='instance_pred')
299+
parser.add_argument(
300+
'--task',
301+
help='input/semantic_gt/semantic_pred/offset_semantic_pred/instance_gt/instance_pred',
302+
default='instance_pred')
260303
parser.add_argument('--out', help='output point cloud file in FILE.ply format')
261304
opt = parser.parse_args()
262305

0 commit comments

Comments
 (0)