Example #1
0
def predict_darkflow_model(cfg_obj, args):
    options = darkflow_parse_config(cfg_obj)

    # erase previous predictions
    imgdir_path = options['imgdir']
    out_dir = os.path.join(imgdir_path, 'out')
    for the_file in os.listdir(out_dir):
        file_path = os.path.join(out_dir, the_file)
        try:
            if os.path.isfile(file_path):
                os.unlink(file_path)
        except Exception as e:
            print(e)

    # load args
    if args.load is None:
        raise AssertionError('Please provide a ckpt number to load from.')
    options['load'] = args.load if args.load == 'best' else int(args.load)
    if args.threshold is not None:
        options['threshold'] = float(args.threshold)
    if args.gpu is not None:
        options['gpu'] = float(args.gpu)

    tfnet = TFNet(options)
    tfnet.predict()
    # save in json format too
    options['json'] = True
    tfnet = TFNet(options)
    assert tfnet.FLAGS.threshold >= 0
    tfnet.predict()
Example #2
0
def predict_darkflow_model(cfg_obj,args):
    options = darkflow_parse_config(cfg_obj)
    if args.load is None:
        raise AssertionError('Please provide a ckpt number to load from.')
    options['load'] = int(args.load)
    if args.threshold is not None:
        options['threshold'] = float(args.threshold)

    tfnet = TFNet(options)
    tfnet.predict()
    # save in json format too
    options['json'] = True
    tfnet = TFNet(options)
    tfnet.predict()
Example #3
0
def image_prediction():
    current_dir = os.getcwd() + "/app/cnnDashboard"
    FLAGS = {
        'imgdir': f'{current_dir}/sample_img/',
        'binary': f'{current_dir}/bin/',
        'config': f'{current_dir}/cfg/',
        'backup': './ckpt/',
        'threshold': -0.1,
        'model': f'{current_dir}/cfg/yolo.cfg',
        'load': f'{current_dir}/bin/yolo.weights',
        'gpu': 0.0,
        'batch': 16
    }
    tfnet = TFNet(FLAGS)
    tfnet.predict()
Example #4
0
def cliHandler(args):
    FLAGS = argHandler()
    FLAGS.setDefaults()
    FLAGS.parseArgs(args)

    # make sure all necessary dirs exist
    def _get_dir(dirs):
        for d in dirs:
            this = os.path.abspath(os.path.join(os.path.curdir, d))
            if not os.path.exists(this): os.makedirs(this)

    _get_dir([
        FLAGS.imgdir, FLAGS.binary, FLAGS.backup,
        os.path.join(FLAGS.imgdir, 'out'), FLAGS.summary
    ])

    # fix FLAGS.load to appropriate type
    try:
        FLAGS.load = int(FLAGS.load)
    except:
        pass

    tfnet = TFNet(FLAGS)

    if FLAGS.demo:
        tfnet.camera()
        exit('Demo stopped, exit.')

    if FLAGS.train:
        print('Enter training ...')
        tfnet.train()
        if not FLAGS.savepb:
            exit('Training finished, exit.')

    if FLAGS.savepb:
        print('Rebuild a constant version ...')
        tfnet.savepb()
        exit('Done')

    tfnet.predict()
options = {
    'model': 'config/tiny-yolo-dolphin.cfg',
    'load': -1,
    'threshold': 0.1,
    'labels': './labels_dolphin.txt',
    'json': False,
}

usage = """
Usage:
    ./test_yolo.py [options]

Options:
    --img=FILE      The image file to test.
    --imgdir=DIR    The image folder to test.
"""
if __name__ == '__main__':
    args = docopt(usage, help=True)

    if args['--img']:
        tfnet = TFNet(options)
        imgcv = cv2.imread(os.path.abspath(args['--img']))
        result = tfnet.return_predict(imgcv)
        pprint(result)

    if args['--imgdir']:
        options['imgdir'] = os.path.abspath(args['--imgdir'])
        tfnet = TFNet(options)
        tfnet.predict()
Example #6
0
from darkflow.net.build import TFNet
import cv2

options = {
    # 訓練済みモデル
    "load": "./data/weights/maeharin_yolo-obj_900.weights",
    # 訓練するときに使ったyoloのコンフィグファイル
    "model": "./data/cfg/maeharin_yolo-obj.cfg",
    # ラベル
    "labels": "./data/labels/obj.names",
    # 閾値
    "threshold": 0.3
}

tfnet = TFNet(options)

# 予測対象の画像
imgcv = cv2.imread("./data/sample-images/IMG_0411_frame_1.jpg")
result = tfnet.return_predict(imgcv)
print(result)
tfnet.predict(imgcv)