Skip to content

Commit

Permalink
example with argscope
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwwyyxx committed Apr 13, 2016
1 parent fbb73a8 commit d6d0638
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions examples/cifar10_convnet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# File: cifar10_convnet.py
# File: argscope_test.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>

import tensorflow as tf
Expand All @@ -19,7 +19,7 @@
from tensorpack.dataflow import imgaug

"""
CIFAR10 90% validation accuracy after 70k step.
CIFAR10 90% validation accuracy after 40k step.
"""

BATCH_SIZE = 128
Expand All @@ -43,27 +43,24 @@ def _get_cost(self, input_vars, is_training):
tf.image_summary("train_image", image, 10)

image = image / 4.0 # just to make range smaller
l = Conv2D('conv1.1', image, out_channel=64, kernel_shape=3,
nl=BNReLU(is_training), use_bias=False)
l = Conv2D('conv1.2', l, out_channel=64, kernel_shape=3, nl=BNReLU(is_training), use_bias=False)
l = MaxPooling('pool1', l, 3, stride=2, padding='SAME')

l = Conv2D('conv2.1', l, out_channel=128, kernel_shape=3,
nl=BNReLU(is_training), use_bias=False)
l = Conv2D('conv2.2', l, out_channel=128, kernel_shape=3, nl=BNReLU(is_training), use_bias=False)
l = MaxPooling('pool2', l, 3, stride=2, padding='SAME')

l = Conv2D('conv3.1', l, out_channel=128, kernel_shape=3,
padding='VALID', nl=BNReLU(is_training), use_bias=False)
l = Conv2D('conv3.2', l, out_channel=128, kernel_shape=3, padding='VALID', nl=BNReLU(is_training), use_bias=False)
with argscope(Conv2D, nl=BNReLU(is_training), use_bias=False, kernel_shape=3):
l = Conv2D('conv1.1', image, out_channel=64)
l = Conv2D('conv1.2', l, out_channel=64)
l = MaxPooling('pool1', l, 3, stride=2, padding='SAME')

l = Conv2D('conv2.1', l, out_channel=128)
l = Conv2D('conv2.2', l, out_channel=128)
l = MaxPooling('pool2', l, 3, stride=2, padding='SAME')

l = Conv2D('conv3.1', l, out_channel=128, padding='VALID')
l = Conv2D('conv3.2', l, out_channel=128, padding='VALID')
l = FullyConnected('fc0', l, 1024 + 512,
b_init=tf.constant_initializer(0.1))
l = tf.nn.dropout(l, keep_prob)
l = FullyConnected('fc1', l, out_dim=512,
l = FullyConnected('fc1', l, 512,
b_init=tf.constant_initializer(0.1))
# fc will have activation summary by default. disable for the output layer
logits = FullyConnected('linear', l, out_dim=10, nl=tf.identity)
prob = tf.nn.softmax(logits, name='output')

y = one_hot(label, 10)
cost = tf.nn.softmax_cross_entropy_with_logits(logits, y)
Expand Down

0 comments on commit d6d0638

Please sign in to comment.