Giter Site home page Giter Site logo

voc_to_coco's Introduction

VOC_to_COCO

update 2019.10.5

最简单的VOC数据集转换为COCO数据集方式

修改路径后, 只要一条指令就能转换

任何报错请issue我

  1. 请先确认你的VOC如下面的格式

      VOC
        |-- Annotations
        		|-- all xml files
        |-- JPEGImages
        		|-- all your samples
        |-- ImageSets
        		|-- 。。。。
    
    
  2. 克隆本仓到你指定的地址

git clone https://github.com/Stephenfang51/VOC_to_COCO
  1. cd 到VOC_to_COCO 编辑 voc_to_coco.py修改以下3点

    1. 设定验证集样本数, 如果设定为100, 则将从你的样本随机提取100个作为验证集
    2. 设定测试集样本数
    3. VOC Annotations 资料夹路径(最后面的"/"务必加上, 否则报错)

    例如

    val_files_num = 100
    test_files_num = 100
    voc_annotations = '././VOC/Annotations/'  #remember to modify the path

    修改到这边已经结束

  2. 执行生成, 确认是python3版本以上解释器, 否则报错

    python3 voc_to_coco.py
    
  3. COCO 数据集已经生成与VOC同一主目录下


The simplest way to covert VOC style dataset to COCO style dataset, only for object detection tesk for now.

Any problem feel free to issue me !

  1. First need to comfirm that your VOC path looks like:

      VOC
        |-- Annotations
        		|-- all xml files
        |-- JPEGImages
        		|-- all your samples
        |-- ImageSets
        		|-- 。。。。
    
  2. Clone this repo

    git clone https://github.com/Stephenfang51/VOC_to_COCO
    
  3. command cd to VOC_to_COCO path, and set the following three parts

    val_files_num = 100
    test_files_num = 100
    voc_annotations = '././VOC/Annotations/'  #remember to modify the path

    ex.

    if you set val_files_num to 100, which means it wil randomly choice 100 samples from your dataset

  4. do it ! only for python3

    python3 voc_to_coco.py
  5. Done ! your COCO dataset and your VOC dataset in the same path. So easy !

voc_to_coco's People

Contributors

stephenfang51 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

voc_to_coco's Issues

ValueError: Filename is supposed to be an integer.

[ Done ! Go check your file ]*
Traceback (most recent call last):
File "/home/litong/voc_to_coco/VOC_to_COCO/voc_to_coco.py", line 166, in get_filename_as_int
return int(filename)
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/litong/voc_to_coco/VOC_to_COCO/voc_to_coco.py", line 266, in
convert(xml_val_files, coco_json_annotations + 'val2017.json')
File "/home/litong/voc_to_coco/VOC_to_COCO/voc_to_coco.py", line 209, in convert
image_id = get_filename_as_int(filename)
File "/home/litong/voc_to_coco/VOC_to_COCO/voc_to_coco.py", line 168, in get_filename_as_int
raise ValueError("Filename %s is supposed to be an integer." % (filename))
ValueError: Filename is supposed to be an integer.

Process finished with exit code 1

请问一下ImageSets里应该放什么文件

您好,我在使用您的代码是,我JPEGImages里有247个图片,ImageSets里不知道放什么所以空着在 然后用默认的100val 100test跑 最后结果train2017.jason是空的 然后python的最后一行如下
100 files copied to /Users/jayhuashi/Desktop/Sub22/xml/xml_val/
The folders are empty, please make sure there are enough 100 file to move

请问会是什么原因导致的呢 感谢

concerning the file name error

Traceback (most recent call last):
File "voc_to_coco.py", line 166, in get_filename_as_int
return int(filename)
ValueError: invalid literal for int() with base 10: '000609af'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "voc_to_coco.py", line 266, in
convert(xml_val_files, coco_json_annotations + 'val2017.json')
File "voc_to_coco.py", line 209, in convert
image_id = get_filename_as_int(filename)
File "voc_to_coco.py", line 168, in get_filename_as_int
raise ValueError("Filename %s is supposed to be an integer." % (filename))
ValueError: Filename 000609af is supposed to be an integer.

