Ejemplo n.º 1
0
    def __init__(self, model_conf: ModelConfig, outputs):
        self.model_conf = model_conf

        self.max_label_num = self.model_conf.max_label_num
        if self.max_label_num == -1:
            exception(
                text=
                "The scene must set the maximum number of label (MaxLabelNum)",
                code=-998)
        self.category_num = self.model_conf.category_num

        flatten = tf.keras.layers.Flatten()(outputs)
        shape_list = flatten.get_shape().as_list()

        # print(shape_list[1], self.max_label_num)
        outputs = tf.keras.layers.Reshape(
            [self.max_label_num,
             int(shape_list[1] / self.max_label_num)])(flatten)
        self.outputs = tf.keras.layers.Dense(
            input_shape=outputs.shape,
            units=self.category_num,
        )(inputs=outputs)

        print("output to reshape ----------- ", self.outputs.shape)
        self.outputs = tf.reshape(self.outputs,
                                  [-1, self.max_label_num, self.category_num],
                                  name="predict")
Ejemplo n.º 2
0
def init():
    if not os.path.exists(MODEL_PATH):
        os.makedirs(MODEL_PATH)

    if not os.path.exists(SYS_CONFIG_PATH):
        exception(
            'Configuration File "{}" No Found. '
            'If it is used for the first time, please copy one from {} as {}'.
            format(SYS_CONFIG_NAME, SYS_CONFIG_DEMO_NAME,
                   SYS_CONFIG_NAME), ConfigException.SYS_CONFIG_PATH_NOT_EXIST)

    if not os.path.exists(MODEL_CONFIG_PATH):
        exception(
            'Configuration File "{}" No Found. '
            'If it is used for the first time, please copy one from {} as {}'.
            format(MODEL_CONFIG_NAME, MODEL_CONFIG_DEMO_NAME,
                   MODEL_CONFIG_NAME),
            ConfigException.MODEL_CONFIG_PATH_NOT_EXIST)

    if not isinstance(CHAR_EXCLUDE, list):
        exception("\"CharExclude\" should be a list")

    if GEN_CHAR_SET == ConfigException.CHAR_SET_NOT_EXIST:
        exception(
            "The character set type does not exist, there is no character set named {}"
            .format(CHAR_SET), ConfigException.CHAR_SET_NOT_EXIST)

    if _TEST_IMAGE_SIZE != _TRAIN_IMAGE_SIZE and not RESIZE:
        exception("The image size of the test set must match the training set")

    MODEL_FILE = checkpoint(TARGET_MODEL, MODEL_PATH)
    CHECKPOINT = 'model_checkpoint_path: {}\nall_model_checkpoint_paths: {}'.format(
        MODEL_FILE, MODEL_FILE)
    with open(SAVE_CHECKPOINT, 'w') as f:
        f.write(CHECKPOINT)
Ejemplo n.º 3
0
def fetch_file_list(path):
    file_list = os.listdir(path)
    if len(file_list) < 200:
        exception("Insufficient Sample!", ConfigException.INSUFFICIENT_SAMPLE)
    group = [os.path.join(path, image_file) for image_file in file_list]
    random.shuffle(group)
    return group
Ejemplo n.º 4
0
def char_set(_type):
    if isinstance(_type, list):
        return _type
    if isinstance(_type, str):
        return SIMPLE_CHAR_SET.get(_type) if _type in SIMPLE_CHAR_SET.keys(
        ) else ConfigException.CHAR_SET_NOT_EXIST
    exception(
        "Character set configuration error, customized character set should be list type",
        ConfigException.CHAR_SET_INCORRECT)
Ejemplo n.º 5
0
def init():
    if not os.path.exists(MODEL_PATH):
        os.makedirs(MODEL_PATH)

    if not os.path.exists(OUTPUT_PATH):
        os.makedirs(OUTPUT_PATH)

    if not os.path.exists(SYS_CONFIG_PATH):
        exception(
            'Configuration File "{}" No Found. '
            'If it is used for the first time, please copy one from {} as {}'.
            format(SYS_CONFIG_NAME, SYS_CONFIG_DEMO_NAME,
                   SYS_CONFIG_NAME), ConfigException.SYS_CONFIG_PATH_NOT_EXIST)

    if not os.path.exists(MODEL_CONFIG_PATH):
        exception(
            'Configuration File "{}" No Found. '
            'If it is used for the first time, please copy one from {} as {}'.
            format(MODEL_CONFIG_NAME, MODEL_CONFIG_DEMO_NAME,
                   MODEL_CONFIG_NAME),
            ConfigException.MODEL_CONFIG_PATH_NOT_EXIST)

    if not isinstance(CHAR_EXCLUDE, list):
        exception("\"CharExclude\" should be a list")

    if GEN_CHAR_SET == ConfigException.CHAR_SET_NOT_EXIST:
        exception(
            "The character set type does not exist, there is no character set named {}"
            .format(CHAR_SET), ConfigException.CHAR_SET_NOT_EXIST)

    model_file = _checkpoint(TARGET_MODEL, MODEL_PATH)
    checkpoint = 'model_checkpoint_path: {}\nall_model_checkpoint_paths: {}'.format(
        model_file, model_file)
    with open(SAVE_CHECKPOINT, 'w') as f:
        f.write(checkpoint)
