Remove Experimental model

It didn't perform any better than the regular model
Removing batch normalisation significantly harmed training performance
This commit is contained in:
Piv
2021-03-25 21:28:07 +10:30
parent ab7da5acd4
commit 78d5aace15
2 changed files with 4 additions and 48 deletions

View File

@@ -5,9 +5,6 @@ import tensorflow_datasets as tfds
"""
Unofficial tensorflow keras implementation of FastDepth (mobilenet_nnconv5).
PyTorch (official) Fast Depth Implementation: https://github.com/dwofk/fast-depth
There's also an experimental version that does not use BatchNormalisation, as well as Parametric ReLU and bilinear
upsampling (mobilenet_nnconv5_no_bn)
"""
@@ -76,50 +73,6 @@ def mobilenet_nnconv5(weights=None, shape=(224, 224, 3)):
return keras.Model(inputs=input, outputs=x, name="fast_depth")
#### Experimental ####
def FDDepthwiseBlockNoBN(inputs, out_channels, block_id=1):
x = keras.layers.DepthwiseConv2D(5, padding='same')(inputs)
x = keras.layers.PReLU()(x)
x = keras.layers.Conv2D(out_channels, 1, padding='same')(x)
return keras.layers.PReLU(name='conv_pw_%d_relu' % block_id)(x)
def mobilenet_nnconv5_no_bn(weights=None, shape=(224, 224, 3)):
"""
Experimental version of the FastDepth model.
This version has the following changes:
- Bilinear upsampling is used rather than nearest neighbour
- No BatchNormalisation in decoder
- Parametric ReLU in Decoder rather than ReLU
:param weights: Pretrained weights for MobileNet, defaults to None
:param shape: Input shape of the image, defaults to (224, 224, 3)
:return: Experimental FastDepth keras Model
"""
input = keras.layers.Input(shape=shape)
mobilenet = keras.applications.MobileNet(input_tensor=input, include_top=False, weights=weights)
for layer in mobilenet.layers:
layer.trainable = True
# Fast depth decoder
x = FDDepthwiseBlockNoBN(mobilenet.output, 512, block_id=14)
x = keras.layers.UpSampling2D(interpolation='bilinear')(x)
x = FDDepthwiseBlockNoBN(x, 256, block_id=15)
x = keras.layers.UpSampling2D(interpolation='bilinear')(x)
x = keras.layers.Add()([x, mobilenet.get_layer(name="conv_pw_5_relu").output])
x = FDDepthwiseBlockNoBN(x, 128, block_id=16)
x = keras.layers.UpSampling2D(interpolation='bilinear')(x)
x = keras.layers.Add()([x, mobilenet.get_layer(name="conv_pw_3_relu").output])
x = FDDepthwiseBlockNoBN(x, 64, block_id=17)
x = keras.layers.UpSampling2D(interpolation='bilinear')(x)
x = keras.layers.Add()([x, mobilenet.get_layer(name="conv_pw_1_relu").output])
x = FDDepthwiseBlockNoBN(x, 32, block_id=18)
x = keras.layers.UpSampling2D(interpolation='bilinear')(x)
x = keras.layers.Conv2D(1, 1, padding='same')(x)
x = keras.layers.PReLU()(x)
return keras.Model(inputs=input, outputs=x, name="fast_depth_experimental")
def delta1_metric(y_true, y_pred):
maxRatio = tf.maximum(y_pred / y_true, y_true / y_pred)
return tf.nn.moments(tf.cast(maxRatio < tf.convert_to_tensor(1.25), tf.float32), axes=None)[0]

View File

@@ -2,7 +2,10 @@ import fast_depth_functional as fd
if __name__ == '__main__':
fd.fix_windows_gpu()
model = fd.mobilenet_nnconv5_no_bn(weights='imagenet')
model = fd.mobilenet_nnconv5(weights='imagenet')
fd.compile(model)
fd.train(existing_model=model, save_file='../fast-depth-experimental')
fd.evaluate(model)
# Save in Tensorflow SavedModel format
# tf.saved_model.save(model, 'fast_depth_nyu_v2_224_224_3_e1_saved_model')