Esempio n. 1
0
def main(_argv):
    if FLAGS.tiny:
        yolo = YoloV3Tiny(classes=FLAGS.num_classes)
    else:
        yolo = YoloV3(classes=FLAGS.num_classes)
    yolo.summary()
    logging.info('model created')
    load_darknet_weights(yolo, FLAGS.weights, FLAGS.tiny)
    logging.info('weights loaded')
    img = np.random.random((1, 320, 320, 3)).astype(np.float32)
    output = yolo(img)
    logging.info('sanity check passed')
    yolo.save_weights(FLAGS.output)
    logging.info('weights saved')
Esempio n. 2
0
def main(_argv):
    physical_devices = tf.config.experimental.list_physical_devices('GPU')
    if len(physical_devices) > 0:
        tf.config.experimental.set_memory_growth(physical_devices[0], True)

    yolo = yolo_v3(classes=FLAGS.num_classes)
    yolo.summary()
    logging.info('model created')

    load_darknet_weights(yolo, FLAGS.weights, FLAGS.tiny)
    logging.info('weights loaded')

    img = np.random.random((1, 320, 320, 3)).astype(np.float32)
    output = yolo(img)
    logging.info('sanity check passed')

    yolo.save_weights(FLAGS.output)
    logging.info('weights saved')
Esempio n. 3
0
def main(_argv):
    if tf.test.is_gpu_available():
        tf.config.gpu.set_per_process_memory_fraction(FLAGS.gpu_fraction)
    if FLAGS.tiny:
        yolo = YoloV3Tiny()
    else:
        yolo = YoloV3()
    yolo.summary()
    logging.info('model created')

    load_darknet_weights(yolo, FLAGS.weights, FLAGS.tiny)
    logging.info('weights loaded')

    img = np.random.random((1, 320, 320, 3)).astype(np.float32)
    output = yolo(img)
    logging.info('sanity check passed')

    yolo.save_weights(FLAGS.output)
    logging.info('weights saved')
Esempio n. 4
0
def main(_argv):
    config = tf.compat.v1.ConfigProto()
    config.gpu_options.allow_growth = True
    tf.compat.v1.InteractiveSession(config=config)
    if FLAGS.tiny:
        yolo = YoloV3Tiny(classes=FLAGS.num_classes)
    else:
        yolo = YoloV3(classes=FLAGS.num_classes)
    yolo.summary()
    logging.info('model created')

    load_darknet_weights(yolo, FLAGS.weights, FLAGS.tiny)
    logging.info('weights loaded')

    img = np.random.random((1, 320, 320, 3)).astype(np.float32)
    output = yolo(img)
    logging.info('sanity check passed')

    yolo.save_weights(FLAGS.output)
    logging.info('weights saved')
Esempio n. 5
0
def main(_argv):
    if tf_version == '2':
        physical_devices = tf.config.experimental.list_physical_devices('GPU')
        if len(physical_devices) > 0:
            tf.config.experimental.set_memory_growth(physical_devices[0], True)

    size = None if FLAGS.size == 0 else FLAGS.size

    if FLAGS.tiny:
        yolo = YoloV3Tiny(size=size, classes=FLAGS.num_classes, training=FLAGS.training)
    elif FLAGS.lite:
        yolo = YoloV2Lite(size=size, classes=FLAGS.num_classes, training=FLAGS.training)
    else:
        yolo = YoloV3(size=size, classes=FLAGS.num_classes, training=FLAGS.training)

    yolo.summary()
    logging.info('model created')

    if FLAGS.from_h5:
    	yolo.load_weights(FLAGS.weights)
    else:
        load_darknet_weights(yolo, FLAGS.weights, FLAGS.tiny, FLAGS.lite)
        logging.info('weights loaded')
        
    imsize = 320 if size is None else size
    img = np.random.random((1, imsize, imsize, 3)).astype(np.float32)
    output = yolo(img)
    logging.info('sanity check passed')

    predict(yolo)
    
    if FLAGS.output.endswith(('.h5', '.hdf5')):
        yolo.save(FLAGS.output)
        logging.info('keras model saved')
    else:
        yolo.save_weights(FLAGS.output)
        logging.info('weights saved')

    if tf_version == '1':       
        convert_to_pb(yolo)
        logging.info('pb saved')
def convert_weights_to_tf():
    if FLAGS.tiny:
        yolo = YoloV3Tiny(classes=80)
        load_darknet_weights(model=yolo, weights_file=FLAGS.tiny_weights, tiny=FLAGS.tiny)
        logging.info('weights loaded')

        img = np.random.random((1, 320, 320, 3)).astype(np.float32)
        output = yolo(img)
        logging.info('sanity check passed')

        yolo.save_weights('./checkpoints/yolov3-tiny.tf')
        logging.info('weights saved')
    else:
        yolo = YoloV3(classes=80)

        load_darknet_weights(model=yolo, weights_file=FLAGS.weights, tiny=FLAGS.tiny)
        logging.info('weights loaded')

        img = np.random.random((1, 320, 320, 3)).astype(np.float32)
        output = yolo(img)
        logging.info('sanity check passed')

        yolo.save_weights(FLAGS.output)
        logging.info('weights saved')
Esempio n. 7
0
import numpy as np
from yolov3_tf2.models_simple import YoloV3, YoloV3Tiny
from yolov3_tf2.utils import load_darknet_weights
import tensorflow as tf

tiny = False
num_classes = 80

path_weights = './data/yolov3.weights'
path_output = './checkpoints/yolov3.tf'
if tiny:
    path_weights = path_weights[:-8] + '-tiny.weights'
    path_output = path_output[:-3] + '-tiny.tf'

physical_devices = tf.config.experimental.list_physical_devices('GPU')
if len(physical_devices) > 0:
    tf.config.experimental.set_memory_growth(physical_devices[0], True)

if tiny:
    yolo = YoloV3Tiny(classes=num_classes)
else:
    yolo = YoloV3(classes=num_classes)
yolo.summary()

load_darknet_weights(yolo, path_weights, tiny)
img = np.random.random((1, 320, 320, 3)).astype(np.float32)
output = yolo(img)

yolo.save_weights(path_output)