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)
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))
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])
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)
def main(): args = parse_args() print("cuda: %s" % CUDA) evaluate(predict(args.test_data, *load_model(args)))