Commit d31ba459 authored by Yuxin Wu's avatar Yuxin Wu

misc fix

parent f482a5aa
......@@ -38,7 +38,7 @@ Accuracy:
With (W,A,G)=(1,2,4), 63% error.
Speed:
About 3.5 iteration/s on 4 Tesla M40. (Each epoch is set to 10000 iterations)
About 2.8 iteration/s on 1 TitanX. (Each epoch is set to 10000 iterations)
To Train:
./alexnet-dorefa.py --dorefa 1,2,6 --data PATH --gpu 0,1,2,3
......@@ -66,8 +66,7 @@ BITW = 1
BITA = 2
BITG = 6
TOTAL_BATCH_SIZE = 128
NUM_GPU = 4
BATCH_SIZE = TOTAL_BATCH_SIZE // NUM_GPU
BATCH_SIZE = 64
class Model(ModelDesc):
def _get_input_vars(self):
......@@ -301,6 +300,10 @@ if __name__ == '__main__':
run_image(Model(), ParamRestore(np.load(args.load, encoding='latin1').item()), args.run)
sys.exit()
assert args.gpu is not None, "Need to specify a list of gpu for training!"
NR_GPU = len(args.gpu.split(','))
BATCH_SIZE = TOTAL_BATCH_SIZE // NR_GPU
config = get_config()
if args.load:
config.session_init = SaverRestore(args.load)
......
......@@ -54,16 +54,16 @@ def build_GAN_losses(vecpos, vecneg):
tf.histogram_summary('sigmoid-neg', sigmneg)
d_loss_pos = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(
vecpos, tf.ones_like(vecpos)), name='d_loss_pos')
vecpos, tf.ones_like(vecpos)), name='d_CE_loss_pos')
d_loss_neg = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(
vecneg, tf.zeros_like(vecneg)), name='d_loss_neg')
vecneg, tf.zeros_like(vecneg)), name='d_CE_loss_neg')
d_pos_acc = tf.reduce_mean(tf.cast(sigmpos > 0.5, tf.float32), name='pos_acc')
d_neg_acc = tf.reduce_mean(tf.cast(sigmneg < 0.5, tf.float32), name='neg_acc')
g_loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(
vecneg, tf.ones_like(vecneg)), name='g_loss')
d_loss = tf.add(d_loss_pos, d_loss_neg, name='d_loss')
vecneg, tf.ones_like(vecneg)), name='g_CE_loss')
d_loss = tf.add(d_loss_pos, d_loss_neg, name='d_CE_loss')
add_moving_summary(d_loss_pos, d_loss_neg,
g_loss, d_loss,
d_pos_acc, d_neg_acc)
......
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# File: imagenet-resnet-short.py
# File: imagenet-resnet.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
import cv2
......@@ -233,7 +233,7 @@ if __name__ == '__main__':
assert args.gpu is not None, "Need to specify a list of gpu for training!"
NR_GPU = len(args.gpu.split(','))
BATCH_SIZE = TOTAL_BATCH_SIZE / NR_GPU
BATCH_SIZE = TOTAL_BATCH_SIZE // NR_GPU
logger.auto_set_dir()
config = get_config()
......
......@@ -40,7 +40,11 @@ def regularize_cost(regex, func, name=None):
@layer_register(log_shape=False)
def Dropout(x, keep_prob=0.5):
def Dropout(x, keep_prob=0.5, is_training=None):
"""
:param is_training: if None, will use the current context by default.
"""
if is_training is None:
is_training = get_current_tower_context().is_training
keep_prob = tf.constant(keep_prob if is_training else 1.0)
return tf.nn.dropout(x, keep_prob)
......
......@@ -5,6 +5,7 @@
import os, sys
from six.moves import urllib
import errno
from . import logger
__all__ = ['mkdir_p', 'download']
......@@ -17,7 +18,7 @@ def mkdir_p(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno != 17:
if e.errno != errno.EEXIST:
raise e
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment