mirror of
https://github.com/sbrl/research-rainfallradar
synced 2024-11-22 09:13:01 +00:00
ddeeplabv3+: fix imports/pathing errors
This commit is contained in:
parent
fc43f145c2
commit
4d8ce792c9
1 changed files with 15 additions and 15 deletions
|
@ -88,23 +88,23 @@ def convolution_block(
|
|||
padding="same",
|
||||
use_bias=False,
|
||||
):
|
||||
x = layers.Conv2D(
|
||||
x = tf.keras.layers.Conv2D(
|
||||
num_filters,
|
||||
kernel_size=kernel_size,
|
||||
dilation_rate=dilation_rate,
|
||||
padding="same",
|
||||
use_bias=use_bias,
|
||||
kernel_initializer=keras.initializers.HeNormal(),
|
||||
kernel_initializer=tf.keras.initializers.HeNormal(),
|
||||
)(block_input)
|
||||
x = layers.BatchNormalization()(x)
|
||||
x = tf.keras.layers.BatchNormalization()(x)
|
||||
return tf.nn.relu(x)
|
||||
|
||||
|
||||
def DilatedSpatialPyramidPooling(dspp_input):
|
||||
dims = dspp_input.shape
|
||||
x = layers.AveragePooling2D(pool_size=(dims[-3], dims[-2]))(dspp_input)
|
||||
x = tf.keras.layers.AveragePooling2D(pool_size=(dims[-3], dims[-2]))(dspp_input)
|
||||
x = convolution_block(x, kernel_size=1, use_bias=True)
|
||||
out_pool = layers.UpSampling2D(
|
||||
out_pool = tf.keras.layers.UpSampling2D(
|
||||
size=(dims[-3] // x.shape[1], dims[-2] // x.shape[2]), interpolation="bilinear",
|
||||
)(x)
|
||||
|
||||
|
@ -113,35 +113,35 @@ def DilatedSpatialPyramidPooling(dspp_input):
|
|||
out_12 = convolution_block(dspp_input, kernel_size=3, dilation_rate=12)
|
||||
out_18 = convolution_block(dspp_input, kernel_size=3, dilation_rate=18)
|
||||
|
||||
x = layers.Concatenate(axis=-1)([out_pool, out_1, out_6, out_12, out_18])
|
||||
x = tf.keras.layers.Concatenate(axis=-1)([out_pool, out_1, out_6, out_12, out_18])
|
||||
output = convolution_block(x, kernel_size=1)
|
||||
return output
|
||||
|
||||
|
||||
def DeeplabV3Plus(image_size, num_classes):
|
||||
model_input = keras.Input(shape=(image_size, image_size, 3))
|
||||
resnet50 = keras.applications.ResNet50(
|
||||
model_input = tf.keras.Input(shape=(image_size, image_size, 3))
|
||||
resnet50 = tf.keras.applications.ResNet50(
|
||||
weights="imagenet", include_top=False, input_tensor=model_input
|
||||
)
|
||||
x = resnet50.get_layer("conv4_block6_2_relu").output
|
||||
x = DilatedSpatialPyramidPooling(x)
|
||||
|
||||
input_a = layers.UpSampling2D(
|
||||
input_a = tf.keras.layers.UpSampling2D(
|
||||
size=(image_size // 4 // x.shape[1], image_size // 4 // x.shape[2]),
|
||||
interpolation="bilinear",
|
||||
)(x)
|
||||
input_b = resnet50.get_layer("conv2_block3_2_relu").output
|
||||
input_b = convolution_block(input_b, num_filters=48, kernel_size=1)
|
||||
|
||||
x = layers.Concatenate(axis=-1)([input_a, input_b])
|
||||
x = tf.keras.layers.Concatenate(axis=-1)([input_a, input_b])
|
||||
x = convolution_block(x)
|
||||
x = convolution_block(x)
|
||||
x = layers.UpSampling2D(
|
||||
x = tf.keras.layers.UpSampling2D(
|
||||
size=(image_size // x.shape[1], image_size // x.shape[2]),
|
||||
interpolation="bilinear",
|
||||
)(x)
|
||||
model_output = layers.Conv2D(num_classes, kernel_size=(1, 1), padding="same")(x)
|
||||
return keras.Model(inputs=model_input, outputs=model_output)
|
||||
model_output = tf.keras.layers.Conv2D(num_classes, kernel_size=(1, 1), padding="same")(x)
|
||||
return tf.keras.Model(inputs=model_input, outputs=model_output)
|
||||
|
||||
|
||||
model = DeeplabV3Plus(image_size=IMAGE_SIZE, num_classes=NUM_CLASSES)
|
||||
|
@ -156,9 +156,9 @@ model.summary()
|
|||
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
# ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ████ ██████
|
||||
|
||||
loss = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
|
||||
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
|
||||
model.compile(
|
||||
optimizer=keras.optimizers.Adam(learning_rate=0.001),
|
||||
optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
|
||||
loss=loss,
|
||||
metrics=["accuracy"],
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue