Beispiel #1
0
    #check output dir
    logger.debug("Create new model dir...")
    if os.path.isdir(args.model_dir):
        new_name = args.model_dir+time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime())
        logger.debug("backup old model-dir in  %s" %new_name )
        os.rename(args.model_dir, new_name )
    os.makedirs(args.model_dir)

    #list classes
    list_classes = os.listdir(args.train_dir)
    logger.info("classes are : %s" %list_classes)

    #use descriptor
    desc=None
    if args.descriptor:
        desc = descriptors.get(args.descriptor)
        logger.info("using descriptor %s" %args.descriptor)
    else:
        logger.info("No descriptor is used")

    #create dataframe
    logger.info("create data frame for training...")
    train_df = pd.DataFrame(columns=["path", "desc", "class"])

    for cls in list_classes:
        list_images_paths = glob.glob(os.path.join(args.train_dir, cls, "*.*"))
        for id in xrange(len(list_images_paths)):

            descvect=None
            if desc is not None:
                descvect = desc(list_images_paths[id]).run()
Beispiel #2
0
        os.rename(args.output_dir, args.output_dir+time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime()))
    os.makedirs(args.output_dir)

    #model infos
    with open(os.path.join(args.model_dir,"model.json"),'r') as json_file:
        json_data = json.load(json_file)
    descriptor_name = json_data["descriptor"]
    model_name = json_data["model"]
    normalizer_name = json_data["normalizer"]
    model = joblib.load(os.path.join(args.model_dir, "model", "model.pkl"))

    logging.info("descriptor = %s, model = %s" %(descriptor_name, model_name))
    #use descriptor
    desc=None
    if descriptor_name is not None:
        desc = descriptors.get(descriptor_name)
        logger.info("using descriptor %s" %desc.__name__)

    #create dataframe
    test_df = pd.DataFrame(columns=["path", "desc", "class"])


    list_images_paths = glob.glob(os.path.join(args.test_dir,  "*.*"))
    for id in xrange(len(list_images_paths)):

        descvect=None
        if desc is not None:
            descvect = desc(list_images_paths[id]).run()

        test_df.loc[len(test_df)+1] = [list_images_paths[id], str(descvect) , -1]