from __future__ import division, print_function
import tensorflow as tf
import numpy as np
import argparse
import cv2
import os
os.environ['CUDA_VISIBLE_DEVICES'] = "7"
from utils.misc_utils import parse_anchors, read_class_names
from utils.nms_utils import gpu_nms
from utils.plot_utils import get_color_table, plot_one_box
from utils.data_aug import letterbox_resize
from model import yolov3
parser = argparse.ArgumentParser(description="YOLO-V3 test single image test procedure.")
parser.add_argument("--input_path", type=str,default='/home/gyx/QR/qr_detect/YOLOv3_TensorFlow/data/demo_data/test_qr/',
help="The path of the input image.")
parser.add_argument("--save_path", type=str,default='/home/gyx/QR/qr_detect/YOLOv3_TensorFlow/data/demo_data/save_output/',
help="The path of the input image.")
parser.add_argument("--anchor_path", type=str, default="./data/yolo_anchors_320.txt",
help="The path of the anchor txt file.")
parser.add_argument("--new_size", nargs='*', type=int, default=[320, 320],
help="Resize the input image with `new_size`, size format: [width, height]")
parser.add_argument("--letterbox_resize", type=lambda x: (str(x).lower() == 'true'), default=True,
help="Whether to use the letterbox resize.")
parser.add_argument("--class_name_path", type=str, default="./data/data.names",
help="The path of the class names.")
parser.add_argument("--restore_path", type=str, default="./checkpoint_320/best_model_Epoch_44_step_18359_mAP_0.9307_loss_0.8562_lr_3e-05",
help="The path of the weights to restore.")
args = parser.parse_args()
args.anchors = parse_anchors(args.anchor_path)
args.classes = read_class_names(args.class_name_path)
args.num_class = len(args.classes)
# color_table = get_color_table(args.num_class)
color_table = {}
color_table[0] = [250,0,0]
img_list=os.listdir(args.input_path)
# print(img_list)
with tf.Session() as sess:
input_data = tf.placeholder(tf.float32, [1, args.new_size[1], args.new_size[0], 3], name='input_data')
yolo_model = yolov3(args.num_class, args.anchors)
with tf.variable_scope('yolov3'):
pred_feature_maps = yolo_model.forward(input_data, False)
pred_boxes, pred_confs, pred_probs = yolo_model.predict(pred_feature_maps)
pred_scores = pred_confs * pred_probs
boxes, scores, labels = gpu_nms(pred_boxes, pred_scores, args.num_class, max_boxes=200, score_thresh=0.3, nms_thresh=0.45)
saver = tf.train.Saver()
saver.restore(sess, args.restore_path)
###########################重点区域#################################
init = tf.initialize_all_variables()
merged = tf.summary.merge_all()
writer = tf.summary.FileWriter("./log/",sess.graph) #目录结构尽量简单,复杂了容易出现找不到文件,原因不清楚
sess.run(init)
print("tensorboard --logdir=./log --host=127.0.0.1")
点击链接或者在命令行输入:tensorboard --logdir=./log --host=127.0.0.1