코드 보기 (셀 34)
import os
import pandas as pd
import numpy as np
import fiftyone as fo
from huggingface_hub import snapshot_download
import seaborn as sns
import matplotlib.pyplot as plt
from IPython.display import display
# --- [단계 1] 데이터셋 안전 다운로드 및 FiftyOne 로드 ---
print("1. Hugging Face 허브에서 데이터셋 직접 안전 다운로드 중...")
local_dir = snapshot_download(
repo_id="Voxel51/TII-RATM-Drone-Racing",
repo_type="dataset"
)
print("2. FiftyOne 데이터셋 엔진에 로드 중...")
dataset = fo.Dataset.from_dir(
dataset_dir=local_dir,
dataset_type=fo.types.FiftyOneDataset
)
# --- [단계 2] 벤치마킹 데이터 파싱 및 df_report 테이블 생성 ---
print("3. 알고리즘 검증 데이터 테이블 생성 중...")
summary_data = []
for i, sample in enumerate(dataset):
track_type = getattr(sample, "track", "N/A")
flight_id = getattr(sample, "flight", f"Episode {i+1}")
distance = getattr(sample, "distance_m", 0.0)
duration = getattr(sample, "duration", 0.0)
mean_speed = getattr(sample, "mean_speed_ms", 0.0)
rmse_err = getattr(sample, "tracking_error_rmse_m", None)
max_err = getattr(sample, "tracking_error_max_m", None)
median_err = getattr(sample, "tracking_error_median_m", None)
final_err = getattr(sample, "tracking_error_final_m", None)
summary_data.append({
"비행 ID": flight_id,
"트랙 종류": track_type,
"비행 거리 (m)": round(distance, 2) if distance else "N/A",
"비행 시간 (초)": round(duration, 2) if duration else "N/A",
"평균 속도 (m/s)": round(mean_speed, 2) if mean_speed else "N/A",
"평균 오차 (RMSE, m)": round(rmse_err, 4) if rmse_err is not None else "N/A",
"최대 오차 (Max, m)": round(max_err, 4) if max_err is not None else "N/A",
"중앙값 오차 (m)": round(median_err, 4) if median_err is not None else "N/A",
"최종 지점 오차 (m)": round(final_err, 4) if final_err is not None else "N/A"
})
df_report = pd.DataFrame(summary_data)
print("📊 [SLAM / OpenVINS 알고리즘 정밀도 검증 결과 테이블]")
display(df_report)
# --- [단계 3] 그래프 시각화를 위한 데이터 전처리 ---
plot_df = df_report.copy()
target_cols = ["비행 거리 (m)", "비행 시간 (초)", "평균 속도 (m/s)", "평균 오차 (RMSE, m)", "최대 오차 (Max, m)"]
for col in target_cols:
plot_df[col] = pd.to_numeric(plot_df[col], errors='coerce')
plot_df = plot_df.dropna(subset=target_cols)
# --- [단계 4] 그래프 1: 변수별 산점도 및 회귀 추세선 (2x1 서브플롯) ---
print("\n4. 📈 [핵심 변수별 산점도 및 회귀 추세선 시각화 수립]")
fig, axes = plt.subplots(1, 2, figsize=(15, 6))
# 4-1. 비행 시간 vs 평균 오차
sns.regplot(
data=plot_df,
x="비행 시간 (초)",
y="평균 오차 (RMSE, m)",
ax=axes[0],
color="#d62728",
scatter_kws={'s': 80, 'alpha': 0.8},
line_kws={'color': 'black', 'linestyle': '--', 'linewidth': 2}
)
axes[0].set_title("Flight Duration vs Mean Error (RMSE)\n[Positive Correlation: 0.9096]", fontsize=12, pad=10)
axes[0].set_xlabel("Flight Duration (seconds)", fontsize=11)
axes[0].set_ylabel("Mean Error (meters)", fontsize=11)
axes[0].grid(True, linestyle=':', alpha=0.6)
# 4-2. 평균 속도 vs 평균 오차
sns.regplot(
data=plot_df,
x="평균 속도 (m/s)",
y="평균 오차 (RMSE, m)",
ax=axes[1],
color="#1f77b4",
scatter_kws={'s': 80, 'alpha': 0.8},
line_kws={'color': 'black', 'linestyle': '--', 'linewidth': 2}
)
axes[1].set_title("Mean Speed vs Mean Error (RMSE)\n[Negative Correlation: -0.5602]", fontsize=12, pad=10)
axes[1].set_xlabel("Mean Speed (m/s)", fontsize=11)
axes[1].set_ylabel("Mean Error (meters)", fontsize=11)
axes[1].grid(True, linestyle=':', alpha=0.6)
plt.suptitle("Statistical Variable Analysis for OpenVINS Accuracy", fontsize=15, y=1.02)
plt.tight_layout()
plt.show()
# --- [단계 5] 그래프 2: 상관계수 매트릭스 Heatmap 시각화 ---
print("\n5. 🌡️ [상관계수 매트릭스 Heatmap 시각화 수립]")
plt.figure(figsize=(8, 6))
corr_matrix = plot_df[target_cols].corr()
sns.heatmap(
corr_matrix,
annot=True,
cmap="coolwarm",
fmt=".4f",
linewidths=0.5,
vmin=-1, vmax=1,
cbar_kws={'label': 'Pearson Correlation Coefficient'}
)
plt.title("Correlation Matrix Heatmap of Flight Variables", fontsize=13, pad=15)
plt.tight_layout()
plt.show()