-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
266 lines (244 loc) · 10.4 KB
/
__init__.py
File metadata and controls
266 lines (244 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# from args import base
# import argparse, os, logging, time
#
# from tasks import colmap_convert, gs_train, gs_metric
#
#
#
# if __name__ == '__main__':
# parser = argparse.ArgumentParser(description='Train parameter setting')
# parser.add_argument('-s', '--scene_root', default=r"", type=str, help='set scene root')
# parser.add_argument('-i', '--cuda_id', default="0", type=str, help='set cuda id.')
# parser.add_argument('-c', '--colmap_convert', action="store_true", help='execute colmap to get camera pose.')
# parser.add_argument('-g', '--gs_train', action="store_true", help='execute gs train to get gs model.')
# parser.add_argument('-m', '--gs_metric', action="store_true", help='execute gs metric')
#
# shell_args = parser.parse_args()
# logging.info(shell_args)
#
#
# """ colmap """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# if shell_args.colmap_convert:
# print("Runing ")
# from args.colmap import ColmapArgs
#
# args = ColmapArgs(shell_args)
# args.scene_root = shell_args.scene_root
# args.show_args()
#
# colmap_convert.colmap_convert(args)
#
#
# """ gaussian splatting """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# if shell_args.gs_train or shell_args.gs_metric:
# from args.scene import SceneArgs
# scene_args = SceneArgs(shell_args)
#
# # scene
# scene_args.task = ["gs", ]
# scene_args.show_args()
#
# from load.loadcolmap import Scene
# scene = Scene(scene_args)
#
# from args.gs import GSArgs
# gs_args = GSArgs(shell_args)
#
# from gs.metric import SSIM, PSNR, Lpips
# metrics = [Lpips(gs_args.DEVICE), SSIM, PSNR]
#
# """ train scene """
# if shell_args.gs_train:
# gs_args.mode = "train"
# gs_args.adaptive_scene(scene)
#
# # tf_logs
# if gs_args.tf:
# tf_log_dir = os.path.join(scene.output_path,
# time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()))
# gs_args.tf_log_dir = tf_log_dir
#
# from tensorboardX import SummaryWriter
# tf_logger = SummaryWriter(log_dir=tf_log_dir)
#
# try:
# from tensorboard import program
# tb = program.TensorBoard()
# tb.configure(argv=[None, '--logdir', tf_log_dir])
# url = tb.launch()
# except:
# print("Tensorboard strat faild!")
# else:
# tf_logger = None
#
# # model
# from gs import training
# model = training.GSTraining(gs_args, scene)
#
# gs_args.show_args()
# gs_train.train_gs(gs_args, model, scene, tf_logger, metrics)
#
# if gs_args.tf: tf_logger.close()
#
# """ eval scene """
# if shell_args.gs_metric:
# gs_args.mode = "test"
#
# max_iter = max(
# int(folder.split("_")[1]) for folder in
# os.listdir(os.path.join(shell_args.scene_root, "point_cloud"))
# if folder.startswith("iteration_"))
# scene.gs_ply = os.path.join(shell_args.scene_root, "point_cloud", 'iteration_{}'.format(str(max_iter)), # 30000
# "point_cloud.ply")
#
# # model
# from gs import gausplat
# model = gausplat.GauSplat(gs_args, scene)
#
# import os
# import time
#
# import torch
# import matplotlib.pyplot as plt
#
# def histplt(input, title="", bins=1000, ):
# print(input.min(), input.max())
# min, max = 0, 1 # torch.floor(
# x = torch.linspace(min, max, bins)
# print(x)
# hist_map = torch.histc(input, bins, min, max).cpu().numpy()
#
# # plot 1:
# plt.subplot(1, 2, 1, )
# plt.bar(x, hist_map, width=0.001)
#
# plt.title("Histogram", fontsize=8)
# plt.ticklabel_format(axis="y", style="sci", scilimits=(0, 0))
# plt.gca().ticklabel_format(useMathText=True)
# plt.grid()
#
# # plot 2:
# min, max = torch.floor(input.min()).int(), torch.ceil(input.max()).int()
# x = torch.linspace(min, max, bins)
# hist_map = torch.histc(input, bins, min, max).cpu().numpy()
# cum_hist_map = [hist_map[:i].sum() for i in range(bins)]
#
# plt.subplot(1, 2, 2)
# plt.bar(x, cum_hist_map, width=0.2)
#
# plt.title("Cumulative histogram", fontsize=8)
# plt.ticklabel_format(axis="y", style="sci", scilimits=(0, 0))
# plt.gca().ticklabel_format(useMathText=True)
# plt.grid()
#
# plt.suptitle(title)
#
# # plt.savefig("pth\hist\{}.jpg".format(time.time()), dpi=300)
# plt.show()
# plt.clf()
# plt.close()
#
#
# # from gs.unit.base import xyz_to_w
# #
# # deactive_w, active_w = xyz_to_w(model._xyz)
# #
# # histplt(active_w)
#
#
# histplt(torch.sigmoid(model._opacity))
#
#
import numpy as np
import matplotlib.pyplot as plt
import math
# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False
# 定义函数
def threshold_function(absorb_rate):
"""计算阈值:y = 1.0 + 3.0 * max(0, min(1, math.log(absorb_rate/0.1)))"""
# 应用max(0, min(1, log_value))
clamped_value = max(0., min(1., math.log(absorb_rate / 0.25, 4)))
# 计算最终阈值
return 1+7.0 * clamped_value
# 创建数据点
absorb_rates = np.linspace(0.001, 2.0, 1000) # 从0.001开始,避免log(0)
thresholds = [threshold_function(r) for r in absorb_rates]
# 创建图形
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))
# 第一个子图:完整范围
ax1.plot(absorb_rates, thresholds, 'b-', linewidth=3)
ax1.axvline(x=0.1, color='r', linestyle='--', linewidth=1.5, alpha=0.7, label='吸收率=0.1')
ax1.axhline(y=1.0, color='g', linestyle='--', linewidth=1.5, alpha=0.7, label='阈值=1.0')
ax1.axhline(y=4.0, color='orange', linestyle='--', linewidth=1.5, alpha=0.7, label='阈值=4.0')
# 标记关键点
critical_points = [0.1, 0.2718, 1.0] # 0.2718是e*0.1,log(0.2718/0.1)=1
for x in critical_points:
y = threshold_function(x)
ax1.plot(x, y, 'ro', markersize=8)
if x == 0.1:
ax1.annotate(f'({x:.2f}, {y:.1f})', xy=(x, y), xytext=(x + 0.05, y - 0.2))
elif x == 0.2718:
ax1.annotate(f'({x:.4f}, {y:.1f})', xy=(x, y), xytext=(x + 0.05, y + 0.1))
else:
ax1.annotate(f'({x:.1f}, {y:.1f})', xy=(x, y), xytext=(x - 0.2, y + 0.1))
ax1.set_xlabel('吸收率', fontsize=12)
ax1.set_ylabel('阈值', fontsize=12)
ax1.set_title('y = 1.0 + 3.0 * max(0, min(1, log(吸收率/0.1)))', fontsize=14)
ax1.set_xlim([0, 1.2])
ax1.set_ylim([0., 9])
ax1.grid(True, alpha=0.3)
ax1.legend()
# 第二个子图:重点区域放大
ax2.plot(absorb_rates, thresholds, 'b-', linewidth=3)
ax2.axvline(x=0.1, color='r', linestyle='--', linewidth=1.5, alpha=0.7, label='吸收率=0.1')
ax2.axhline(y=1.0, color='g', linestyle='--', linewidth=1.5, alpha=0.7, label='阈值=1.0')
ax2.axhline(y=4.0, color='orange', linestyle='--', linewidth=1.5, alpha=0.7, label='阈值=4.0')
# 标记关键点
for x in critical_points:
y = threshold_function(x)
ax2.plot(x, y, 'ro', markersize=8)
if x == 0.1:
ax2.annotate(f'({x:.2f}, {y:.1f})', xy=(x, y), xytext=(x + 0.02, y - 0.15))
elif x == 0.2718:
ax2.annotate(f'({x:.4f}, {y:.1f})', xy=(x, y), xytext=(x + 0.03, y + 0.1))
else:
ax2.annotate(f'({x:.1f}, {y:.1f})', xy=(x, y), xytext=(x - 0.15, y + 0.1))
# 添加区域说明
ax2.fill_between([0, 0.1], 0.5, 4.5, color='gray', alpha=0.1, label='log≤0区域')
ax2.fill_between([0.1, 0.2718], 0.5, 4.5, color='blue', alpha=0.1, label='0<log<1区域')
ax2.fill_between([0.2718, 1.5], 0.5, 4.5, color='red', alpha=0.1, label='log≥1区域')
ax2.set_xlabel('吸收率', fontsize=12)
ax2.set_ylabel('阈值', fontsize=12)
ax2.set_title('重点区域放大 (0-0.5)', fontsize=14)
ax2.set_xlim([0, 1.2])
ax2.set_ylim([0., 9])
ax2.grid(True, alpha=0.3)
ax2.legend(loc='upper left')
plt.tight_layout()
plt.show()
# 函数分析
print("函数分析:y = 1.0 + 3.0 * max(0, min(1, math.log(absorb_rate/0.1)))")
print("=" * 70)
# 计算关键点
print("\n关键点分析:")
print("1. 当 absorb_rate ≤ 0.1 时:log(absorb_rate/0.1) ≤ 0 → max(0, ...)=0 → y = 1.0")
print(f" 示例:absorb_rate=0.05 → y = {threshold_function(0.05):.2f}")
print(f" 示例:absorb_rate=0.10 → y = {threshold_function(0.10):.2f}")
print("\n2. 当 0.1 < absorb_rate < 0.1*e ≈ 0.2718 时:0 < log(absorb_rate/0.1) < 1")
print(f" 示例:absorb_rate=0.15 → log={math.log(0.15 / 0.1):.3f} → y = {threshold_function(0.15):.2f}")
print(f" 示例:absorb_rate=0.20 → log={math.log(0.20 / 0.1):.3f} → y = {threshold_function(0.20):.2f}")
print(f" 示例:absorb_rate=0.2718 → log={math.log(0.2718 / 0.1):.3f} → y = {threshold_function(0.2718):.2f}")
print("\n3. 当 absorb_rate ≥ 0.1*e ≈ 0.2718 时:log(absorb_rate/0.1) ≥ 1 → min(1, ...)=1 → y = 4.0")
print(f" 示例:absorb_rate=0.3 → y = {threshold_function(0.3):.2f}")
print(f" 示例:absorb_rate=0.5 → y = {threshold_function(0.5):.2f}")
print(f" 示例:absorb_rate=1.0 → y = {threshold_function(1.0):.2f}")
print(f" 示例:absorb_rate=2.0 → y = {threshold_function(2.0):.2f}")
print("\n" + "=" * 70)
print("函数特性总结:")
print("1. 阈值范围:1.0 到 4.0")
print("2. 当吸收率≤0.1时,阈值固定为1.0")
print("3. 当吸收率在0.1到0.2718之间时,阈值从1.0线性增长到4.0")
print("4. 当吸收率≥0.2718时,阈值固定为4.0")
print("5. 这是一个三阶段函数:恒定(1.0)-增长(1.0→4.0)-恒定(4.0)")