vodet.detect module¶
- class vodet.detect.Detector(classifier, classes, labels_path, label_type='labelme', conf_th=0.95, iou_th=0.3, step_ratio=0.5, input_size=[24, 24])¶
Bases:
objectThe detector object.
- classifier¶
The GMVAE’s classifier.
- classes¶
A dict of names and index of each classes. The keys must be the name of classes. The values must be the index of each classes (used by the classifier).
- Type
dict of int
- labels_path¶
The path for the annotation data of train dataset. If label_type is “VoTT”, this must be a path for the exported csv file. If label_type is “labelme”, this must be a path for the directory that contains labelme’s json output files.
- Type
str
- label_type¶
The type of label data, either “VoTT” (for VoTT’s csv export) or “labelme” (for labelme’s json export).
- Type
str
- conf_th¶
The confidence threshold for each proposed bounding box.
- Type
float default 0.99
- iou_th¶
The threshold of IoU value for Non-Maximum Supression of bounding boxes.
- Type
float default 0.3
- step_ratio¶
The ratio between the step size and width or height of sliding windows.
- Type
float default 0.5
- input_size¶
The input size of the classifier
- Type
list of int
- detect_dir(in_dir, out_dir)¶
Detect objects and save the results from images in a directory.
- Parameters
in_dir (str) – The path of input directory.
out_dir (str) – The path of output directory.
- Returns
df – A dataframe of detected objects.
- Return type
pd.DataFrame
- detect_img(in_path, out_path)¶
Detect objects and save the result from an image.
- Parameters
in_path (str) – The path of input image.
out_path (str) – The path of output image.
- Returns
nums – The detected numbers of each classes.
- Return type
dict
- draw_barplot(date_df, out_path)¶
Draw a bar plot of detected result. The x-axis stands for the date of each picture was taken and the y-axis stands for the detected numbers of each class. Run this after detect_dir.
- Parameters
date_df (pd.DataFrame) – A dataframe that contains column “image” for the names of each image file, column “date” for the date each picture was taken. You can make this with vodet.utils.exif_date.
out_path (str) – The output path for the barplot.
- Returns
df – A dataframe of detected result with “date” column.
- Return type
pd.DataFrame
- vodet.detect.detect(classifier, image_path, labels_path, out_path, classes, label_type, bb_color, conf_th=0.99, iou_th=0.3, step_ratio=0.5, input_size=[24, 24])¶
Detect object with GMVAE’s classifier and sliding windows.
- Parameters
classifier (vodet.distributions.Classifier) – A trained Classifier object.
image_path (str) – The path for the target image.
labels_path (str) – The path for the annotation data of train dataset. If label_type is “VoTT”, this must be a path for the exported csv file. If label_type is “labelme”, this must be a path for the directory that contains labelme’s json output files.
out_path (str) – The path for the output image (input image with detected results).
classes (dict of int) – A dict of names and index of each classes. The keys must be the name of classes. The values must be the index of each classes (used by the classifier).
label_type (str) – The type of label data, either “VoTT” (for VoTT’s csv export) or “labelme” (for labelme’s json export).
bb_color (dict of tuple) – The RGB bounding box color values for each classes. RGB values should be 0-255 int.
conf_th (float default 0.99) – The confidence threshold for each proposed bounding box.
iou_th (float default 0.3) – The threshold of IoU value for Non-Maximum Supression of bounding boxes.
step_ratio (float default 0.5) – The ratio between the step size and width or height of sliding windows.
input_size (list of int) – The input size of the classifier
- Returns
detected_numbers – The detected numbers of each classes
- Return type
dict of int
- vodet.detect.detect_old(classifier, image_path, labels_path, out_path, classes, label_type, bb_color, conf_th=0.99, iou_th=0.3, step_ratio=0.5, input_size=[24, 24], device='cuda:0')¶
Detect object with GMVAE’s classifier and sliding windows.
- Parameters
classifier (vodet.distributions.Classifier) – A trained Classifier object.
image_path (str) – The path for the target image.
labels_path (str) – The path for the annotation data of train dataset. If label_type is “VoTT”, this must be a path for the exported csv file. If label_type is “labelme”, this must be a path for the directory that contains labelme’s json output files.
out_path (str) – The path for the output image (input image with detected results).
classes (dict of int) – A dict of names and index of each classes. The keys must be the name of classes. The values must be the index of each classes (used by the classifier).
label_type (str) – The type of label data, either “VoTT” (for VoTT’s csv export) or “labelme” (for labelme’s json export).
bb_color (dict of tuple) – The RGB bounding box color values for each classes. RGB values should be 0-255 int.
conf_th (float default 0.99) – The confidence threshold for each proposed bounding box.
iou_th (float default 0.3) – The threshold of IoU value for Non-Maximum Supression of bounding boxes.
step_ratio (float default 0.5) – The ratio between the step size and width or height of sliding windows.
input_size (list of int) – The input size of the classifier
device (str default "cuda:0") – The device name to use for running the classifier.
- Returns
detected_numbers – The detected numbers of each classes
- Return type
dict of int
- vodet.detect.iou(a, b)¶
Intersection over Union
- Parameters
a (tuple of int) – A tuple of size 4. Each element stands for x1, y1, x2, y2 of the bounding box
b (tuple of int) – A tuple of size 4. Each element stands for x1, y1, x2, y2 of the bounding box
- Returns
iou – The calculated IoU value.
- Return type
float
- vodet.detect.nms(bboxes: list, scores: list, labels: list, iou_threshold: float) -> (<class 'list'>, <class 'list'>)¶
Non-Maximum Suppression
- Parameters
bboxes (list of tuple) – A list of bounding boxes each contains x1, y1, x2, y2.
scores (list of float) – A list of confidence scores of each bounding box.
labels (list of str) – A list of label names of each bounding box.
- Returns
new_bboxes (list of tuple) – A list of survived bounding boxes.
new_labels (list of str) – A list of label names for new_bboxes.