Giter Club home page Giter Club logo

augmentation's Introduction

Image Augmentation 增强数据

Description

This script is meant to augment a set of images to a specified amount. It will try to iterate through the set of images in Source and perform some transformations, then save the result into Augmented. After one iteration ends, it will restart from the first image again and will not stop until the designated limit is reached. The tmp folder is needed for temporarily saving the transformed image; do not delete it, it will be emptied.

    本脚本功能是随机生成增强图片和注释。对图片的更改不大,增强原有数据达到指定目标张数。因对原图产生影响不大,用于均衡数量不平衡标签类用。 之前的使用是人工取出一类标签数据放入Source,用本程序增强到固定数量,再人工拷贝到训练集目录下。

The procedure to generate a new image involves three steps.

First step is cropping, the image will either receive no change, a crop from the top, or a crop from the bottom with equal probability. With the top crop mode, the corresponding xml will be changed as well. 上下裁剪

Second step is sharpening, the image will either receive no change, a sharpening filtering, an excessive sharpening filtering, or an edge enhancement filtering with equal probability. Since this transformation does not affect bounding boxes, corresponding xmls are simply copied. 边缘增强,图片锐化

Third step is equalizing histograms, the image's pixel histograms will be equalized with 50% probability. 直方图均衡化

With each step, the image file's name will be changed, the operation it received will be appended, corresponding xml's name will be changed.

For Use 使用时

  1. Put jpg and annotation files to into the folders under Source. Make sure that your images have names with specific suffix: '.jpg', and the annotations have the suffix '.xml".
   源数据请放在Source里,图片放在jpg_data, 注释放在anno里
  1. Change a few parameters to your need:

    1. In augment_training_data.py, set your augment_limit, the number of images you want after augmentation.
       在augment_training_data.py里,修改augment_limit,它指的是你最后想要图片有多少张。
    
    1. Optionally, you can change img_savepath, anno_savepath, imgset_savepath, the final location of your augmented JPEG images and XML annotations, and the location of file lists.
        修改最终增强后的三类数据存储路径
    
    1. You also can change source_path, the location you need to put your files before augmentation.
  2. Run augment_training_data.py, and get your training data folder called Augmented. In Augmented, images are stored in JPEGImages, and annotations are stored in Annotations, and the list of all image names are stored in ImageSets/Main/trainval.txt.

##For Extension 添加新增强处理

  1. The three steps of augmentation are found to work best independently of each other. Therefore, it is better if we do not modify the steps.

        实验发现前三层增强操作可以进行叠加,而第二层的三种锐化不可相互叠加,结果会不理想,故放在同一层
    
  2. Here are the general naming preferences of the author:

        以下为个人命名变量习惯
    

imgp= the path to the jpeg image to be modified; 、

xmlp = the path to the xml file to be modified;

person = id = the name of the file, stripped of suffixes, e.g '10011.jpg' -> '10011';

img_savepath = the path to save image; xml_savepath = the path to save xml;

trainval = the text file to write our file list in;

code = the 3 digit transform code, corresponding to 3 steps of transformation.

  1. How the transformation code represent the transformations, see the comments in augment_training_data.py.

  2. ! To add another step of transformation to the augmentation procedure:

    1. Write your own transform.py, which should implement an function named interface.
        def interface(imgp, xmlp, id, img_save, xml_save, mode):
        # mode can be a string of 0, 1, 2. etc to represent a transformation you want to perform
        # make sure to return the path of your new img and xml, and the new id
        # 按照这个格式添加新的增强处理,对于同一处理的不同变种可以放在同一步,例如左裁剪,右裁剪等,在裁剪步中取其一。
        # 变换完成后返回新的文件路径和新的文件名
            return img_save + id + '_new', xml_save + id + '_new', id + new
    1. Modify generate_transform() function in augment_training_data.py to add another transform option with equal probability, or however you want.
    在随机生成转换码的程序中加一位
    
    1. Import your file transform.py in augment_training_data.py, and modify transform() to call your transform.interface() function giving it the new digit.

augmentation's People

Contributors

zaczzy avatar

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.