CGVM-R2.6-Qwen3VL-8B-step600 / src /scripts /audit_sample332_identity.py
XiangnanW's picture
Upload CGVM R2.6 step-000600 checkpoint, R2.6 source bundle (cgvm-r26-src-v1.tar.gz), and 4-round audit report
4ad9219 verified
Raw History Blame Contribute Delete
3.31 kB
#!/usr/bin/env python3
"""按固定内容重叠阈值核对发布者候选与官方尚可解码前缀,不读取QA答案。"""
import hashlib
import json
from pathlib import Path
import sys
import time
import cv2
import numpy as np
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'scripts'))
from download_assets import atomic, sha
from fingerprint_media import fingerprint
def main():
cv2.setNumThreads(1)
official = ROOT / 'data/StreamingBench/videos/sample_332_real.mp4'
candidate = ROOT / 'data/media_recovery/_Dl3Yr1CjZY.format137.mp4'
if not candidate.exists():
candidate = ROOT / 'data/media_recovery/_Dl3Yr1CjZY.first128MiB.mp4'
caps = [cv2.VideoCapture(str(p), cv2.CAP_FFMPEG, [cv2.CAP_PROP_N_THREADS, 1]) for p in (official, candidate)]
fps = [cap.get(cv2.CAP_PROP_FPS) for cap in caps]
assert abs(fps[0]-fps[1]) < 1e-8
rows = []
started = time.perf_counter()
# 覆盖全部仍正常的四分钟前缀;相同native index,无时间偏移搜索或帧匹配择优。
for timestamp in list(range(0, 241, 5)) + [244]:
index = round(timestamp * fps[0])
images = []
for cap in caps:
cap.set(cv2.CAP_PROP_POS_FRAMES, index)
ok, image = cap.read()
if not ok:
raise RuntimeError(f'身份核查正常前缀解码失败:{timestamp}')
images.append(image)
fingerprints = [fingerprint(im) for im in images]
distances = {key: (int(fingerprints[0][key], 16)^int(fingerprints[1][key], 16)).bit_count()
for key in ('phash', 'dhash')}
rows.append(dict(timestamp=timestamp, native_index=index, phash_hamming=distances['phash'],
dhash_hamming=distances['dhash'], pixel_equal=np.array_equal(*images),
mean_absolute_RGB_error=float(np.abs(images[0].astype(np.float32)-images[1]).mean()),
official_RGB_sha256=fingerprints[0]['rgb_sha256'], candidate_RGB_sha256=fingerprints[1]['rgb_sha256'],
passed=distances['phash'] <= 6 and distances['dhash'] <= 8))
for cap in caps:
cap.release()
result = dict(passed=all(row['passed'] for row in rows), scope='publisher_identity_and_zero_offset_only; not_full_restored_decode_audit',
public_source='https://www.youtube.com/watch?v=_Dl3Yr1CjZY', official_sha256=sha(official),
candidate_path=str(candidate.relative_to(ROOT)), candidate_sha256=sha(candidate), native_fps=fps,
threshold_source='same_frozen_content_overlap_phash6_dhash8; no_QA_or_answers_read',
exact_first_I_frame_VCL_sha256='9fb5d4c280e26660877ebdc23dab084bf6bb0b349545e88116509540ad1396a5',
comparisons=rows, samples=len(rows), elapsed_CPU_wall_seconds=time.perf_counter()-started,
limitation='same_source_and_frame_timeline; current_publisher_P_frame_encoding_differs_from_published_benchmark')
atomic(ROOT / 'provenance/sample332_publisher_identity_audit.json', result)
print(json.dumps({key: value for key, value in result.items() if key != 'comparisons'}), flush=True)
if not result['passed']:
raise SystemExit(1)
if __name__ == '__main__':
main()