2022-09-07 16:45:38 +00:00
|
|
|
import math
|
|
|
|
|
|
|
|
from loguru import logger
|
|
|
|
import tensorflow as tf
|
|
|
|
|
|
|
|
from .components.convnext_inverse import do_convnext_inverse
|
|
|
|
|
|
|
|
def model_rainfallwater_segmentation(metadata, feature_dim_in, shape_water_out, batch_size=64, summary_file=None):
|
2022-09-28 17:14:09 +00:00
|
|
|
out_water_width, out_water_height = shape_water_out
|
2022-09-15 18:54:50 +00:00
|
|
|
|
2022-09-07 16:45:38 +00:00
|
|
|
|
|
|
|
layer_input = tf.keras.layers.Input(
|
|
|
|
shape=(feature_dim_in)
|
|
|
|
)
|
|
|
|
|
|
|
|
# BEGIN
|
|
|
|
layer_next = tf.keras.layers.Dense(name="cns.stage.begin.dense")(layer_input)
|
|
|
|
layer_next = tf.keras.layers.LayerNormalisation(name="stage_begin.norm", epsilon=1e-6)(layer_next)
|
|
|
|
layer_next = tf.keras.layers.ReLU(name="stage_begin.relu")(layer_next)
|
|
|
|
|
|
|
|
layer_next = do_convnext_inverse(layer_next, arch_name="convnext_i_tiny")
|
|
|
|
|
2022-09-16 14:36:01 +00:00
|
|
|
# TODO: An attention layer here instead of a dense layer, with a skip connection perhaps?
|
2022-09-15 18:54:50 +00:00
|
|
|
layer_next = tf.keras.layers.Dense(32)(layer_next)
|
2022-09-28 17:07:26 +00:00
|
|
|
layer_next = tf.keras.layers.Conv2D(1, kernel_size=1, activation="softmax", padding="same")(layer_next)
|
2022-09-07 16:45:38 +00:00
|
|
|
|
|
|
|
model = tf.keras.Model(
|
|
|
|
inputs = layer_input,
|
|
|
|
outputs = layer_next
|
|
|
|
)
|
|
|
|
|
|
|
|
model.compile(
|
|
|
|
optimizer="Adam",
|
2022-09-28 17:08:31 +00:00
|
|
|
loss=tf.keras.losses.SparseCategoricalCrossentropy(),
|
2022-09-28 17:07:26 +00:00
|
|
|
metrics=["accuracy"]
|
2022-09-07 16:45:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return model
|