Spaces:
Sleeping
Sleeping
File size: 1,436 Bytes
a18e884 03f90fb 6b950bf a18e884 6b950bf a18e884 6b950bf a18e884 03f90fb 6b950bf aaf5be1 6b950bf a18e884 03f90fb 6b950bf a18e884 03f90fb 6b950bf a18e884 03f90fb 6b950bf a18e884 6b950bf a18e884 6b950bf a18e884 6b950bf a18e884 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import tensorflow as tf
from tensorflow.keras import layers, Model
def separable_block(x, filters, dropout_rate=0.25):
x = layers.SeparableConv2D(filters, 3, padding="same", use_bias=False)(x)
x = layers.BatchNormalization()(x)
x = layers.Activation("relu")(x)
x = layers.SeparableConv2D(filters, 3, padding="same", use_bias=False)(x)
x = layers.BatchNormalization()(x)
x = layers.Activation("relu")(x)
x = layers.MaxPooling2D()(x)
x = layers.SpatialDropout2D(dropout_rate)(x)
return x
# Model Definition
def build_sara_tf_model(input_shape=(150, 150, 3), num_classes=6):
inputs = tf.keras.Input(shape=input_shape)
x = layers.Conv2D(32, 3, padding="same", use_bias=False)(inputs)
x = layers.BatchNormalization()(x)
x = layers.Activation("relu")(x)
x = separable_block(x, 64, 0.25)
x = separable_block(x, 128, 0.25)
x = separable_block(x, 256, 0.30)
x = layers.GlobalAveragePooling2D()(x)
x = layers.Dense(128, use_bias=False)(x)
x = layers.BatchNormalization()(x)
x = layers.Activation("relu")(x)
x = layers.Dropout(0.5)(x)
outputs = layers.Dense(num_classes, activation="softmax")(x)
model = Model(inputs, outputs, name="SaraCNN_TF")
model.compile(
optimizer=tf.keras.optimizers.Adam(learning_rate=1e-3),
loss="categorical_crossentropy",
metrics=["accuracy"],
)
return model
|