<jupyter_start><jupyter_text>Celebrity Identification  2018-12-20 Verison 4 *** Please see LICENSE for licensing information  Configurtationspath = 'localtest-celebrity'current_model = 'my_model-300epochs.h5'<jupyter_code># preparation linux commands

#!pip install keras
#!unzip localtest-celebrity-f-m.zip

#backup
#!tar cvfz localtest-celebrity.tgz localtest-celebrity/*
#!tar cvfz result.tgz result
spath = 'localtest-celebrity'

#current_model = 'my_model-100epochs.h5'
current_model = 'my_model-300epochs.h5'
import numpy as np
from keras import layers
from keras.layers import Input, Add, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D, AveragePooling2D, MaxPooling2D, GlobalMaxPooling2D
from keras.models import Model, load_model
from keras.preprocessing import image
from keras.utils import layer_utils
from keras.utils.data_utils import get_file
from keras.applications.imagenet_utils import preprocess_input
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
from keras.utils import plot_model
from keras.initializers import glorot_uniform
import scipy.misc
from matplotlib.pyplot import imshow
%matplotlib inline
from ci_utils import *

import keras.backend as K
K.set_image_data_format('channels_last')
K.set_learning_phase(1)

from scipy import ndimage
import gc<jupyter_output>/usr/local/lib/python3.5/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.<jupyter_text>Load ModelThe model is build on ..<jupyter_code>model = load_model(current_model)<jupyter_output><empty_output><jupyter_text>Run the inferrence codeThe inf..<jupyter_code>from keras.preprocessing import image
from IPython.display import display
from PIL import Image, ImageDraw, ImageFont

#clean up all output folders and recreate them - linux
os.system("rm -Rf result/0")
os.system("rm -Rf result/1")
os.system("rm -Rf result")
os.system("mkdir -p result/0")
os.system("mkdir -p result/1")

#clean up all output folders and recreate them - windows
#os.system("del /s /q result")
#os.system("rmdir /s /q result")
#os.system("mkdir result\\0")
#os.system("mkdir result\\1")

j = 0
total = 0
s = spath
n = dircount(s, ".jpg")
print(s + " has files " + str(n))

spath = s + "/"
k = 0
for name in os.listdir(spath):
    if name.endswith(".jpg"):
        img_path = spath + name
        print(img_path)

        img = image.load_img(img_path, target_size=(64, 64))
        x = image.img_to_array(img)
        x = np.expand_dims(x, axis=0)
        x /=255
        my_image = scipy.misc.imread(img_path)
        
        img = Image.open(img_path)
        
        r = model.predict(x)
        
        #decide if a output should goes to which folder, this is either or situation, no multi-class
        if r[0,1] < r[0,0]:
            class_str = "0"
        else:
            class_str = "1"
        result_path = "result/" + class_str + "/"

        #reduce accuracy of r for easy display
        r *= 100
        u = np.uint32(r)
        r = u
        
        outext = "[p(0), p(1)] = %\n" + str(r[0,0]) + ', ' + str(r[0,1])
        
        img.save(result_path + name)
        
        print(outext)        

        k += 1
        
        print(' ')<jupyter_output>localtest-celebrity has files 33
localtest-celebrity/1467626104339.jpg
{'fraction_non_alphanumeric': 0.10641316685584563, 'fraction_numerical': 0.02383654937570942, 'mean_word_length': 3.554263565891473, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '337509', 'license': 'Apache-2.0', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1205, 'n_words': 321, 'path': 'ci4.ipynb', 'repo_name': 'moseswmwong/Celebrity-Identification-Neural-Network', 'size': '3524'}