Skip to content

Instantly share code, notes, and snippets.

Train acc Val acc Time per epoch
92.9% 96.0% 79 sec
Train acc Val acc Time per epoch
96.2% 95.3% 20 sec
Train acc Val acc Time per epoch
85.0% 65.0% 80 sec
Train acc Val acc Time per epoch
88.0% 72.0% 33 sec
Train acc Val acc Time per epoch
88.0% 67.3% 32 sec
model.load_weights(ckpt_dir)
for inputs in test_gen:
outputs = model(inputs, training=False)
break
#load model weights
model.load_state_dict(torch.load(ckpt_dir))
for inputs, targets in test_gen:
# use GPU if available
inputs = inputs.to(device)
inputs = inputs.float()
outputs = model(inputs)
break
learning_rate = 0.0001
#get mobilenet
model = torchvision.models.mobilenet_v2(pretrained=True)
# freeze the feature extraction convolutional layers
for param in model.parameters():
param.requires_grad = False
# define a classification layer
from torch.utils.tensorboard import SummaryWriter
# Setup tensorboard
file_writer = SummaryWriter(log_dir=log_dir + '/metrics')
best_val_acc = 0 # for model check pointing
# Epoch loop
for epoch in range(1, num_epoch + 1):
start_time = timer()
# Reset metrics
train_loss = 0.0
learning_rate = 0.0001
# get just the feature extraction layers of mobilenet
base_model = tf.keras.applications.MobileNetV2(
include_top=False, weights='imagenet', input_shape=(im_size, im_size, 3))
# freeze the feature extractor convolutional layers
base_model.trainable = False
# define a classification layer on top
global_average_layer = tf.keras.layers.GlobalAveragePooling2D()