window10 Keras写的YOLOv3 测试程序yolo_video.py改进测试图像

       如果测试图像而非视频的话,网上有很多代码都是在terminal里面运行:python yolo_video.py --image, 本人比较懒不喜欢使用命令运行程序,因此对测试程序yolo.video.py做了如下更改。

       实验结果发现Keras写的yolo虽然可以出实验结果但是loss接近10左右。实验结果如图:

将yolo_video.py更改为下面的代码直接运行即可,每测试一张显示一张图像,22行的path是测试图像的路径,23行outputdir是要保存测试图像的路径,61行的default=‘True’即可:(使用需要点赞,谢谢!)

import sys
import argparse
from yolo import YOLO, detect_video
from PIL import Image
import glob, os
from skimage import io
from matplotlib import pyplot as plt
import numpy as np
# def detect_img(yolo):
#     while True:
#         img = input('Input image filename:')
#         try:
#             image = Image.open(img)
#         except:
#             print('Open Error! Try again!')
#             continue
#         else:
#             r_image = yolo.detect_image(image)
#             r_image.show()
#     yolo.close_session()
def detect_img(yolo):
    path = "D:\\Users\\Experiments\\YOLO3\\keras-yolo3-master\\data\\testimage\\*.jpg"
    outputdir = "D:\\Users\\Experiments\\YOLO3\\keras-yolo3-master\\data"
    for jpgfile in glob.glob(path):
        img = Image.open(jpgfile)
        img = yolo.detect_image(img)
        img.save(os.path.join(outputdir, os.path.basename(jpgfile)))
        img = np.array(img)
        io.imshow(img)
        plt.show()
    yolo.close_session()

FLAGS = None

if __name__ == '__main__':
    # class YOLO defines the default value, so suppress any default here
    parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
    '''
    Command line options
    '''
    parser.add_argument(
        '--model', type=str,
        help='path to model weight file, default ' + YOLO.get_defaults("model_path")
    )

    parser.add_argument(
        '--anchors', type=str,
        help='path to anchor definitions, default ' + YOLO.get_defaults("anchors_path")
    )

    parser.add_argument(
        '--classes', type=str,
        help='path to class definitions, default ' + YOLO.get_defaults("classes_path")
    )

    parser.add_argument(
        '--gpu_num', type=int,
        help='Number of GPU to use, default ' + str(YOLO.get_defaults("gpu_num"))
    )

    parser.add_argument(
        '--image', default=True, action="store_true",
        help='Image detection mode, will ignore all positional arguments'
    )
    '''
    Command line positional arguments -- for video detection mode
    '''
    parser.add_argument(
        "--input", nargs='?', type=str,required=False,default='./path2your_video',
        help = "Video input path"
    )

    parser.add_argument(
        "--output", nargs='?', type=str, default="",
        help = "[Optional] Video output path"
    )

    FLAGS = parser.parse_args()

    if FLAGS.image:
        """
        Image detection mode, disregard any remaining command line arguments
        """
        print("Image detection mode")
        if "input" in FLAGS:
            print(" Ignoring remaining command line arguments: " + FLAGS.input + "," + FLAGS.output)
        detect_img(YOLO(**vars(FLAGS)))
    elif "input" in FLAGS:
        detect_video(YOLO(**vars(FLAGS)), FLAGS.input, FLAGS.output)
    else:
        print("Must specify at least video_input_path.  See usage with --help.")

在改进yolo的过程中遇见的错误记录:

错误一:'NoneType' object has no attribute '_inbound_n’

这个错误是由误用tensorflow中的代码写作方式导致的,不可将TensorFlow代码与keras代码一起使用,

解决方法:检查改进的代码,将TensorFlow写的代码替换成keras.

 

  • 11
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苏打水的杯子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值