Skip to content

Commit 119b966

Browse files
committed
dartmouth backup 202502024
1 parent 8caccce commit 119b966

39 files changed

+7285
-15064
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ venv/
1515
*.bin
1616
output
1717
version.py
18+
data/kitti/

crop_min_max.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from pathlib import Path
2+
import numpy as np
3+
import sys
4+
import json
5+
import os
6+
7+
# e.g.,
8+
# python print_min_max.py ./ '[[-70.4, -70.4, -4], [70.4, 70.4, 4]]'
9+
10+
print(sys.argv[2])
11+
# INPUT
12+
root_path = sys.argv[1]
13+
min_max_threshold = np.array(json.loads(sys.argv[2]))
14+
15+
16+
pathlist = Path(root_path).rglob('*.npy')
17+
min_max = [[np.inf]*3, [-np.inf]*3]
18+
valid = []
19+
total = 0
20+
21+
for path in pathlist:
22+
total += 1
23+
# because path is object not string
24+
arr = np.load(path)
25+
if arr.shape[0] == 0:
26+
print("shape,{}:{}".format(path, arr.shape))
27+
continue
28+
29+
tmp_min_max = [[np.inf]*3, [-np.inf]*3]
30+
for i in range(3):
31+
tmp_min_max[0][i] = min(arr[:,i])
32+
tmp_min_max[1][i] = max(arr[:,i])
33+
34+
tmp_min_max = np.array(tmp_min_max)
35+
36+
if np.any(tmp_min_max[0, :] < min_max_threshold[0, :]) or np.any(tmp_min_max[1, :] > min_max_threshold[1, :]):
37+
print("minmax,{}:{}".format(path, tmp_min_max))
38+
continue
39+
40+
for i in range(3):
41+
min_max[0][i] = min(min_max[0][i], tmp_min_max[0][i])
42+
min_max[1][i] = max(min_max[1][i], tmp_min_max[1][i])
43+
valid.append(path)
44+
45+
print("Valid {}/{}".format(len(valid), total))
46+
print(min_max)
47+
# print(valid)
48+
49+
for valid_one in valid:
50+
#path, file_name = os.path.split(valid_one)
51+
#new_output_folder = path.replace("points", "cropped_points")
52+
if not os.path.exists("cropped_points"):
53+
os.makedirs("cropped_points")
54+
new_output_path = os.path.join("cropped_points", valid_one)
55+
# print(valid_one)
56+
#if not os.path.exists(new_output_folder):
57+
# os.makedirs(new_output_folder)
58+
#output_file_name = os.path.join(new_output_folder, file_name)
59+
valid_arr = np.load(valid_one)
60+
np.save(new_output_path, valid_arr)
61+
print("saving ... {}".format(new_output_path))
62+
print("complete saving valid ones !!")

crop_splitter.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import os
2+
3+
train_ratio = 0.7
4+
val_ratio = 0.15
5+
test_ratio =0.15
6+
7+
8+
def empty_label_check(directory_path, verbose=False):
9+
"""
10+
Returns:
11+
empty_file_names=['009994.txt', '009199.txt',
12+
'010044.txt', '009226.txt', '010784.txt',
13+
'009228.txt', '010843.txt', '010443.txt',
14+
'003150.txt', '003104.txt', '008256.txt']
15+
"""
16+
# List to store files with no entries
17+
empty_files = []
18+
19+
# Iterate through all the files in the directory
20+
for filename in os.listdir(directory_path):
21+
if filename.endswith(".txt"): # Only check .txt files
22+
file_path = os.path.join(directory_path, filename)
23+
# print(file_path)
24+
with open(file_path, "r") as file:
25+
# Check if the file has no lines or only empty lines
26+
if not any(line.strip() for line in file):
27+
empty_files.append(filename)
28+
29+
# Print the list of empty files
30+
if empty_files:
31+
if verbose:
32+
print("Files with no entries: {}".format(empty_files))
33+
# for empty_file in empty_files:
34+
# print(empty_file)
35+
print(
36+
"Files with no entries counts: {} / total {}".format(
37+
len(empty_files), len(os.listdir(directory_path))
38+
)
39+
)
40+
else:
41+
print(
42+
"Files with no entries counts: {} / total {}".format(
43+
len(empty_files), len(os.listdir(directory_path))
44+
)
45+
)
46+
else:
47+
print("No empty files found.")
48+
49+
return empty_files
50+
51+
def get_only_numbers(data_list):
52+
number_list = [os.path.splitext(filename)[0] for filename in data_list]
53+
return number_list
54+
55+
if __name__ == "__main__":
56+
57+
total_valid_ones = os.listdir("points")
58+
total_num = len(total_valid_ones)
59+
train_end = int(total_num * train_ratio)
60+
val_end = train_end + int(total_num * val_ratio)
61+
62+
# split
63+
train_list = total_valid_ones[:train_end]
64+
valid_list = total_valid_ones[train_end:val_end]
65+
test_list = total_valid_ones[val_end:]
66+
67+
train_set_numbers = get_only_numbers(train_list)
68+
valid_set_numbers = get_only_numbers(valid_list)
69+
test_set_numbers = get_only_numbers(test_list)
70+
71+
train_set = set(train_set_numbers)
72+
val_set = set(valid_set_numbers)
73+
test_set = set(test_set_numbers)
74+
75+
# ----------------------------------
76+
label_path = "labels"
77+
# labels = os.listdir(label_path)
78+
empty_files = empty_label_check(label_path)
79+
empty_file_numbers = []
80+
if empty_files:
81+
# only extract 6 digit numbers
82+
empty_file_numbers = [os.path.splitext(filename)[0] for filename in empty_files]
83+
print("empty {}".format(len(empty_file_numbers)))
84+
# ----------------------------------
85+
86+
if len(empty_file_numbers):
87+
train_set = train_set - set(empty_file_numbers)
88+
val_set = val_set - set(empty_file_numbers)
89+
test_set = test_set - set(empty_file_numbers)
90+
91+
# make it back to list
92+
train_set_numbers = list(train_set)
93+
valid_set_numbers = list(val_set)
94+
test_set_numbers = list(test_set)
95+
96+
print("train {}".format(len(train_set_numbers)))
97+
print("val {}".format(len(valid_set_numbers)))
98+
print("tes {}".format(len(test_set_numbers)))
99+
100+
output_dir = "ImageSetsCrop"
101+
# Save to text files
102+
os.makedirs(output_dir, exist_ok=True)
103+
with open(os.path.join(output_dir, "train.txt"), "w") as train_file:
104+
train_file.write("\n".join(train_set_numbers) + "\n")
105+
with open(os.path.join(output_dir, "val.txt"), "w") as val_file:
106+
val_file.write("\n".join(valid_set_numbers) + "\n")
107+
with open(os.path.join(output_dir, "test.txt"), "w") as test_file:
108+
test_file.write("\n".join(test_set_numbers) + "\n")
109+
110+
print("new ImageSets as per Crop genrated...")

0 commit comments

Comments
 (0)