Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Define the rest of the model architecture
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 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")
|