Skip to content

Commit

Permalink
update mobilenetv3
Browse files Browse the repository at this point in the history
  • Loading branch information
WZMIAOMIAO committed Feb 4, 2021
1 parent c5b99da commit 720be3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions tensorflow_classification/Test6_mobilenet/model_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _make_divisible(ch, divisor=8, min_ch=None):
return new_ch


def correct_pad(input_c, kernel_size):
def correct_pad(input_c: int, kernel_size: int):
"""Returns a tuple for zero-padding for 2D convolution with downsampling.
Arguments:
Expand All @@ -28,8 +28,8 @@ def correct_pad(input_c, kernel_size):
Returns:
A tuple.
"""
if isinstance(kernel_size, int):
kernel_size = (kernel_size, kernel_size)

kernel_size = (kernel_size, kernel_size)

adjust = (1 - input_c % 2, 1 - input_c % 2)
correct = (kernel_size[0] // 2, kernel_size[1] // 2)
Expand Down Expand Up @@ -84,15 +84,15 @@ def _se_block(inputs, filters, prefix, se_ratio=1 / 4.):


def _inverted_res_block(x,
input_c,
kernel_size,
exp_c,
out_c,
use_se,
activation,
stride,
block_id,
alpha=1.0):
input_c: int, # input channel
kernel_size: int, # kennel size
exp_c: int, # expanded channel
out_c: int, # out channel
use_se: bool, # whether using SE
activation: str, # RE or HS
stride: int,
block_id: int,
alpha: float = 1.0):

bn = partial(layers.BatchNormalization, epsilon=0.001, momentum=0.99)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def main():
data_root = "/data/flower_photos" # get data root path
data_root = "D:/My_code/pythonProject/deep-learning-for-image-processing-master/data_set/flower_data/flower_photos" # get data root path

if not os.path.exists("./save_weights"):
os.makedirs("./save_weights")
Expand Down Expand Up @@ -62,15 +62,15 @@ def train_step(train_images, train_labels):
optimizer.apply_gradients(zip(gradients, model.trainable_variables))

train_loss(loss)
train_accuracy(labels, output)
train_accuracy(train_labels, output)

@tf.function
def val_step(val_images, val_labels):
output = model(val_images, training=False)
loss = loss_object(val_labels, output)

val_loss(loss)
val_accuracy(labels, output)
val_accuracy(val_labels, output)

best_test_loss = float('inf')
for epoch in range(epochs):
Expand Down

0 comments on commit 720be3a

Please sign in to comment.