示例#1
0
def main(argv=None):
    if FLAGS.tiny:
        model = yolo_v3_tiny.yolo_v3_tiny
    else:
        model = yolo_v3.yolo_v3

    config = configparser.ConfigParser(strict=False)
    config.read(FLAGS.model_config)

    classes = load_coco_names(FLAGS.class_names)
    # placeholder for detector inputs
    inputs = tf.placeholder(tf.float32, [
        None,
        config.getint("net", "height"),
        config.getint("net", "width"), 3
    ], "inputs")

    with tf.variable_scope('detector'):
        detections = model(inputs, len(classes), data_format=FLAGS.data_format)
        load_ops = load_weights(tf.global_variables(scope='detector'),
                                FLAGS.weights_file)
    # Sets the output nodes in the current session
    boxes = detections_boxes(detections)

    with tf.Session() as sess:
        sess.run(load_ops)
        freeze_graph(sess, FLAGS.output_graph)
def main(argv=None):
    if FLAGS.tiny:
        model = yolov3_tiny_3l.yolo_v3_tiny
    elif FLAGS.dense:
        model = dense_yolov3_v1.dense_yolo_v3
    else:
        model = yolo_v3.yolo_v3

    classes = load_names(FLAGS.class_names)

    # placeholder for detector inputs
    inputs = tf.placeholder(tf.float32, [None, FLAGS.size, FLAGS.size, 3],
                            "inputs")

    with tf.variable_scope('detector'):
        detections = model(inputs, len(classes), data_format=FLAGS.data_format)
        load_ops = load_weights(tf.global_variables(scope='detector'),
                                FLAGS.weights_file)

    # Sets the output nodes in the current session
    boxes = detections_boxes(detections)

    with tf.Session() as sess:
        sess.run(load_ops)
        freeze_graph(sess, FLAGS.output_graph)
        writer = tf.summary.FileWriter("logs/", sess.graph)
示例#3
0
def main(argv=None):
    if FLAGS.tiny:
        model = yolo_v3_tiny.yolo_v3_tiny
        print ('doing tiny')
    else:
        model = yolo_v3.yolo_v3

    classes = load_coco_names(FLAGS.class_names)
    print ('num classes',len(classes))

    # placeholder for detector inputs
    inputs = tf.placeholder(tf.float32, [None, FLAGS.size, FLAGS.size, 3], "inputs")

    with tf.variable_scope('detector'):
        detections = model(inputs, len(classes), data_format=FLAGS.data_format)
        load_ops = load_weights(tf.global_variables(scope='detector'), FLAGS.weights_file)

    #detect_1.shape = (?, 507, 85)
    #detect_2.shape = (?, 2028, 85)
    #detect_3.shape = (?, 8112, 85)
    #detections.shape = (?, 10647, 85)
    #detections = Tensor("detector/yolo-v3/detections:0", shape=(?, 10647, 85), dtype=float32)
    print("detections.shape =", detections.shape)
    print(detections)
    print(detections.name)
    # Sets the output nodes in the current session
    boxes = detections_boxes(detections)

    with tf.Session() as sess:
        sess.run(load_ops)
        freeze_graph(sess, FLAGS.output_graph, FLAGS.tiny)
def main(argv=None):
    if FLAGS.tiny:
        model = yolo_v3_tiny.yolo_v3_tiny
        # model = yolov3_tiny_tflite.yolo_v3_tiny
    elif FLAGS.spp:
        model = yolo_v3.yolo_v3_spp
    else:
        model = yolo_v3.yolo_v3

    classes = load_coco_names(FLAGS.class_names)

    # placeholder for detector inputs
    inputs = tf.placeholder(tf.float32, [1, FLAGS.size, FLAGS.size, 3],
                            "inputs")

    with tf.variable_scope('detector'):
        # detect_1,detect_2 = model(inputs, len(classes), data_format=FLAGS.data_format)
        detection = model(inputs, len(classes), data_format=FLAGS.data_format)
        load_ops = load_weights(tf.global_variables(scope='detector'),
                                FLAGS.weights_file)

    # Sets the output nodes in the current session
    # detect_1,detect_2 = detections_boxes(detect_1,detect_2)
    detection = detections_boxes(detection)

    with tf.Session() as sess:
        sess.run(load_ops)
        freeze_graph(sess, FLAGS.output_graph)
