Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ from tensorflow.keras.applications import EfficientNetB0, ResNet50
|
|
| 4 |
from tensorflow.keras.applications.efficientnet import preprocess_input as efficient_preprocess
|
| 5 |
from tensorflow.keras.applications.resnet import preprocess_input as resnet_preprocess
|
| 6 |
from tensorflow.keras.preprocessing import image
|
| 7 |
-
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
|
| 8 |
from tensorflow.keras.models import Model
|
| 9 |
import numpy as np
|
| 10 |
|
|
@@ -13,10 +13,13 @@ IMG_SIZE = 224
|
|
| 13 |
MODEL_TYPE = "efficientnet" # or "resnet"
|
| 14 |
CLASS_NAMES = ['Cat', 'Dog', 'Panda'] # Replace with your actual classes
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
# β
Load Base Model
|
| 17 |
-
base_model = EfficientNetB0(weights='imagenet', include_top=False,
|
| 18 |
if MODEL_TYPE == "efficientnet" else \
|
| 19 |
-
ResNet50(weights='imagenet', include_top=False,
|
| 20 |
base_model.trainable = False
|
| 21 |
|
| 22 |
# β
Build Classifier
|
|
@@ -28,7 +31,7 @@ model = Model(inputs=base_model.input, outputs=output)
|
|
| 28 |
# β
Compile & Load Weights (Optional)
|
| 29 |
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
|
| 30 |
try:
|
| 31 |
-
model.load_weights("your_weights.h5")
|
| 32 |
except Exception as e:
|
| 33 |
print("β οΈ Could not load weights:", e)
|
| 34 |
|
|
|
|
| 4 |
from tensorflow.keras.applications.efficientnet import preprocess_input as efficient_preprocess
|
| 5 |
from tensorflow.keras.applications.resnet import preprocess_input as resnet_preprocess
|
| 6 |
from tensorflow.keras.preprocessing import image
|
| 7 |
+
from tensorflow.keras.layers import Input, Dense, GlobalAveragePooling2D
|
| 8 |
from tensorflow.keras.models import Model
|
| 9 |
import numpy as np
|
| 10 |
|
|
|
|
| 13 |
MODEL_TYPE = "efficientnet" # or "resnet"
|
| 14 |
CLASS_NAMES = ['Cat', 'Dog', 'Panda'] # Replace with your actual classes
|
| 15 |
|
| 16 |
+
# β
Input Tensor
|
| 17 |
+
input_tensor = Input(shape=(IMG_SIZE, IMG_SIZE, 3))
|
| 18 |
+
|
| 19 |
# β
Load Base Model
|
| 20 |
+
base_model = EfficientNetB0(weights='imagenet', include_top=False, input_tensor=input_tensor) \
|
| 21 |
if MODEL_TYPE == "efficientnet" else \
|
| 22 |
+
ResNet50(weights='imagenet', include_top=False, input_tensor=input_tensor)
|
| 23 |
base_model.trainable = False
|
| 24 |
|
| 25 |
# β
Build Classifier
|
|
|
|
| 31 |
# β
Compile & Load Weights (Optional)
|
| 32 |
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
|
| 33 |
try:
|
| 34 |
+
model.load_weights("your_weights.h5")
|
| 35 |
except Exception as e:
|
| 36 |
print("β οΈ Could not load weights:", e)
|
| 37 |
|