# Path: DeepFried2/datasets/images.py
# def imread(fname, dtype=_np.float32):
#     im = _cv2.imread(fname, flags=_cv2.IMREAD_UNCHANGED)
#     if im is None:
#         raise IOError("Couldn't open image file {}".format(fname))
#     # Convert BGR to RGB. OpenCV is weird like that.
#     if im.ndim == 3 and im.shape[-1] == 3:
#         im = im[:,:,::-1]
#     return im.astype(dtype)
# 
# def imresizecrop(img, size):
#     assert not isinstance(size, tuple), "For now, `size` needs to be a single integer, i.e. it's being squared."
# 
#     # First, resize the smallest side to `size`.
#     img = imresize(img, h=img.shape[0]*size//min(img.shape[:2]),
#                         w=img.shape[1]*size//min(img.shape[:2]))
# 
#     # Then, crop-out the central part of the largest side.
#     return img[(img.shape[0]-size)//2:img.shape[0]-(img.shape[0]-size)//2,
#                (img.shape[1]-size)//2:img.shape[1]-(img.shape[1]-size)//2,
#                :]
# 
# Path: examples/utils.py
# def printnow(fmt, *a, **kw):
#     _sys.stdout.write(fmt.format(*a, **kw))
#     _sys.stdout.flush()


import sys, os, json, argparse, collections
import numpy as np
import DeepFried2 as df
from DeepFried2.datasets.images import imread, imresizecrop
from examples.utils import printnow
    parser.add_argument('image', nargs='?')
    args = parser.parse_args()

    if args.model == 'vgg16':
        vgg = df.zoo.vgg16
    elif args.model == 'vgg19':
        vgg = df.zoo.vgg19

    printnow("Loading models...")
    modelFC, mean, classes = vgg.pretrained(fully_conv=True)
    model, mean, classes = vgg.pretrained(fully_conv=False)
    printnow("Done\n")

    # Switch to prediction mode for deterministic output.
    # NOTE: it could be interesting[1] to evaluate in training mode!
    # 1: http://mlg.eng.cam.ac.uk/yarin/blog_3d801aa532c1ce.html
    modelFC.evaluate()
    model.evaluate()

    # Potentially download example image from gist.
    args.image = args.image or df.zoo.download('https://gist.github.com/lucasb-eyer/237d03b9fcdb0fe03bce/raw/ILSVRC2012_val_00000151.JPEG')

    printnow("Loading and preparing image...")
    img = imread(args.image)

    # Subtracting the per-channel mean (stored in `mean`) as only pre-processing.
    if not args.raw:
        img -= mean

    # For the regular network, we need to resize and crop the image.

# Path: DeepFried2/datasets/images.py
# def imread(fname, dtype=_np.float32):
#     im = _cv2.imread(fname, flags=_cv2.IMREAD_UNCHANGED)
#     if im is None:
#         raise IOError("Couldn't open image file {}".format(fname))
#     # Convert BGR to RGB. OpenCV is weird like that.
#     if im.ndim == 3 and im.shape[-1] == 3:
#         im = im[:,:,::-1]
#     return im.astype(dtype)
# 
# def imresizecrop(img, size):
#     assert not isinstance(size, tuple), "For now, `size` needs to be a single integer, i.e. it's being squared."
# 
#     # First, resize the smallest side to `size`.
#     img = imresize(img, h=img.shape[0]*size//min(img.shape[:2]),
#                         w=img.shape[1]*size//min(img.shape[:2]))
# 
#     # Then, crop-out the central part of the largest side.
#     return img[(img.shape[0]-size)//2:img.shape[0]-(img.shape[0]-size)//2,
#                (img.shape[1]-size)//2:img.shape[1]-(img.shape[1]-size)//2,
#                :]
# 
# Path: examples/utils.py
# def printnow(fmt, *a, **kw):
#     _sys.stdout.write(fmt.format(*a, **kw))
#     _sys.stdout.flush()


# Path: examples/Pretrained/run_vgg.py
import sys, os, json, argparse, collections
import numpy as np
import DeepFried2 as df
from DeepFried2.datasets.images import imread, imresizecrop
from examples.utils import printnow

    parser.add_argument('image', nargs='?')
    args = parser.parse_args()

    if args.model == 'vgg16':
        vgg = df.zoo.vgg16
    elif args.model == 'vgg19':
        vgg = df.zoo.vgg19

    printnow("Loading models...")
    modelFC, mean, classes = vgg.pretrained(fully_conv=True)
    model, mean, classes = vgg.pretrained(fully_conv=False)
    printnow("Done\n")

    # Switch to prediction mode for deterministic output.
    # NOTE: it could be interesting[1] to evaluate in training mode!
    # 1: http://mlg.eng.cam.ac.uk/yarin/blog_3d801aa532c1ce.html
    modelFC.evaluate()
    model.evaluate()

    # Potentially download example image from gist.
    args.image = args.image or df.zoo.download('https://gist.github.com/lucasb-eyer/237d03b9fcdb0fe03bce/raw/ILSVRC2012_val_00000151.JPEG')

    printnow("Loading and preparing image...")
    img = imread(args.image)

    # Subtracting the per-channel mean (stored in `mean`) as only pre-processing.
    if not args.raw:
        img -= mean

    # For the regular network, we need to resize and crop the image.

    img224 = imresizecrop(img, 224)