Spaces:
Sleeping
Sleeping
| """ | |
| export_scaler.py | |
| ================ | |
| Jalankan script ini di LINGKUNGAN yang sama dengan training notebook (misal: Google Colab) | |
| untuk men-export StandardScaler ke file scaler.pkl. | |
| CARA PAKAI: | |
| 1. Copy-paste cell ini ke Google Colab DI BAWAH cell Step 5.7 (setelah scaler.fit_transform) | |
| 2. Download file scaler.pkl yang dihasilkan | |
| 3. Upload ke folder backend/model/ (lokal) DAN ke Hugging Face Space di path model/scaler.pkl | |
| CODE UNTUK DIJALANKAN DI NOTEBOOK (tambahkan setelah Step 5.7): | |
| ================================================================ | |
| import pickle | |
| import os | |
| # scaler sudah di-fit di Step 5.7: scaler = StandardScaler(); scaler.fit_transform(train_fused) | |
| scaler_path = 'scaler.pkl' | |
| with open(scaler_path, 'wb') as f: | |
| pickle.dump(scaler, f) | |
| print(f"[OK] scaler.pkl berhasil disimpan!") | |
| print(f" Type : {type(scaler)}") | |
| print(f" Features: {scaler.n_features_in_} dimensi (harus 1797)") | |
| print(f" Mean[0] : {scaler.mean_[0]:.6f}") | |
| print(f" Std[0] : {scaler.scale_[0]:.6f}") | |
| print(f"\\nUnduh file scaler.pkl lalu upload ke:") | |
| print(f" - backend/model/scaler.pkl (lokal)") | |
| print(f" - Hugging Face Space > Files > model/scaler.pkl") | |
| ================================================================ | |
| File scaler.pkl ini WAJIB ada agar prediksi backend benar! | |
| Tanpanya, semua gambar akan diprediksi sebagai GLAUCOMA. | |
| """ | |
| # Script verifikasi (jalankan lokal setelah upload scaler.pkl): | |
| if __name__ == '__main__': | |
| import os, pickle, sys | |
| scaler_path = os.path.join(os.path.dirname(__file__), 'model', 'scaler.pkl') | |
| if not os.path.exists(scaler_path): | |
| print(f"[ERROR] scaler.pkl tidak ditemukan di: {scaler_path}") | |
| print("Jalankan kode export di notebook Google Colab terlebih dahulu!") | |
| sys.exit(1) | |
| with open(scaler_path, 'rb') as f: | |
| scaler = pickle.load(f) | |
| print(f"[OK] scaler.pkl berhasil dimuat!") | |
| print(f" Type : {type(scaler)}") | |
| print(f" Fitur : {scaler.n_features_in_} dimensi (harus 1797)") | |
| print(f" Mean[0:5] : {scaler.mean_[:5].round(4)}") | |
| print(f" Scale[0:5] : {scaler.scale_[:5].round(4)}") | |
| if scaler.n_features_in_ != 1797: | |
| print(f"\n[WARNING] Dimensi scaler ({scaler.n_features_in_}) tidak sesuai!") | |
| print("Pastikan scaler di-fit pada 1797 dimensi: [CNN(1792) + CDR(4) + QS(1)]") | |
| else: | |
| print("\n[READY] Backend siap menerima prediksi yang akurat!") | |