def load_model_and_weights(args, mode, appcfg):
    log.debug("---------------------------->")
    from falcon.arch import Model as M

    archcfg = M.get_archcfg(appcfg)
    log.debug("archcfg: {}".format(archcfg))
    cmdcfg = archcfg

    # modelcfg_path = os.path.join(appcfg.PATHS.AI_MODEL_CFG_PATH, cmdcfg.model_info)
    modelcfg_path = apputil.get_abs_path(appcfg, cmdcfg, 'AI_MODEL_CFG_PATH')
    log.info("modelcfg_path: {}".format(modelcfg_path))
    modelcfg = M.get_modelcfg(modelcfg_path)

    log.info("modelcfg: {}".format(modelcfg))

    num_classes_model = apputil.get_num_classes(modelcfg)
    name = modelcfg.name

    cmdcfg.name = name
    cmdcfg.config.NAME = name
    cmdcfg.config.NUM_CLASSES = num_classes_model

    dnnmod = M.get_module(cmdcfg.dnnarch)
    load_model_and_weights = M.get_module_fn(dnnmod, "load_model_and_weights")
    model = load_model_and_weights(args, mode, cmdcfg, modelcfg, appcfg)

    status = True
    return status
def test_load_model(args, mode, appcfg):
    log.debug("---------------------------->")
    from falcon.arch import Model as M

    archcfg = M.get_archcfg(appcfg)
    log.debug("archcfg: {}".format(archcfg))
    cmdcfg = archcfg

    modelcfg_path = os.path.join(appcfg.PATHS.AI_MODEL_CFG_PATH,
                                 cmdcfg.model_info)
    log.info("modelcfg_path: {}".format(modelcfg_path))
    modelcfg = M.get_modelcfg(modelcfg_path)
    class_names = apputil.get_class_names(modelcfg)
    log.debug("class_names: {}".format(class_names))

    num_classes = len(class_names)
    name = modelcfg.name

    cmdcfg.name = name
    cmdcfg.config.NAME = name
    cmdcfg.config.NUM_CLASSES = num_classes

    dnnmod = M.get_module(cmdcfg.dnnarch)

    weights_path = apputil.get_abs_path(appcfg, modelcfg, 'AI_WEIGHTS_PATH')
    cmdcfg['weights_path'] = weights_path

    load_model_and_weights = M.get_module_fn(dnnmod, "load_model_and_weights")
    model = load_model_and_weights(mode, cmdcfg, appcfg)

    log.debug("model: {}".format(model))

    # modelsummary_path = os.path.join(appcfg.PATHS.AI_LOGS, name+"-summary.txt")
    # log.debug("modelsummary_path: {}".format(modelsummary_path))

    # # msummary = model.keras_model.summary()
    # # log.debug("model.keras_model.summary(): {}".format(msummary))
    # # with open(modelsummary_path, 'w') as fw:
    # #   fw.write(msummary)

    return
def load_and_display(args, mode, appcfg):
    log.debug("---------------------------->")
    from falcon.arch import Model as M
    from importlib import import_module

    datacfg = M.get_datacfg(appcfg)
    log.debug("datacfg: {}".format(datacfg))
    datamod = import_module(datacfg.dataclass)
    datamodcls = getattr(datamod, datacfg.dataclass)
    dataset = datamodcls(datacfg.name)

    subset = args.eval_on
    log.debug("subset: {}".format(subset))

    # total_img, total_annotation, total_classes = dataset.load_data(appcfg, datacfg, subset)
    # log.debug("total_img, total_annotation, total_classes: {}, {}, {}".format(total_img, total_annotation, total_classes))

    dataset, num_classes, num_images, class_names, total_stats, total_verify = M.get_dataset_instance(
        dataset, appcfg, datacfg, subset)

    # colors = viz.random_colors(len(class_names))
    # log.debug("len(colors), colors: {},{}".format(len(colors), colors))

    log.info("class_names: {}".format(class_names))
    log.info("len(class_names): {}".format(len(class_names)))
    log.info("num_classes: {}".format(num_classes))
    log.info("num_images: {}".format(num_images))

    name = dataset.name
    log.info("dataset.name: {}".format(name))
    # datacfg.name = name
    # datacfg.classes = class_names
    # datacfg.num_classes = num_classes

    # # log.debug("dataset: {}".format(vars(dataset)))
    # log.debug("len(dataset.image_info): {}".format(len(dataset.image_info)))
    # log.debug("len(dataset.image_ids): {}".format(len(dataset.image_ids)))

    return
Esempio n. 4
0
def setAndLoadModel(args):
    print("Inside setAndLoadModel::")
    print("args.ORG_NAME - args.ID - args.REL_NUM:: {} {} {}".format(
        args.ORG_NAME, args.ID, args.REL_NUM))

    # get model details
    modelDtls = Model.getDetails(args)

    if modelDtls is not None:
        app.config["MODEL_DTLS"] = modelDtls
        print("setAndLoadModel:Model Details: {}".format(
            app.config["MODEL_DTLS"]))

        args.DNNARCH = app.config["MODEL_DTLS"]["DNNARCH"]
        ## TBD Null check doe DNN_MODULE
        app.config["DNN_MODULE"] = Util.getDnnModule(
            args)  ## "pixel.faster_rcnn_end2end"
        # load model
        app.config["NET"] = Model.load(app.config["DNN_MODULE"],
                                       app.config["MODEL_DTLS"], args)
        return True

    return False
Esempio n. 5
0
def detect_in_image(filename):
    t1 = time.time()

    print('detect_in_image: filename: {}'.format(filename))

    all_rows_for_all_classes = Model.exec_prediction(
        app.config["DNN_MODULE"], app.config["MODEL_DTLS"], app.config["NET"],
        [filename], appcfg.UPLOAD_FOLDER, appcfg.LOG_FOLDER, appcfg)

    t2 = time.time()
    time_taken = (t2 - t1)
    print('Total time taken in detect_in_image: %f seconds' % (time_taken))

    return all_rows_for_all_classes
def inspect_annon(args, mode, appcfg):
    log.debug("---------------------------->")
    from falcon.arch import Model as M
    M.inspect_annon(args, mode, appcfg)
def viz_annon(args, mode, appcfg):
    log.debug("---------------------------->")
    from falcon.arch import Model as M
    M.viz_annon(args, mode, appcfg)
def train(args, mode, appcfg):
    log.debug("---------------------------->")
    from falcon.arch import Model as M
    M.train(args, mode, appcfg)