anamjafar6 commited on
Commit
4629cf6
·
verified ·
1 Parent(s): a944c81

Update utils/model_loader.py

Browse files
Files changed (1) hide show
  1. utils/model_loader.py +12 -1
utils/model_loader.py CHANGED
@@ -57,7 +57,18 @@ def load_pytorch_model(build_fn, weights_path, device):
57
  def load_keras_model(weights_path):
58
  if not os.path.exists(weights_path):
59
  raise FileNotFoundError(f"Model not found: {weights_path}")
60
- return tf.keras.models.load_model(weights_path, compile=False)
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  def load_all_models():
63
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
57
  def load_keras_model(weights_path):
58
  if not os.path.exists(weights_path):
59
  raise FileNotFoundError(f"Model not found: {weights_path}")
60
+ try:
61
+ return tf.keras.models.load_model(weights_path, compile=False)
62
+ except Exception:
63
+ import h5py
64
+ with h5py.File(weights_path, 'r') as f:
65
+ model_config = f.attrs.get('model_config')
66
+ model = tf.keras.models.model_from_json(
67
+ model_config,
68
+ custom_objects=None
69
+ )
70
+ model.load_weights(weights_path)
71
+ return model
72
 
73
  def load_all_models():
74
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")