MalikShehram commited on
Commit
a3071ef
·
verified ·
1 Parent(s): cf3bcb7

Update backend.py

Browse files
Files changed (1) hide show
  1. backend.py +35 -4
backend.py CHANGED
@@ -3,13 +3,44 @@ import numpy as np
3
  import joblib
4
  from PIL import Image
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  print("Loading AI Models... Please wait.")
7
- # Load all 5 components of your pipeline
8
- base_cnn = tf.keras.models.load_model('base_cnn.h5')
9
- encoder = tf.keras.models.load_model('encoder_model.h5') # Make sure you exported this!
 
10
  pca = joblib.load('pca_model.pkl')
11
  selector = joblib.load('selector_model.pkl')
12
- classifier = tf.keras.models.load_model('parkinsons_model.h5')
13
  print("All models loaded successfully!")
14
 
15
  def process_and_predict(input_img):
 
3
  import joblib
4
  from PIL import Image
5
 
6
+ # --- THE FIX: Custom Layer Wrappers to ignore version bugs ---
7
+ class SafeDense(tf.keras.layers.Dense):
8
+ def __init__(self, *args, **kwargs):
9
+ kwargs.pop('quantization_config', None)
10
+ super().__init__(*args, **kwargs)
11
+
12
+ class SafeDropout(tf.keras.layers.Dropout):
13
+ def __init__(self, *args, **kwargs):
14
+ kwargs.pop('quantization_config', None)
15
+ super().__init__(*args, **kwargs)
16
+
17
+ class SafeConv2D(tf.keras.layers.Conv2D):
18
+ def __init__(self, *args, **kwargs):
19
+ kwargs.pop('quantization_config', None)
20
+ super().__init__(*args, **kwargs)
21
+
22
+ class SafeMaxPooling2D(tf.keras.layers.MaxPooling2D):
23
+ def __init__(self, *args, **kwargs):
24
+ kwargs.pop('quantization_config', None)
25
+ super().__init__(*args, **kwargs)
26
+
27
+ # Group them up to feed into the loader
28
+ safe_objects = {
29
+ 'Dense': SafeDense,
30
+ 'Dropout': SafeDropout,
31
+ 'Conv2D': SafeConv2D,
32
+ 'MaxPooling2D': SafeMaxPooling2D
33
+ }
34
+ # -------------------------------------------------------------
35
+
36
  print("Loading AI Models... Please wait.")
37
+ # We use compile=False because we only need to predict, not train.
38
+ # This also saves memory and prevents further errors!
39
+ base_cnn = tf.keras.models.load_model('base_cnn.h5', custom_objects=safe_objects, compile=False)
40
+ encoder = tf.keras.models.load_model('encoder_model.h5', custom_objects=safe_objects, compile=False)
41
  pca = joblib.load('pca_model.pkl')
42
  selector = joblib.load('selector_model.pkl')
43
+ classifier = tf.keras.models.load_model('parkinsons_model.h5', custom_objects=safe_objects, compile=False)
44
  print("All models loaded successfully!")
45
 
46
  def process_and_predict(input_img):