Skip to content

Commit

Permalink
change to PIL
Browse files Browse the repository at this point in the history
  • Loading branch information
JiahaoYao committed May 24, 2018
1 parent 574b911 commit 15e821b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions mmdnn/conversion/examples/imagenet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import argparse
import numpy as np
from six import text_type as _text_type
from tensorflow.contrib.keras.api.keras.preprocessing import image
from PIL import Image


class TestKit(object):
Expand Down Expand Up @@ -227,8 +227,9 @@ def __init__(self):

@staticmethod
def ZeroCenter(path, size, BGRTranspose=False):
img = image.load_img(path, target_size = (size, size))
x = image.img_to_array(img)
img = Image.open(path)
img = img.resize((size, size))
x = np.array(img, dtype=np.float64)

# Reference: 1) Keras image preprocess: https://github.com/keras-team/keras/blob/master/keras/applications/imagenet_utils.py
# 2) tensorflow github issue: https://github.com/tensorflow/models/issues/517
Expand All @@ -247,8 +248,9 @@ def ZeroCenter(path, size, BGRTranspose=False):

@staticmethod
def Normalize(path, size=224, scale=0.0392156863 ,mean=[-0.485, -0.456, -0.406], std=[0.229, 0.224, 0.225], BGRTranspose = False):
img = image.load_img(path, target_size=(size, size))
x = image.img_to_array(img)
img = Image.open(path)
img = img.resize((size, size))
x = np.array(img, dtype=np.float64)
x *= scale
for i in range(0, 3):
x[..., i] += mean[i]
Expand All @@ -260,8 +262,9 @@ def Normalize(path, size=224, scale=0.0392156863 ,mean=[-0.485, -0.456, -0.406],

@staticmethod
def Standard(path, size, BGRTranspose=False):
img = image.load_img(path, target_size = (size, size))
x = image.img_to_array(img)
img = Image.open(path)
img = img.resize((size, size))
x = np.array(img, dtype=np.float64)
x /= 255.0
x -= 0.5
x *= 2.0
Expand All @@ -272,8 +275,9 @@ def Standard(path, size, BGRTranspose=False):

@staticmethod
def Identity(path, size, BGRTranspose=False):
img = image.load_img(path, target_size = (size, size))
x = image.img_to_array(img)
img = Image.open(path)
img = img.resize((size, size))
x = np.array(img, dtype=np.float64)
if BGRTranspose == True:
x = x[..., ::-1]
return x
Expand Down

0 comments on commit 15e821b

Please sign in to comment.