<jupyter_start><jupyter_text>Production   Real time analysis using the Best selected model  1. Requirments :<jupyter_code>import sys
import warnings

if not sys.warnoptions:
    warnings.simplefilter("ignore")
import numpy as np    
from ipyfilechooser import FileChooser

from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.preprocessing.image import load_img
from keras.preprocessing import image

import pickle
report_dic={2:"Labradoodle",1:'Fried Chicken',3:"cookie"} # Image class labels<jupyter_output>Using TensorFlow backend.<jupyter_text>2. Functions :<jupyter_code>def read_image(IMAGE,PLOT=0):
    #img = Image.open(IMAGE).convert('L')#convert to grayscale
    #img = load_img(IMAGE, target_size=(128, 128,)).convert('L')
    img = load_img(IMAGE, target_size=(64, 64,3))

    #img= img_to_array(img)
    
    img = np.array(img)
    img=img/255
    # plot the image
    if PLOT ==1:
        image_plot(img)
    
    
    #return img
    img = img.flatten()
    img=img.reshape(1,len(img))
    print(img.shape)
    img=pca_component(img)
    
    model_predict(img)
    
def pca_component(data):
    components = pca.transform(data)
    return components

def model_predict(data):
    #print(report_dic[])
    print(model.predict(data))
    print("Detected Image : ",report_dic[model.predict(data)[0]])<jupyter_output><empty_output><jupyter_text>3. Loading the Models:  (Clf and PCA)<jupyter_code>#loading models:
tem= open('./model.pkl','rb')
model = pickle.load(tem)
tem= open('./pca.pkl','rb')
pca = pickle.load(tem)
tem.close()<jupyter_output><empty_output><jupyter_text>4. Loading the Image:<jupyter_code>fc = FileChooser('./')
display(fc)<jupyter_output><empty_output><jupyter_text>5. Image Classification using the classifier:<jupyter_code>read_image(fc.selected_path+"/"+fc.selected_filename,PLOT=0)<jupyter_output>(1, 12288)
[2]
Detected Image :  Labradoodle
{'fraction_non_alphanumeric': 0.12790697674418605, 'fraction_numerical': 0.017189079878665317, 'mean_word_length': 5.302547770700637, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '529272', 'license': 'MIT', 'n_tokens_mistral': 730, 'n_tokens_neox': 698, 'n_words': 131, 'path': 'Regression/Production_Model_v2.1.ipynb', 'repo_name': 'BabakEA/Image_classification', 'size': '1978'}