简体   繁体   English

为 SVHN 数据集实现 YOLOv3 object 检测器

[英]Implementing a YOLOv3 object detector for the SVHN dataset

I am trying to use object detection for digit detection.我正在尝试使用 object 检测进行数字检测。 I found the SVHN dataset .我找到了SVHN 数据集 Speed is important in my project so I decided to apply a YOLO approach.速度在我的项目中很重要,所以我决定采用 YOLO 方法。

However, all tutorials and explanatiosn on using YOLOv3 either expect me to be using a dataset made from the Google Open Images API or by manually labeling images using a tool such as labellimg.py.但是,所有关于使用YOLOv3的教程和说明都希望我使用由 Google Open Images API 制作的数据集,或者使用 labellimg.py 等工具手动标记图像。

I however have a premade dataset with annotaions in the PASCAL VOC format (which can be found here https://github.com/penny4860/svhn-voc-annotation-format ).然而,我有一个带有 PASCAL VOC 格式注释的预制数据集(可以在这里找到https://github.com/penny4860/svhn-voc-annotation-format )。 Because of this I do not create a labels.txt or classes.txt file as I do no labeling myself.因此,我不创建标签.txt 或 classes.txt 文件,因为我不给自己贴标签。

I am rather at a loss on where to get started.我不知道从哪里开始。

Any help would be appreciated.任何帮助,将不胜感激。

You can follow the below code to convert from PASCAL VOC to YOLO supported format.您可以按照以下代码将 PASCAL VOC 转换为 YOLO 支持的格式。

import glob
import os
import pickle
import xml.etree.ElementTree as ET
from os import listdir, getcwd
from os.path import join

dirs = ['train', 'val']
classes = ['person', 'car']

def getImagesInDir(dir_path):
    image_list = []
    for filename in glob.glob(dir_path + '/*.jpg'):
        image_list.append(filename)

    return image_list

def convert(size, box):
    dw = 1./(size[0])
    dh = 1./(size[1])
    x = (box[0] + box[1])/2.0 - 1
    y = (box[2] + box[3])/2.0 - 1
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)

def convert_annotation(dir_path, output_path, image_path):
    basename = os.path.basename(image_path)
    basename_no_ext = os.path.splitext(basename)[0]

    in_file = open(dir_path + '/' + basename_no_ext + '.xml')
    out_file = open(output_path + basename_no_ext + '.txt', 'w')
    tree = ET.parse(in_file)
    root = tree.getroot()
    size = root.find('size')
    w = int(size.find('width').text)
    h = int(size.find('height').text)

    for obj in root.iter('object'):
        difficult = obj.find('difficult').text
        cls = obj.find('name').text
        if cls not in classes or int(difficult)==1:
            continue
        cls_id = classes.index(cls)
        xmlbox = obj.find('bndbox')
        b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
        bb = convert((w,h), b)
        out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')

cwd = getcwd()

for dir_path in dirs:
    full_dir_path = cwd + '/' + dir_path
    output_path = full_dir_path +'/yolo/'

    if not os.path.exists(output_path):
        os.makedirs(output_path)

    image_paths = getImagesInDir(full_dir_path)
    list_file = open(full_dir_path + '.txt', 'w')

    for image_path in image_paths:
        list_file.write(image_path + '\n')
        convert_annotation(full_dir_path, output_path, image_path)
    list_file.close()

    print("Finished processing: " + dir_path)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Object 使用 YOLOv3 检测 - Object Detection Using YOLOv3 YOLOV3 对象检测未检测到对象且边界框未包围对象 - YOLOV3 object detection not detecting the object and bounding boxes are not bounding the objects 在 Keras 中使用 YOLOv3 进行对象检测 - ValueError:如果您的数据采用符号张量的形式 - Object Detection With YOLOv3 in Keras- ValueError: If your data is in the form of symbolic tensors 训练 model 检测新物体 - YoloV3 - Train model to detect new objects - YoloV3 Darknet Yolov3 - 预训练模型的自定义训练 - Darknet Yolov3 - Custom training on pre-trained model 使用 YOLOV3 检测时 output 视频 stream 中的延迟使用 OpenCV - Delay in output video stream when using YOLOV3 Detection using OpenCV Tensorflow 自定义 Object 检测器:model_main_tf2 未开始训练 - Tensorflow custom Object Detector: model_main_tf2 doesn't start training 是否有实现 object 克隆 function 的自定义方法? - Is there a custom way for implementing an object clone function? 如何将检测到的对象转换为COCO数据集Json - How to Convert Detected Object to COCO dataset Json AttributeError:数据集对象没有属性“c”FastAI - AttributeError: dataset object has no attribute 'c' FastAI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM