Ejemplo n.º 1
0
def predict_target_by_paths(paths, augment_times=1):
    util.set_img_format()

    # sys.argv[0] = "--model=resnet50"
    predict.args = predict.parse_args()
    predict.model_module = util.get_model_class_instance()
    predict.model = predict.model_module.load()
    predict.classes_in_keras_format = util.get_classes_in_keras_format()

    for path in paths:
        predict.predict(dir=path, augment_times=augment_times)
Ejemplo n.º 2
0
def predict_target_by_dir(main_dir, augment_times=1):
    util.set_img_format()

    # sys.argv[0] = "--model=resnet50"
    predict.args = predict.parse_args()
    predict.model_module = util.get_model_class_instance()
    predict.model = predict.model_module.load()
    predict.classes_in_keras_format = util.get_classes_in_keras_format()

    dirs = glob.glob(main_dir + "*")

    global_summary = {"total": 0, "trues": 0, "falses": 0, "acc": 0}
    iter = 0
    for dir in dirs:
        stats = predict.predict(dir + os.sep, iter, augment_times, False)
        iter += 1
        global_summary["total"] += stats["summary"]["total"]
        global_summary["trues"] += stats["summary"]["trues"]
        global_summary["falses"] += stats["summary"]["falses"]
    global_summary["acc"] = float(
        global_summary["trues"]) / global_summary["total"]
    print("Global summary: {0}".format(global_summary))
Ejemplo n.º 3
0
for caffefile in glob.glob('*.caffemodel'):
    m = re.search(r'\S+(\d+)_iter_(\d+).caffemodel', caffefile)
    if m:
        fold = int(m.group(1))
        iter = int(m.group(2))
        if fold not in models or models[fold][1] < iter:
            models[fold] = (caffefile, iter)

#for each fold, collect the predictions
predictions = []  #a list of tuples
topresults = []
for fold in models:
    (caffefile, iter) = models[fold]
    testfile = prefix + 'test%d.types' % fold
    pargs = predict.parse_args([
        '-m', 'model.model', '-w', caffefile, '-d', args.data_root, '-i',
        testfile
    ])
    predictions += predict.predict(pargs)[0]
    topresults += calctop.evaluate_fold(testfile, caffefile, 'model.model',
                                        args.data_root)

#parse prediction lines
expaffs = []
predaffs = []
scores = []
labels = []
for p in predictions:
    score = p[0]
    predaff = p[1]
    vals = p[2].split()
    label = float(vals[0])
Ejemplo n.º 4
0
for caffefile in glob.glob('*.caffemodel'):
    m = re.search(r'\S+(\d+)_iter_(\d+).caffemodel',caffefile)
    if m:
        fold = int(m.group(1))
        iter = int(m.group(2))
        if fold not in models or models[fold][1] < iter:
            models[fold] = (caffefile,iter)
        

#for each fold, collect the predictions
predictions = [] #a list of tuples
topresults = []
for fold in models:
    (caffefile, iter) = models[fold]
    testfile = prefix+'test%d.types'%fold
    pargs = predict.parse_args(['-m','model.model','-w',caffefile,'-d',args.data_root,'-i',testfile])
    predictions += predict.predict(pargs)[0]
    topresults += calctop.evaluate_fold(testfile,caffefile,'model.model',args.data_root)

#parse prediction lines 
expaffs = []
predaffs = []
scores = []
labels = []
for p in predictions:
    score = p[0]
    predaff = p[1]
    vals = p[2].split()
    label = float(vals[0])
    aff = float(vals[1])
    scores.append(score)
Ejemplo n.º 5
0
def main():
    args = parse_args()
    print("cuda: %s" % CUDA)
    evaluate(predict(args.test_data, *load_model(args)))