653. BYU - Locating Bacterial Flagellar Motors 2025 | byu-locating-bacterial-flagellar-motors-2025
首先,我要感谢 @playwithme 分享了一个优秀的 Notebook。这是我在比赛期间参考的 Notebook。
Notebook 中使用的模型是预训练且公开的。
我的主要改进相当简单——我只修改了其中一个函数:
def perform_3d_nms(detections, iou_threshold):
"""
考虑空间距离和 Z 切片厚度的 3D NMS 类似聚类。
参数:
detections (list of dict): 检测信息列表 [{'z': int, 'y': int, 'x': int, 'confidence': float}, ...]
iou_threshold (float): 用于缩放 XY 空间距离限制的阈值 (例如 0.2)
返回:
list of dict: NMS 后的代表性检测结果 (可以包含多个簇)
"""
if not detections:
return []
# 聚类条件
xy_distance_threshold = 24 * iou_threshold # 24 是假设的框边长
z_distance_threshold = 10 # Z 切片方向的可接受范围
min_z_span = 3 # 视为有效簇的最小 Z 切片数量
# 按置信度降序排序检测结果
detections = sorted(detections, key=lambda d: d['confidence'], reverse=True)
final_detections = []
while detections:
base = detections.pop(0)
group = [base]
z_set = {base['z']}
rest = []
for d in detections:
dz = abs(d['z'] - base['z'])
dy = abs(d['y'] - base['y'])
dx = abs(d['x'] - base['x'])
if dz <= z_distance_threshold and dy <= xy_distance_threshold and dx <= xy_distance_threshold:
group.append(d)
z_set.add(d['z'])
else:
rest.append(d)
# 如果该组跨越了足够的 Z 切片,则取置信度最高的检测结果
if len(z_set) >= min_z_span:
best = max(group, key=lambda g: g['confidence'])
final_detections.append(best)
detections = rest
return final_detections
perform_3d_nms 函数执行检测点的 3D 聚类,模拟跨越 3D 空间的非极大值抑制 (NMS) 机制。它通过识别跨 Z 切片的空间接近点来过滤冗余检测,并仅保留每个有效簇中置信度最高的检测。
CONFIDENCE_THRESHOLD = 0.7 # 降低阈值以捕获更多潜在的马达
MAX_DETECTIONS_PER_TOMO = 1 # 跟踪每个断层扫描图的前 N 个检测结果
NMS_IOU_THRESHOLD = 0.7 # 3D 聚类的非极大值抑制阈值
CONCENTRATION = 1 # 仅处理 1/20 的切片以快速提交
SIZE = 1024