Commit cddca55f authored by Yuxin Wu's avatar Yuxin Wu

fix imports

parent 32b9a9e8
...@@ -16,7 +16,7 @@ from tensorpack.tfutils.symbolic_functions import * ...@@ -16,7 +16,7 @@ from tensorpack.tfutils.symbolic_functions import *
from tensorpack.tfutils.summary import * from tensorpack.tfutils.summary import *
""" """
Training code of ResNet on ImageNet. Work In Progress. Training code of Pre-Activation version of ResNet on ImageNet. Work In Progress.
Top1 error is now about 0.5% higher than fb.resnet.torch. Top1 error is now about 0.5% higher than fb.resnet.torch.
""" """
...@@ -136,31 +136,29 @@ def get_data(train_or_test): ...@@ -136,31 +136,29 @@ def get_data(train_or_test):
image_std = np.array([0.229, 0.224, 0.225], dtype='float32') image_std = np.array([0.229, 0.224, 0.225], dtype='float32')
if isTrain: if isTrain:
class Resize(imgaug.ImageAugmentor): def resize_func(img):
def __init__(self): # crop 8%~100% of the original image
self._init(locals()) # See `Going Deeper with Convolutions` by Google.
def _augment(self, img, _): h, w = img.shape[:2]
# fbaug area = h * w
h, w = img.shape[:2] for _ in range(10):
area = h * w targetArea = self.rng.uniform(0.08, 1.0) * area
for _ in range(10): aspectR = self.rng.uniform(0.75,1.333)
targetArea = self.rng.uniform(0.08, 1.0) * area ww = int(np.sqrt(targetArea * aspectR))
aspectR = self.rng.uniform(0.75,1.333) hh = int(np.sqrt(targetArea / aspectR))
ww = int(np.sqrt(targetArea * aspectR)) if self.rng.uniform() < 0.5:
hh = int(np.sqrt(targetArea / aspectR)) ww, hh = hh, ww
if self.rng.uniform() < 0.5: if hh <= h and ww <= w:
ww, hh = hh, ww x1 = 0 if w == ww else self.rng.randint(0, w - ww)
if hh <= h and ww <= w: y1 = 0 if h == hh else self.rng.randint(0, h - hh)
x1 = 0 if w == ww else self.rng.randint(0, w - ww) out = img[y1:y1+hh,x1:x1+ww]
y1 = 0 if h == hh else self.rng.randint(0, h - hh) out = cv2.resize(out, (224,224), interpolation=cv2.INTER_CUBIC)
out = img[y1:y1+hh,x1:x1+ww] return out
out = cv2.resize(out, (224,224), interpolation=cv2.INTER_CUBIC) out = cv2.resize(img, (224,224), interpolation=cv2.INTER_CUBIC)
return out return out
out = cv2.resize(img, (224,224), interpolation=cv2.INTER_CUBIC)
return out
augmentors = [ augmentors = [
Resize(), imgaug.MapImage(resize_func),
imgaug.RandomOrderAug( imgaug.RandomOrderAug(
[imgaug.Brightness(30, clip=False), [imgaug.Brightness(30, clip=False),
imgaug.Contrast((0.8, 1.2), clip=False), imgaug.Contrast((0.8, 1.2), clip=False),
......
...@@ -134,12 +134,12 @@ class Saturation(ImageAugmentor): ...@@ -134,12 +134,12 @@ class Saturation(ImageAugmentor):
class Lighting(ImageAugmentor): class Lighting(ImageAugmentor):
def __init__(self, std, eigval, eigvec): def __init__(self, std, eigval, eigvec):
""" Lighting noise. """ Lighting noise.
See `ImageNet Classification with Deep Convolutional Neural Networks - Alex` See `ImageNet Classification with Deep Convolutional Neural Networks - Alex`
The implementation follows 'fb.resnet.torch': https://github.com/facebook/fb.resnet.torch/blob/master/datasets/transforms.lua#L184 The implementation follows 'fb.resnet.torch': https://github.com/facebook/fb.resnet.torch/blob/master/datasets/transforms.lua#L184
:param eigvec: each column is one eigen vector :param eigvec: each column is one eigen vector
""" """
eigval = np.asarray(eigval) eigval = np.asarray(eigval)
eigvec = np.asarray(eigvec) eigvec = np.asarray(eigvec)
assert eigval.shape == (3,) assert eigval.shape == (3,)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# Author: Yuxin Wu <ppwwyyxxc@gmail.com> # Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import tensorflow as tf import tensorflow as tf
import re
__all__ = ['get_current_tower_context', 'TowerContext'] __all__ = ['get_current_tower_context', 'TowerContext']
......
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