Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement one-padding and reduce number of SE blocks for QuickNet #136

Merged
merged 4 commits into from Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions larq_zoo/sota/quicknet.py
Expand Up @@ -69,6 +69,7 @@ def residual_fast_block(
kernel_size=3,
strides=strides,
padding="Same",
pad_values=1.0,
input_quantizer=self.input_quantizer,
kernel_quantizer=self.kernel_quantizer,
kernel_constraint=self.kernel_constraint,
Expand Down Expand Up @@ -97,7 +98,7 @@ def build(self) -> tf.keras.models.Model:
if self.include_top:
x = utils.global_pool(x)
x = tf.keras.layers.Dense(
self.num_classes, kernel_initializer="glorot_normal",
self.num_classes, kernel_initializer="glorot_normal"
)(x)
x = tf.keras.layers.Activation("softmax", dtype="float32")(x)

Expand All @@ -109,16 +110,16 @@ def build(self) -> tf.keras.models.Model:
if self.include_top:
weights_path = utils.download_pretrained_model(
model="quicknet",
version="v0.1.0",
version="v0.2.0",
file="quicknet_weights.h5",
file_hash="f52abb0ce984015889f8a8842944eed1bfad06897d745c7b58eb663b3457cd3c",
file_hash="6a765f120ba7b62a7740e842c4f462eb7ba3dd65eb46b4694c5bc8169618fae7",
)
else:
weights_path = utils.download_pretrained_model(
model="quicknet",
version="v0.1.0",
version="v0.2.0",
file="quicknet_weights_notop.h5",
file_hash="057391ea350ce0af33194db300d3d9d690c8fb5b11427bbaf37504af257e9dc5",
file_hash="5bf2fc450fb8cc322b33a16410bf88fed09d05c221550c2d5805a04985383ac2",
)
model.load_weights(weights_path)
elif self.weights is not None:
Expand Down
19 changes: 12 additions & 7 deletions larq_zoo/sota/quicknet_large.py
Expand Up @@ -71,12 +71,15 @@ def residual_block_SE(
else:
residual = x

y = squeeze_and_excite(x, strides=strides)
use_se = filters not in [64, 128]
if use_se:
koenhelwegen marked this conversation as resolved.
Show resolved Hide resolved
y = squeeze_and_excite(x, strides=strides)
x = lq.layers.QuantConv2D(
filters,
kernel_size=3,
strides=strides,
padding="Same",
pad_values=1.0,
input_quantizer=self.input_quantizer,
kernel_quantizer=self.kernel_quantizer,
kernel_constraint=self.kernel_constraint,
Expand All @@ -86,7 +89,9 @@ def residual_block_SE(
)(x)

x = tf.keras.layers.BatchNormalization(momentum=0.9, epsilon=1e-5)(x)
x = tf.multiply(x, y)

if use_se:
koenhelwegen marked this conversation as resolved.
Show resolved Hide resolved
x = tf.multiply(x, y)
koenhelwegen marked this conversation as resolved.
Show resolved Hide resolved

return tf.keras.layers.add([x, residual])

Expand All @@ -102,7 +107,7 @@ def build(self) -> tf.keras.models.Model:
if self.include_top:
x = utils.global_pool(x)
x = tf.keras.layers.Dense(
self.num_classes, kernel_initializer="glorot_normal",
self.num_classes, kernel_initializer="glorot_normal"
)(x)
x = tf.keras.layers.Activation("softmax", dtype="float32")(x)

Expand All @@ -116,16 +121,16 @@ def build(self) -> tf.keras.models.Model:
if self.include_top:
weights_path = utils.download_pretrained_model(
model="quicknet_large",
version="v0.1.0",
version="v0.2.0",
file="quicknet_large_weights.h5",
file_hash="1cd7ff411710023f902ec0152b860b4c3dea82e4bfe373b9310ca3598b3de640",
file_hash="2d9ebbf8ba0500552e4dd243c3e52fd8291f965ef6a0e1dbba13cc72bf6eee8b",
)
else:
weights_path = utils.download_pretrained_model(
model="quicknet_large",
version="v0.1.0",
version="v0.2.0",
file="quicknet_large_weights_notop.h5",
file_hash="628bde2a21cf9338e90da9b0179432d1dfa5f25a7d2aa6e51fc91d1630675c10",
file_hash="067655ef8a1a1e99ef1c71fa775c09aca44bdfad0b9b71538b4ec500c3beee4f",
)
model.load_weights(weights_path)
elif self.weights is not None:
Expand Down