首页 > 其他 > 详细

YOLO V3 错误总结

时间:2019-04-16 15:33:53      阅读:176      评论:0      收藏:0      [点我收藏+]

问题1

TypeError: function takes exactly 1 argument (3 given)

报错说PIL库中的函数只接收到一个参数,应该给三个,自己在这里记录下解决方法,出错的地方在yolo.py中,在yolo中在测试时需要对检测到的区域进行画出标记框和类别数字,因为作者测试的coco等图库都是RGB图像,会有三个参数输入给rectangle函数,不会发生报错,而在测试图像为灰度图时,就会出错。在解决错误是参考了参考文献[1]中的提示,很感谢!

对于这个错误原因,个人认为是这个函数在图像上绘制矩形框时,要求输入的图像的颜色空间维度要和矩形框颜色维度一致,比如:我们输入的灰度图(不做维度扩充),只能使用灰度进行画矩形框;输入的是RGB三色图,可以使用RGB颜色画矩形框。

解决方法:

1.对灰度图进行转换,

使用 image = image.convert(‘RGB‘)

比如部分yolo.py函数如下:

 

 

        for i, c in reversed(list(enumerate(out_classes))):
            predicted_class = self.class_names[c]
            box = out_boxes[i]
            score = out_scores[i]
 
            label = {} {:.2f}.format(predicted_class, score)
            # 对灰度图像进行RGB转换,输入的原图为(0)一维 转为(0,0,0)三维
            image = image.convert(RGB)
            draw = ImageDraw.Draw(image)
            label_size = draw.textsize(label, font)
 
            top, left, bottom, right = box
            top = max(0, np.floor(top + 0.5).astype(int32))
            left = max(0, np.floor(left + 0.5).astype(int32))
            bottom = min(image.size[1], np.floor(bottom + 0.5).astype(int32))
            right = min(image.size[0], np.floor(right + 0.5).astype(int32))
            print(label, (left, top), (right, bottom))
 
            if top - label_size[1] >= 0:
                text_origin = np.array([left, top - label_size[1]])
            else:
                text_origin = np.array([left, top + 1])
 
            # My kingdom for a good redistributable image drawing library.
            for i in range(thickness):
                draw.rectangle(
                    [left + i, top + i, right - i, bottom - i],
                    outline=self.colors[c])
                    #outline=(255))
            draw.rectangle(
                [tuple(text_origin), tuple(text_origin + label_size)],
                fill=self.colors[c])
                #outline=(255))
            #draw.text(text_origin, label, fill=(0, 0, 0), font=font)
            draw.text(text_origin, label, fill=(0), font=font)
            del draw

 

YOLO V3 错误总结

原文:https://www.cnblogs.com/guaweibaba/p/10717157.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!