예제 #1
0
from flask import Flask, render_template, request
import warnings
with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=FutureWarning)
    import tensorflow as tf
    from model import load
    import re, base64, cv2
    import numpy as np
    from crop import borders

app = Flask(__name__)
model = load.init()


@app.route('/')
def index():
    return render_template("index.html")


def model_predict(img_path, model):
    img = cv2.imread(img_path, 0)
    _, img = cv2.threshold(img, 128, 255, cv2.THRESH_BINARY_INV)
    img = cv2.resize(img, (28, 28))
    img = cv2.GaussianBlur(img, (3, 3), -1)
    top, bottom, b = borders(img, 0)
    img = img[top:bottom]
    cv2.imwrite('abc.png', img)
    img = img.reshape(-1, 28, 28, 1) / 255
    preds = model.predict(img)
    return preds
예제 #2
0
import io
import tensorflow as tf
from tensorflow.python.keras import backend as K
tf.compat.v1.disable_v2_behavior()
sys.path.append(os.path.abspath("./model"))

app = Flask(__name__)

app.config['SECRET_KEY'] = 'the quick brown fox jumps over the lazy   dog'
app.config['CORS_HEADERS'] = "Content-Type"
cors = CORS(app, resources={r"/foo": {"origins": "127.0.0.1:8648"}})

K.clear_session()
global graph, model_mobile, sess, class_names

model_mobile, graph, sess = init()  # เรียกจาก load.py

# model_mobile = keras.models.load_model('model_moblienet_v2.h5', custom_objects={
#     'f1_m': f1_m, 'precision_m': precision_m, 'recall_m': recall_m})

graph = tf.compat.v1.get_default_graph()

class_names = [
    'kanom bua loi', 'kanom chan', 'kanom dok jok', 'kanom kai tao',
    'kanom krok', 'kanom phoi tong', 'kanom salim', 'kanom sangkhaya faktong',
    'kanom tong yib', 'kanom tong yod'
]


@app.route('/', methods=['POST', 'GET'])
@cross_origin(origin='*', headers=['Content-Type', 'Authorization'])
예제 #3
0
#for regular expressions, saves time dealing with string data
import re

#system level operations (like loading files)
import sys
#for reading operating system data
import os
#tell our app where our saved model is
sys.path.append(os.path.abspath("./model"))
from model.load import init
#initalize our flask app
app = Flask(__name__)
#global vars for easy reusability
global model, graph
#initialize these variables
model, graph = init()


#decoding an image from base64 into raw representation
def convertImage(imgData1):
    imgstr = re.search(r'base64,(.*)', imgData1).group(1)
    #print(imgstr)
    with open('output.png', 'wb') as output:
        output.write(imgstr.decode('base64'))


@app.route('/')
def index():
    #initModel()
    #render out pre-built HTML file right on the index page
    return render_template("index.html")
예제 #4
0
from tifffile import imwrite
import os
from os import listdir
from tqdm import tqdm
from os.path import isfile, join
from ae import load_ae, util, load_cae
import anomaly

# tell our app where our saved model is
sys.path.append(os.path.abspath("./model"))
from model import load, process

# global vars for easy reusability
global model, graph, ae, ae_graph, cae, cae_graph
# initialize these variables
model, graph = load.init()
ae, ae_graph = load_ae.init()
cae, cae_graph = load_cae.init()


def fill_dict(d):
    '''
		Auxiliary function to fill dictionary with key values from 2 to 9.

		:param dict d: Dictionary to be filled
		:return dict d: Filled dictionary

	'''
    for i in range(2, 9):
        if i not in d:
            d[i] = 0