示例#5
0
def main(argv=None):
    if FLAGS.tiny:
        model = yolo_v3_tiny.yolo_v3_tiny
    elif FLAGS.spp:
        model = yolo_v3.yolo_v3_spp
    else:
        model = yolo_v3.yolo_v3

    classes = load_coco_names(FLAGS.class_names)

    # placeholder for detector inputs
    inputs = tf.placeholder(tf.float32, [None, FLAGS.size, FLAGS.size, 3],
                            "inputs")

    with tf.variable_scope('detector'):
        detections = model(
            inputs, len(classes), data_format=FLAGS.data_format
        )  # 得到yolov3整体模型(包含模型输出(?, 10647, (num_classes + 5)))
        load_ops = load_weights(tf.global_variables(scope='detector'),
                                FLAGS.weights_file)

    # Sets the output nodes in the current session
    boxes = detections_boxes(
        detections)  # 1,将整体输出分解为box结果与概率数值结果;2、将结果名称定义为output_boxes再放入graph中

    with tf.Session() as sess:
        sess.run(load_ops)
        reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
        var_to_shape_map = reader.get_variable_to_shape_map()
        for key in var_to_shape_map:
            print("tensor_name: ", key)
        freeze_graph(sess, FLAGS.output_graph)
示例#6
0
def main(argv=None):

    model = yolo_v3.yolo_v3

    classes = load_coco_names(FLAGS.class_names)

    # placeholder for detector inputs
    inputs = tf.placeholder(tf.float32, [None, FLAGS.size, FLAGS.size, 3],
                            "inputs")

    with tf.variable_scope('detector'):
        detections = model(inputs, len(classes), data_format=FLAGS.data_format)
        load_ops = load_weights(tf.global_variables(scope='detector'),
                                FLAGS.weights_file)

    # Sets the output nodes in the current session
    boxes = detections_boxes(detections)

    with tf.Session() as sess:
        sess.run(load_ops)
        freeze_graph(sess, FLAGS.output_graph)
            tf.float32,
            [1, image_h, image_w, 3])  # placeholder for detector inputs
        print("=>", inputs)

        with tf.variable_scope('yolov3-tiny'):
            feature_map = model.forward(inputs, is_training=False)

        boxes, confs, probs = model.predict(feature_map)
        scores = confs * probs
        print("=>", boxes.name[:-2], scores.name[:-2])
        cpu_out_node_names = [boxes.name[:-2], scores.name[:-2]]
        boxes, scores, labels = utils.gpu_nms(boxes,
                                              scores,
                                              num_classes,
                                              score_thresh=0.5,
                                              iou_thresh=0.5)
        print("=>", boxes.name[:-2], scores.name[:-2], labels.name[:-2])
        gpu_out_node_names = [
            boxes.name[:-2], scores.name[:-2], labels.name[:-2]
        ]
        feature_map_1, feature_map_2, feature_map_3 = feature_map
        saver = tf.train.Saver(var_list=tf.global_variables(
            scope='yolov3-tiny'))

        saver.restore(sess, ckpt_file)
        print('=> checkpoint file restored from ', ckpt_file)
        utils.freeze_graph(sess, './pb/yolov3_cpu_nms_tiny_mix_v2_low_q_5k.pb',
                           cpu_out_node_names)
        utils.freeze_graph(sess, './pb/yolov3_gpu_nms_tiny_mix_v2_low_q_5k.pb',
                           gpu_out_node_names)