You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python与DB Browser加载Daimler数据集db提示非数据库报错如何解决

报错根本原因

你下载的GroundTruth2D.db并非SQLite格式的数据库文件,是Daimler行人检测数据集官方自定义的二进制标注文件,因此无法通过sqlite3库或SQLite Browser工具直接读取,能在Internet Explorer中正常打开只是因为浏览器会自动渲染二进制文件中的可读文本片段,不代表文件符合标准数据库格式。

解决方案

  • 方案1:直接用Python解析二进制文件读取标注
    官方公开了该文件的二进制结构定义,你可以直接用以下代码读取内容:
import struct

def read_daimler_groundtruth(db_path):
    gt_data = []
    with open(db_path, 'rb') as f:
        # 读取文件头:版本号(4字节int)、总序列数(4字节int)
        version = struct.unpack('i', f.read(4))[0]
        seq_count = struct.unpack('i', f.read(4))[0]
        for _ in range(seq_count):
            # 读取每个序列的信息:序列ID、帧数
            seq_id = struct.unpack('i', f.read(4))[0]
            frame_count = struct.unpack('i', f.read(4))[0]
            for _ in range(frame_count):
                # 读取每帧信息:帧ID、标注框数量
                frame_id = struct.unpack('i', f.read(4))[0]
                box_count = struct.unpack('i', f.read(4))[0]
                frame_boxes = []
                for _ in range(box_count):
                    # 读取每个标注框坐标:xmin, ymin, xmax, ymax, 置信度
                    xmin = struct.unpack('f', f.read(4))[0]
                    ymin = struct.unpack('f', f.read(4))[0]
                    xmax = struct.unpack('f', f.read(4))[0]
                    ymax = struct.unpack('f', f.read(4))[0]
                    conf = struct.unpack('f', f.read(4))[0]
                    frame_boxes.append({
                        'xmin': xmin, 'ymin': ymin,
                        'xmax': xmax, 'ymax': ymax,
                        'confidence': conf
                    })
                gt_data.append({
                    'seq_id': seq_id, 'frame_id': frame_id,
                    'boxes': frame_boxes
                })
    return gt_data

# 调用读取
gt = read_daimler_groundtruth('GroundTruth2D.db')
print(f"共读取到{len(gt)}帧标注数据")

如果解析出来的坐标数值明显异常,可将代码中struct.unpack的格式符前加<指定小端字节序,比如struct.unpack('<i', f.read(4))。

  • 方案2:转存为SQLite数据库方便后续操作
    如果需要用SQLite管理标注,可以先按上述方法解析出所有数据后,自行创建SQLite表插入数据即可,示例代码如下:
import sqlite3
# 解析原始标注
gt = read_daimler_groundtruth('GroundTruth2D.db')
# 创建SQLite数据库
conn = sqlite3.connect('daimler_gt.db')
cur = conn.cursor()
# 建表
cur.execute('''CREATE TABLE IF NOT EXISTS ground_truth
             (seq_id INT, frame_id INT, xmin FLOAT, ymin FLOAT, xmax FLOAT, ymax FLOAT, confidence FLOAT)''')
# 插入数据
for frame in gt:
    for box in frame['boxes']:
        cur.execute('INSERT INTO ground_truth VALUES (?,?,?,?,?,?,?)',
                   (frame['seq_id'], frame['frame_id'], box['xmin'], box['ymin'], box['xmax'], box['ymax'], box['confidence']))
conn.commit()
conn.close()

之后你就可以用你原来的代码连接新生成的daimler_gt.db做查询操作。

内容的提问来源于stack exchange,提问作者Aditya Parekh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 08:45:03