dev-yuje commited on
Commit
9efb88a
·
1 Parent(s): d42dc1b

fix: keras 3.12.1 + tf 2.21.0 복원 (로컬 환경 일치) + quantization_config 역직렬화 오류 3단계 fallback 추가

Browse files
Files changed (2) hide show
  1. app.py +18 -2
  2. requirements.txt +2 -1
app.py CHANGED
@@ -71,9 +71,25 @@ def load_all_models():
71
  self.load_error = f"파일이 너무 작음({fsize}B). LFS 포인터일 가능성 있음."
72
  return
73
 
74
- self.model = tf.keras.models.load_model(target_path, compile=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  self.load_error = "성공"
76
- print(f"✅ 모델 로드 성공 (파일 크기: {fsize:,}B)")
77
  except Exception as model_e:
78
  self.load_error = f"모델 로드 실패: {str(model_e)}\n{traceback.format_exc()}"
79
  except Exception as e:
 
71
  self.load_error = f"파일이 너무 작음({fsize}B). LFS 포인터일 가능성 있음."
72
  return
73
 
74
+ # [핵심 수정] quantization_config 역직렬화 오류 우회
75
+ # Keras 버전 차이로 Dense 레이어에 quantization_config 미지원 시 custom_objects로 패치
76
+ try:
77
+ self.model = tf.keras.models.load_model(target_path, compile=False)
78
+ print(f"✅ 모델 로드 성공 1차 시도 (파일 크기: {fsize:,}B)")
79
+ except Exception as e1:
80
+ print(f"⚠️ 1차 로드 실패, 2차 시도: {str(e1)[:200]}")
81
+ # 2차: safe_mode=False로 재시도 (Keras 3.x 옵션)
82
+ try:
83
+ self.model = tf.keras.models.load_model(target_path, compile=False, safe_mode=False)
84
+ print(f"✅ 모델 로드 성공 2차 시도 (safe_mode=False)")
85
+ except Exception as e2:
86
+ print(f"⚠️ 2차 로드 실패, 3차 시도: {str(e2)[:200]}")
87
+ # 3차: keras.saving으로 직접 로드
88
+ import keras
89
+ self.model = keras.saving.load_model(target_path, compile=False)
90
+ print(f"✅ 모델 로드 성공 3차 시도 (keras.saving)")
91
+
92
  self.load_error = "성공"
 
93
  except Exception as model_e:
94
  self.load_error = f"모델 로드 실패: {str(model_e)}\n{traceback.format_exc()}"
95
  except Exception as e:
requirements.txt CHANGED
@@ -1,7 +1,8 @@
1
  gradio
2
  pandas
3
  numpy<2.0.0
4
- tensorflow==2.15.0
 
5
  scikit-learn==1.6.1
6
  langchain>=0.3.0
7
  langchain-huggingface
 
1
  gradio
2
  pandas
3
  numpy<2.0.0
4
+ keras==3.12.1
5
+ tensorflow==2.21.0
6
  scikit-learn==1.6.1
7
  langchain>=0.3.0
8
  langchain-huggingface