In [1]:
import tensorflow as tf

# from models.alexnet import AlexNet
from models.vgg import VGG
# from models.vgg_slim import VGGslim
# from models.inception_v3 import InceptionV3

from helper.imageloader import load_image_paths_by_subfolder
from helper.retrainer import Retrainer

In [2]:
# Set Model
model_def = VGG
checkpoint_path = '../checkpoints/vgg'

# Input settings
image_dir = '../../datasets/CUHKPQ'
validation_ratio = 2 # 50%
skip_folder = ['yiwen']

# Learning/Network params
learning_rate = 0.005
num_epochs = 200
batch_size = 32
dropout_keep_prop = 1.0 # [0.5]
finetune_layers = ['fc6', 'fc7', 'fc8']

# Hardware usage
device = '/cpu:0'
memory_usage = 0.4

In [3]:
# Load image paths
image_paths = load_image_paths_by_subfolder(
    image_dir,
    validation_ratio,
    skip_folder,
    use_subfolder=True
)


Looking for images in HighQuality
=> Found 4524 images
  => Training: 2262
  => Validation 2262
  => Labeling them with: highquality (0)
Looking for images in LowQuality
=> Found 13166 images
  => Training: 6583
  => Validation 6583
  => Labeling them with: lowquality (1)

In [ ]:
# Retrain
trainer = Retrainer(model_def, image_paths)
trainer.run(
    finetune_layers=finetune_layers,
    epochs=num_epochs,
    learning_rate=learning_rate,
    batch_size=batch_size,
    keep_prob=dropout_keep_prop,
    memory_usage=memory_usage,
    device=device,
    show_misclassified=True,
    validate_on_each_epoch=True,
    save_ckpt_dir=checkpoint_path 
)


=> Will Restore:
  => <tf.Variable 'conv1_1/weights:0' shape=(3, 3, 3, 64) dtype=float32_ref>
  => <tf.Variable 'conv1_1/biases:0' shape=(64,) dtype=float32_ref>
  => <tf.Variable 'conv1_2/weights:0' shape=(3, 3, 64, 64) dtype=float32_ref>
  => <tf.Variable 'conv1_2/biases:0' shape=(64,) dtype=float32_ref>
  => <tf.Variable 'conv2_1/weights:0' shape=(3, 3, 64, 128) dtype=float32_ref>
  => <tf.Variable 'conv2_1/biases:0' shape=(128,) dtype=float32_ref>
  => <tf.Variable 'conv2_2/weights:0' shape=(3, 3, 128, 128) dtype=float32_ref>
  => <tf.Variable 'conv2_2/biases:0' shape=(128,) dtype=float32_ref>
  => <tf.Variable 'conv3_1/weights:0' shape=(3, 3, 128, 256) dtype=float32_ref>
  => <tf.Variable 'conv3_1/biases:0' shape=(256,) dtype=float32_ref>
  => <tf.Variable 'conv3_2/weights:0' shape=(3, 3, 256, 256) dtype=float32_ref>
  => <tf.Variable 'conv3_2/biases:0' shape=(256,) dtype=float32_ref>
  => <tf.Variable 'conv3_3/weights:0' shape=(3, 3, 256, 256) dtype=float32_ref>
  => <tf.Variable 'conv3_3/biases:0' shape=(256,) dtype=float32_ref>
  => <tf.Variable 'conv4_1/weights:0' shape=(3, 3, 256, 512) dtype=float32_ref>
  => <tf.Variable 'conv4_1/biases:0' shape=(512,) dtype=float32_ref>
  => <tf.Variable 'conv4_2/weights:0' shape=(3, 3, 512, 512) dtype=float32_ref>
  => <tf.Variable 'conv4_2/biases:0' shape=(512,) dtype=float32_ref>
  => <tf.Variable 'conv4_3/weights:0' shape=(3, 3, 512, 512) dtype=float32_ref>
  => <tf.Variable 'conv4_3/biases:0' shape=(512,) dtype=float32_ref>
  => <tf.Variable 'conv5_1/weights:0' shape=(3, 3, 512, 512) dtype=float32_ref>
  => <tf.Variable 'conv5_1/biases:0' shape=(512,) dtype=float32_ref>
  => <tf.Variable 'conv5_2/weights:0' shape=(3, 3, 512, 512) dtype=float32_ref>
  => <tf.Variable 'conv5_2/biases:0' shape=(512,) dtype=float32_ref>
  => <tf.Variable 'conv5_3/weights:0' shape=(3, 3, 512, 512) dtype=float32_ref>
  => <tf.Variable 'conv5_3/biases:0' shape=(512,) dtype=float32_ref>
=> Will train:
  => <tf.Variable 'fc6/weights:0' shape=(25088, 4096) dtype=float32_ref>
  => <tf.Variable 'fc6/biases:0' shape=(4096,) dtype=float32_ref>
  => <tf.Variable 'fc7/weights:0' shape=(4096, 4096) dtype=float32_ref>
  => <tf.Variable 'fc7/biases:0' shape=(4096,) dtype=float32_ref>
  => <tf.Variable 'fc8/weights:0' shape=(4096, 2) dtype=float32_ref>
  => <tf.Variable 'fc8/biases:0' shape=(2,) dtype=float32_ref>
=> Learningrate: 0.0050
=> Batchsize: 32
=> Dropout: 0.0000
##################################
=> Restoring weights from numpy file: ./weights/vgg16.npy
2017-10-05 00:45:39.343350 Epoch number: 1

In [ ]: