Spaces:
Sleeping
Sleeping
Update model_tensorflow.py
Browse files- model_tensorflow.py +6 -13
model_tensorflow.py
CHANGED
|
@@ -1,13 +1,3 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Architecture summary:
|
| 3 |
-
Stem : Conv(32, 3×3) → BN → ReLU
|
| 4 |
-
Stage 1: SepConv(64) → BN → ReLU → MaxPool → Dropout
|
| 5 |
-
Stage 2: SepConv(128) → BN → ReLU → MaxPool → Dropout
|
| 6 |
-
Stage 3: SepConv(256) → BN → ReLU → MaxPool → Dropout
|
| 7 |
-
Head : GlobalAvgPool → Dense(128) → BN → ReLU → Dropout → Dense(6, softmax)
|
| 8 |
-
|
| 9 |
-
"""
|
| 10 |
-
|
| 11 |
import tensorflow as tf
|
| 12 |
from tensorflow.keras import layers, Model
|
| 13 |
|
|
@@ -24,14 +14,13 @@ def separable_block(x, filters: int, dropout_rate: float = 0.25):
|
|
| 24 |
x = layers.Activation("relu")(x)
|
| 25 |
|
| 26 |
x = layers.MaxPooling2D(pool_size=2)(x)
|
| 27 |
-
|
| 28 |
x = layers.SpatialDropout2D(rate=dropout_rate)(x)
|
| 29 |
|
| 30 |
return x
|
| 31 |
|
| 32 |
|
| 33 |
def build_sara_tf_model(input_shape=(150, 150, 3), num_classes: int = 6) -> Model:
|
| 34 |
-
|
| 35 |
inputs = tf.keras.Input(shape=input_shape, name="image_input")
|
| 36 |
|
| 37 |
x = layers.Conv2D(32, kernel_size=3, padding="same",
|
|
@@ -43,7 +32,6 @@ def build_sara_tf_model(input_shape=(150, 150, 3), num_classes: int = 6) -> Mode
|
|
| 43 |
x = separable_block(x, filters=128, dropout_rate=0.25)
|
| 44 |
x = separable_block(x, filters=256, dropout_rate=0.30)
|
| 45 |
|
| 46 |
-
|
| 47 |
x = layers.GlobalAveragePooling2D(name="gap")(x)
|
| 48 |
|
| 49 |
x = layers.Dense(128, use_bias=False, name="fc1")(x)
|
|
@@ -67,4 +55,9 @@ def build_sara_tf_model(input_shape=(150, 150, 3), num_classes: int = 6) -> Mode
|
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
model = build_sara_tf_model()
|
|
|
|
|
|
|
|
|
|
| 70 |
model.load_weights("ton_modele_weights.h5")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import tensorflow as tf
|
| 2 |
from tensorflow.keras import layers, Model
|
| 3 |
|
|
|
|
| 14 |
x = layers.Activation("relu")(x)
|
| 15 |
|
| 16 |
x = layers.MaxPooling2D(pool_size=2)(x)
|
|
|
|
| 17 |
x = layers.SpatialDropout2D(rate=dropout_rate)(x)
|
| 18 |
|
| 19 |
return x
|
| 20 |
|
| 21 |
|
| 22 |
def build_sara_tf_model(input_shape=(150, 150, 3), num_classes: int = 6) -> Model:
|
| 23 |
+
|
| 24 |
inputs = tf.keras.Input(shape=input_shape, name="image_input")
|
| 25 |
|
| 26 |
x = layers.Conv2D(32, kernel_size=3, padding="same",
|
|
|
|
| 32 |
x = separable_block(x, filters=128, dropout_rate=0.25)
|
| 33 |
x = separable_block(x, filters=256, dropout_rate=0.30)
|
| 34 |
|
|
|
|
| 35 |
x = layers.GlobalAveragePooling2D(name="gap")(x)
|
| 36 |
|
| 37 |
x = layers.Dense(128, use_bias=False, name="fc1")(x)
|
|
|
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
model = build_sara_tf_model()
|
| 58 |
+
|
| 59 |
+
model.build((None, 150, 150, 3))
|
| 60 |
+
|
| 61 |
model.load_weights("ton_modele_weights.h5")
|
| 62 |
+
|
| 63 |
+
print("Modèle chargé correctement !")
|