Ejemplo n.º 6
0
    def check_field(self):

        if not os.path.exists(self.model_conf_path):
            exception(
                'Configuration File "{}" No Found. '
                'If it is used for the first time, please copy one according to model.template as {}'
                .format(MODEL_CONFIG_NAME, MODEL_CONFIG_NAME),
                ConfigException.MODEL_CONFIG_PATH_NOT_EXIST)
        if not os.path.exists(self.model_root_path):
            os.makedirs(self.model_root_path)

        model_file = ModelConfig.checkpoint(self.model_name,
                                            self.model_root_path)
        checkpoint = 'model_checkpoint_path: {}\nall_model_checkpoint_paths: {}'.format(
            model_file, model_file)
        with open(self.save_checkpoint, 'w') as f:
            f.write(checkpoint)
Ejemplo n.º 7
0
 def param_convert(source, param_map: dict, text, code, default=None):
     if source is None:
         return default
     if source not in param_map.keys():
         exception(text, code)
     return param_map[source]
Ejemplo n.º 8
0
PLATFORM = platform.system()

PATH_SPLIT = "\\" if PLATFORM == "Windows" else "/"

SYS_CONFIG_PATH = os.path.join(PROJECT_PATH, SYS_CONFIG_NAME)
MODEL_PATH = os.path.join(PROJECT_PATH, 'model')

if not os.path.exists(MODEL_PATH):
    os.makedirs(MODEL_PATH)

MODEL_CONFIG_PATH = os.path.join(PROJECT_PATH, MODEL_CONFIG_NAME)

if not os.path.exists(SYS_CONFIG_PATH):
    exception(
        'Configuration File "{}" No Found. '
        'If it is used for the first time, please copy one from {} as {}'.
        format(SYS_CONFIG_NAME, SYS_CONFIG_DEMO_NAME,
               SYS_CONFIG_NAME), ConfigException.SYS_CONFIG_PATH_NOT_EXIST)

if not os.path.exists(MODEL_CONFIG_PATH):
    exception(
        'Configuration File "{}" No Found. '
        'If it is used for the first time, please copy one from {} as {}'.
        format(MODEL_CONFIG_NAME, MODEL_CONFIG_DEMO_NAME,
               MODEL_CONFIG_NAME), ConfigException.MODEL_CONFIG_PATH_NOT_EXIST)

with open(SYS_CONFIG_PATH, 'r', encoding="utf-8") as sys_fp:
    sys_stream = sys_fp.read()
    cf_system = yaml.load(sys_stream)

with open(MODEL_CONFIG_PATH, 'r', encoding="utf-8") as sys_fp:
from flask import Flask, jsonify, request, make_response, send_from_directory
from util import util
import exception

util = util()
ex = exception.exception()

UPLOAD_FOLDER = 'uploaded'

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER


@app.route("/message", methods=["POST"])
def send_image():
    data = request.get_json()
    user = data["user"]
    reply = util.recieving_image_status(user=user)

    try:
        return jsonify(reply), 200

    except:
        return jsonify(ex.error(user=user, flag=exception.SERVER_ERROR)), 500


@app.route("/uploaded", methods=["POST"])
def upload_image():
    response = make_response()
    try:
        image = request.files['image']
Ejemplo n.º 10
0
import re
import sys

import yaml

from character import *
from exception import exception, ConfigException

MODEL_CONFIG_DEMO_PATH = 'model_demo.yaml'
MODEL_CONFIG_PATH = 'model.yaml'
MODEL_PATH = 'model'

if not os.path.exists(MODEL_CONFIG_PATH):
    exception(
        'Configuration File "{}" No Found. '
        'If it is used for the first time, please copy one from {} as {}'.
        format(MODEL_CONFIG_PATH, MODEL_CONFIG_DEMO_PATH,
               MODEL_CONFIG_PATH), ConfigException.MODEL_CONFIG_PATH_NOT_EXIST)

with open(MODEL_CONFIG_PATH, 'r', encoding="utf-8") as sys_fp:
    sys_stream = sys_fp.read()
    cf_model = yaml.load(sys_stream)


def char_set(_type):
    if isinstance(_type, list):
        return _type
    if isinstance(_type, str):
        return SIMPLE_CHAR_SET.get(_type) if _type in SIMPLE_CHAR_SET.keys(
        ) else ConfigException.CHAR_SET_NOT_EXIST
    exception(