Minbz commited on
Commit
6779b5b
·
verified ·
1 Parent(s): 031e73e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -22,17 +22,22 @@ model_h5_path = "model.h5"
22
 
23
  # Load the saved TensorFlow Hub KerasLayer
24
  model_url = "https://tfhub.dev/sayakpaul/vit_b16_classification/1"
25
- vit_b16 = hub.KerasLayer(model_url, trainable=False)
 
 
 
 
 
 
 
26
 
27
  # Define the rest of the model architecture
28
- input_tensor = Input(shape=(224, 224, 3))
29
- x = vit_b16(preprocess_input(input_tensor))
30
- x = Dense(1024, activation='relu')(x)
31
- x = Dropout(0.5)(x)
32
- output_tensor = Dense(1, activation='sigmoid')(x)
33
-
34
- # Create the model
35
- model = Model(inputs=input_tensor, outputs=output_tensor)
36
 
37
  # Load the saved weights
38
  model.load_weights("model.h5")
 
22
 
23
  # Load the saved TensorFlow Hub KerasLayer
24
  model_url = "https://tfhub.dev/sayakpaul/vit_b16_classification/1"
25
+
26
+ # Load the ViT-B16 model pre-trained on ImageNet
27
+ try:
28
+ vit_b16 = hub.KerasLayer(model_url, trainable=False, input_shape=(224, 224, 3))
29
+ except Exception as e:
30
+ print(f"Failed to load the model from {model_url}. Error: {e}")
31
+ # Handle the error if the model cannot be loaded
32
+ raise
33
 
34
  # Define the rest of the model architecture
35
+ model = Sequential([
36
+ vit_b16,
37
+ Dense(1024, activation='relu'),
38
+ Dropout(0.5),
39
+ Dense(1, activation='sigmoid')
40
+ ])
 
 
41
 
42
  # Load the saved weights
43
  model.load_weights("model.h5")