pascal_voc_tools package¶
Subpackages¶
Submodules¶
pascal_voc_tools.anchors_kmeans module¶
Calculating anchors using k-means for yolov3.
-
class
pascal_voc_tools.anchors_kmeans.AnchorsKMeans(filelist)¶ Bases:
object对anchors聚类
-
calculate(num_clusters, yolo_input_shape, yolo_version='yolov3')¶ Parameters: - num_clusters – number of clusters;
- yolo_version – default=’yolov3’, yolov2 or yolov3;
- yolo_input_shape – input images shape,multiples of 32. etc. 416*416;
Returns: anchors
-
save(output_dir)¶ Save current anchors to a file
Parameters: output_dir – str, a dir to save anchors file.
-
pascal_voc_tools.annotation_tools module¶
pascal_voc_tools.aspect_ratios module¶
pascal_voc_tools.darknet_config module¶
-
class
pascal_voc_tools.darknet_config.DarknetConfig¶ Bases:
objectTools about config file for darknet.
-
change_anchors(layers, new_anchors)¶ Parameters: - layers – list, the list of Layers;
- new_anchors – list, which have n anchors, for each anchor it has the format like [w, h].
Returns: list, the layers had been changed.
Return type: layers
-
check_yolo(cfg_file, label_list_file)¶ Using to check some key in yolo config. :param cfg_file: str, the config file path; :param label_list_file: str, the file of label list;
-
parse(config_path)¶ decode the config file for darknet :param config_path: str, the path of config file;
Returns: list, including Layer struct. Return type: layers
-
save(layers, save_path)¶ Saving the list of Layer to save_path. :param layers: list, have some Layers; :param save_path: str, the path using to save.
-
-
class
pascal_voc_tools.darknet_config.Layer(name)¶ Bases:
objectDarknet Layer Struct
-
pascal_voc_tools.darknet_config.main()¶
pascal_voc_tools.datatools module¶
pascal_voc_tools.file module¶
pascal_voc_tools.format module¶
pascal_voc_tools.image_annotation_split module¶
pascal_voc_tools.resize module¶
pascal_voc_tools.tools module¶
Some useful tools.
-
pascal_voc_tools.tools.average_precision_11_point()¶
-
pascal_voc_tools.tools.average_precision_matric()¶
-
pascal_voc_tools.tools.bb_intersection_over_union(box_a, box_b)¶ calculate intersection over union between two boundboxes.
Parameters: - box_a – list of xmin, ymin, xmax, ymax;
- box_b – list of xmin, ymin, xmax, ymax;
Returns: a float number of iou between two inputs.
Module contents¶
Pascal Voc Tools
This package provide some tools using for pascal voc format dataset and some usrful functions.
-
class
pascal_voc_tools.ImageWrapper¶ Bases:
objectSome image tools.
-
crop_image(split_bboxes)¶ Split an image to some subimages.
Parameters: split_bboxes – list, like[[xmin, ymin, xmax, ymax], ] Returns: list, all subimages. Return type: images
-
load(image_path: str)¶ load image data.
Parameters: image_path – image file path.
-
resize_by_rate(rate: float)¶ Resize image.
Parameters: rate – image resize rate.
-
resize_letter_box(width: int, height: int)¶ using letter box to resize image data.
Parameters: - width – new image width.
- height – new image height.
Returns: a flot of resize rate.
-
save(save_path)¶ save image data to a file.
Parameters: save_path – a image file path.
-
-
class
pascal_voc_tools.DataSource(database: str = 'Unknown')¶ Bases:
objectSource data format in Pascal VOC xml
-
database¶ a str of dataset name.
-
load_from_node(node)¶ Decode database info from node.
Parameters: node – a source Element node.
-
save_to_node(node)¶ Encode database info from node.
Parameters: node – a source Element node.
-
-
class
pascal_voc_tools.ImageSize(width: int = 0, height: int = 0, depth: int = 0)¶ Bases:
objectSize data format in Pascal VOC xml
-
width¶ a int of image width.
-
height¶ a int of image height.
-
depth¶ a int of image depth.
-
load_from_node(node)¶ Decode size info from node.
Parameters: node – a size Element node.
-
save_to_node(node)¶ Encode size info to node.
Parameters: node – a size Element node.
-
-
class
pascal_voc_tools.PascalXml(folder: str = '', filename: str = '', path: str = '', source: pascal_voc_tools.xml_tools.DataSource = <pascal_voc_tools.xml_tools.DataSource object>, size: pascal_voc_tools.xml_tools.ImageSize = <pascal_voc_tools.xml_tools.ImageSize object>, segmented: int = 0, object_list: list = None)¶ Bases:
objectPascal VOC xml file data format
-
folder¶ image folder.
-
filename¶ image file name.
-
path¶ image file path.
-
source¶ the DataSource.
-
size¶ the ImageSize.
-
segmented¶ default 0.
-
object_list¶ a list of XmlObject
-
add_object(name, xmin, ymin, xmax, ymax, pose='Unspecified', truncated=0, difficult=0)¶ add an object info
Parameters: - name – str, class name.
- xmin – int, left.
- ymin – int, top.
- xmax – int, right.
- ymax – int, bottom.
- pose – str, default is ‘Unspecified’.
- truncated – str, default is 0.
- difficult – int, default is 0.
-
convert2csv(classes: list = [])¶ Convert data to info list. The head is [file_name, width, height, category, xmin, ymin, xmax, ymax]
Parameters: classes – a list of categories.
-
convert2yolotxt(save_path: str, classes: list)¶ save data to txt for yolo format.
Parameters: - save_path – the txt file path to save data.
- classes – a list of categories.
-
crop_annotations(split_bboxes, iou_thresh=0.7)¶ Using split_bboxes to split an xml file.
Parameters: - xml_info – dict, all info about a xml.
- split_bboxes – list, like [[xmin, ymin, xmax, ymax], ]
Returns: list, like [xml_info, ]
Return type: subannotations
-
load(xml_file_path)¶ form a xml file load data.
Parameters: xml_file_path – a xml file path.
-
load_from_node(node)¶ load data from Element
Parameters: node – an annotation Element.
-
replace_name(old_name, new_name)¶ Replace an object name.
Parameters: - old_name – str, an object class name.
- new_name – str, a new object class name.
-
resize_obj_by_rate(rate: float, biases: tuple)¶ Resize all bndbox by rate.
Parameters: rate – a float for timeing bndbox.
-
save(save_xml_path)¶ save data to a xml file.
Parameters: save_xml_path – the xml path to save data.
-
save_to_node(node)¶ save info to annotation Element
Parameters: node – an annotation Element.
-
-
class
pascal_voc_tools.JPEGImages(image_dir=None)¶ Bases:
objectSome tools for JPEGImages dir.
-
load(image_dir=None)¶ Load jpg image files’ path.
Parameters: image_dir – a directory incluing jpg images.
-
-
class
pascal_voc_tools.Annotations(ann_dir)¶ Bases:
objectdeal with annotations in PascalVOC format dataset.
-
ann_dir¶ str, the dir including xmls.
Raises: AssertError– can not find path.-
convert2csv(save_path, category_list=[])¶ find all bndbox info and save to csv file. If category_list exist, only save the categories in list.
Parameters: - save_path – a csv file path.
- category_list – a list for keep category to save.
Raises: AssertionError– the save path not a csv file path.
-
count_category()¶
-
get_bbox_info()¶
-
height_analyse(save_dir='./', split_num=100)¶ Draw height ratio distribution in dataset.
Parameters: - save_dir – str, image save dir;
- split_num – int, the number of data partitions
-
iou_analyse(save_dir='./', split_num=100)¶ Draw iou distribution in dataset.
Parameters: - save_dir – str, image save dir;
- split_num – int, the number of data partitions
-
load(name_list=None)¶
-
width_analyse(save_dir='./', split_num=100)¶ Draw width ratio distribution in dataset.
Parameters: - save_dir – str, image save dir;
- split_num – int, the number of data partitions
-
-
class
pascal_voc_tools.VOCTools(voc_root_dir: str)¶ Bases:
objecta VOC format dataset.
-
root_dir¶ a voc directory like VOC2007.
-
check_jpg_xml_match()¶ Check matching degree about xml files and jpeg files.
-
crop_data(save_root_dir, set_name_list, min_side=1000, max_side=1333, cover_thresh=0.2, iou_thresh=0.7)¶ split image and annotation to some sub data.
Parameters: - save_root_dir – a new dir to save new data.
- set_name_list – a list like [train, val].
- min_side – a int of sub image min side.
- max_side – a int of sub image max side.
- cover_thresh – sub image overlap rate.
- iou_thresh – bndbox with sub image overlap rate.
Returns: a new VOCTools including new data.
-
crop_image_annotations(jpg_path, xml_path, min_side, max_side, cover_thresh=0.2, iou_thresh=0.7)¶ Split an image and it’s annotation file.
Parameters: - jpg_path – str, image path.
- xml_path – str, xml path.
- cover_thresh – float, cover rate about each subimage, default=0.2.
- iou_thresh – float, filter annotations which one’s iou is smaller than thresh, default=1.0.
Returns: a list of ImageWrapper. subannotations: a list of PascalXml
Return type: subimages
-
gen_format_dir()¶
-
get_crop_bboxes(width, height, min_side, max_side, cover_thresh=0.2)¶
-
get_image_path_by_xml_path(xml_path)¶ using xml path to inference image path
Parameters: xml_path – str, xml file path. Returns: image path in current dataset.
-
get_year()¶
-
match_jpg_xml()¶
-
resize_by_size(width, height, save_root_dir)¶ Resize whole dataset by set a fix image size.
Parameters: - width – int, new image width.
- height – int, new image height.
- save_root_dir – a new dir to save data.
Returns: new VOCTools have new data.
-
-
class
pascal_voc_tools.AnchorsKMeans(filelist)¶ Bases:
object对anchors聚类
-
calculate(num_clusters, yolo_input_shape, yolo_version='yolov3')¶ Parameters: - num_clusters – number of clusters;
- yolo_version – default=’yolov3’, yolov2 or yolov3;
- yolo_input_shape – input images shape,multiples of 32. etc. 416*416;
Returns: anchors
-
save(output_dir)¶ Save current anchors to a file
Parameters: output_dir – str, a dir to save anchors file.
-
-
class
pascal_voc_tools.DarknetConfig¶ Bases:
objectTools about config file for darknet.
-
change_anchors(layers, new_anchors)¶ Parameters: - layers – list, the list of Layers;
- new_anchors – list, which have n anchors, for each anchor it has the format like [w, h].
Returns: list, the layers had been changed.
Return type: layers
-
check_yolo(cfg_file, label_list_file)¶ Using to check some key in yolo config. :param cfg_file: str, the config file path; :param label_list_file: str, the file of label list;
-
parse(config_path)¶ decode the config file for darknet :param config_path: str, the path of config file;
Returns: list, including Layer struct. Return type: layers
-
save(layers, save_path)¶ Saving the list of Layer to save_path. :param layers: list, have some Layers; :param save_path: str, the path using to save.
-