Is this a file name error? Looking forward to your reply.

filename的id

我想转换通过labelImg标注的数据集为coco数据集,这个filename不是数字串,是字母等,在调用get_filename_as_int这个地方就会出错,这里是不是只是赋给每张图一个id,那我手动赋值可以吗

[Errno 13] Permission Denied

Traceback (most recent call last):
File "voc_to_coco.py", line 65, in
mkdir(coco_path)
File "voc_to_coco.py", line 54, in mkdir
os.makedirs(path)
File "/usr/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/VOC2020_COCO/'

Firstly, I thought it may be the setting of Big Sur SIP. But after I change the setting on macOS or turning to other Operation System, the problem still exists.

显示Done但是依然报错

您好,我运行后您的代码后显示Done,但是同时也有报错的信息,请问是什么问题呢?

原始数据的目录(我用的是VOC2012):

 VOC
    |-- Annotations
    		|-- 17125个xml
    |-- JPEGImages
    		|-- 17125张图片
    |-- ImageSets
    		|-- Action
    		|-- Layout
    		|-- Main
    		|-- Segmentation

 VOC_to_COCO
    |-- README.md
    |-- voc_to_coco.py

voc_to_coco.py中我只改了地址voc_annotations = '/home/vincent/Data/VOCdevkit/VOC/Annotations/'

生成的目录:

 VOC
    |-- Annotations
    		|-- 17125个xml
    |-- JPEGImages
    		|-- 17125张图片
    |-- ImageSets
    		|-- Action
    		|-- Layout
    		|-- Main
    		|-- Segmentation

 VOC_to_COCO
    |-- README.md
    |-- voc_to_coco.py

# 下面两个是新生成的

 VOC_COCO
    |-- annotations
    		|-- test2017.json
    		|-- val2017.json
    |-- images
    		|-- 17125张图片

 xml
    |-- xml_test
    		|-- 100个xml
    |-- xml_train
    		|-- 16925个xml
    |-- xml_val
    		|-- 100个xml

报错为:

/home/vincent/Data/VOCdevkit/VOC_COCO/ ----- folder created
/home/vincent/Data/VOCdevkit/VOC_COCO/images ----- folder created
/home/vincent/Data/VOCdevkit/VOC_COCO/annotations/ ----- folder created
/home/vincent/Data/VOCdevkit/xml/xml_val/ ----- folder created
/home/vincent/Data/VOCdevkit/xml/xml_test/ ----- folder created
/home/vincent/Data/VOCdevkit/xml/xml_train/ ----- folder created


 100 files copied to /home/vincent/Data/VOCdevkit/xml/xml_val/


***************************[ Done ! Go check your file ]****************************
Traceback (most recent call last):
  File "voc_to_coco.py", line 268, in <module>
    convert(xml_train_files, coco_json_annotations + 'train2017.json')
  File "voc_to_coco.py", line 231, in convert
    ymin = int(get_and_check(bndbox, "ymin", 1).text) - 1
ValueError: invalid literal for int() with base 10: '281.70000076293945'

我打开查看test2017.jsonval2017.json,内容如下:
test2017.json内容:

images
    |-- 编号从0~99
type: "instances"
annotations
    |-- 编号从0~242
categories
    |-- 编号从0~19

val2017.json内容:

images
    |-- 编号从0~99
type: "instances"
annotations
    |-- 编号从0~199
categories
    |-- 编号从0~18

我修改了voc_to_coco.py中的val_files_numtest_files_num,尝试10或者1000,也是报同一个错误

我有以下的疑问:

  1. 请问是不是应该还有一个关于train的json呢,因为报错的原因所以没有生成?
  2. 请问有什么办法解决这个报错不?

谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.