Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficientdet #261

Merged
merged 15 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions docs/structure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from paz.backend import angles
from paz.backend import boxes
from paz.backend import anchors
from paz.backend import camera
from paz.backend import render
from paz.backend import keypoints
Expand Down Expand Up @@ -58,11 +59,29 @@
boxes.to_one_hot,
boxes.to_normalized_coordinates,
boxes.to_corner_form,
boxes.extract_bounding_box_corners
boxes.extract_bounding_box_corners,
boxes.scale_box
],
},


{
'page': 'backend/anchors.md',
'functions': [
anchors.build_anchors,
anchors.build_octaves,
anchors.build_aspect,
anchors.build_scales,
anchors.build_strides,
anchors.make_branch_boxes,
anchors.compute_box_coordinates,
anchors.build_base_anchor,
anchors.compute_aspect_size,
anchors.compute_anchor_dims,
anchors.compute_anchor_centres
],
},

{
'page': 'backend/keypoints.md',
'functions': [
Expand Down Expand Up @@ -190,7 +209,8 @@
image.get_rotation_matrix,
image.calculate_image_center,
image.get_affine_transform,
image.get_scaling_factor
image.get_scaling_factor,
image.scale_resize
],
},

Expand Down Expand Up @@ -262,7 +282,15 @@
'functions': [
models.detection.SSD300,
models.detection.SSD512,
models.detection.HaarCascadeDetector
models.detection.HaarCascadeDetector,
models.detection.EFFICIENTDETD0,
models.detection.EFFICIENTDETD1,
models.detection.EFFICIENTDETD2,
models.detection.EFFICIENTDETD3,
models.detection.EFFICIENTDETD4,
models.detection.EFFICIENTDETD5,
models.detection.EFFICIENTDETD6,
models.detection.EFFICIENTDETD7,
],
},

Expand Down Expand Up @@ -395,7 +423,9 @@
processors.ReplaceLowerThanThreshold,
processors.GetNonZeroValues,
processors.GetNonZeroArguments,
processors.FlipLeftRightImage
processors.FlipLeftRightImage,
processors.DivideStandardDeviationImage,
processors.ScaledResize
]
},

Expand Down Expand Up @@ -454,7 +484,13 @@
processors.NonMaximumSuppressionPerClass,
processors.FilterBoxes,
processors.OffsetBoxes2D,
processors.CropImage
processors.CropImage,
processors.BoxesToBoxes2D,
processors.BoxesWithOneHotVectorsToBoxes2D,
processors.BoxesWithClassArgToBoxes2D,
processors.RoundBoxes,
processors.RemoveClass,
processors.ScaleBox
]
},

Expand Down Expand Up @@ -590,7 +626,9 @@
pipelines.DetectSingleShot,
pipelines.DetectHaarCascade,
pipelines.SSD512HandDetection,
pipelines.SSD512MinimalHandPose
pipelines.SSD512MinimalHandPose,
pipelines.SSDPreprocess,
pipelines.SSDPostprocess
]
},

Expand Down
82 changes: 0 additions & 82 deletions examples/efficientdet/boxes.py

This file was deleted.

49 changes: 19 additions & 30 deletions examples/efficientdet/detection.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import numpy as np
from paz import processors as pr
import paz.processors as pr
from paz.abstract import SequentialProcessor, Processor
from paz.pipelines.detection import (DetectSingleShot, SSDPreprocess,
SSDPostprocess)
from efficientdet import (EFFICIENTDETD0, EFFICIENTDETD1, EFFICIENTDETD2,
EFFICIENTDETD3, EFFICIENTDETD4, EFFICIENTDETD5,
EFFICIENTDETD6, EFFICIENTDETD7)
from processors import (DivideStandardDeviationImage, ScaledResize, ScaleBox,
NonMaximumSuppressionPerClass, FilterBoxes,
ToBoxes2D, RemoveClass, RoundBoxes)

B_IMAGENET_STDEV, G_IMAGENET_STDEV, R_IMAGENET_STDEV = 57.3, 57.1, 58.4
RGB_IMAGENET_STDEV = (R_IMAGENET_STDEV, G_IMAGENET_STDEV, B_IMAGENET_STDEV)
from paz.pipelines.detection import DetectSingleShot
from paz.models import (EFFICIENTDETD0, EFFICIENTDETD1, EFFICIENTDETD2,
EFFICIENTDETD3, EFFICIENTDETD4, EFFICIENTDETD5,
EFFICIENTDETD6, EFFICIENTDETD7)


class DetectSingleShotEfficientDet(Processor):
Expand Down Expand Up @@ -65,12 +58,12 @@ class EfficientDetPreprocess(SequentialProcessor):
per channel on ImageNet.
"""
def __init__(self, model, mean=pr.RGB_IMAGENET_MEAN,
standard_deviation=RGB_IMAGENET_STDEV):
standard_deviation=pr.RGB_IMAGENET_STDEV):
super(EfficientDetPreprocess, self).__init__()
self.add(pr.CastImage(float))
self.add(pr.SubtractMeanImage(mean=mean))
self.add(DivideStandardDeviationImage(standard_deviation))
self.add(ScaledResize(image_size=model.input_shape[1]))
self.add(pr.DivideStandardDeviationImage(standard_deviation))
self.add(pr.ScaledResize(image_size=model.input_shape[1]))


class EfficientDetPostprocess(Processor):
Expand All @@ -93,18 +86,17 @@ def __init__(self, model, class_names, score_thresh, nms_thresh,
self.postprocess = pr.SequentialProcessor([
pr.Squeeze(axis=None),
pr.DecodeBoxes(model.prior_boxes, variances),
RemoveClass(class_names, class_arg)])
self.scale = ScaleBox()
self.nms_per_class = NonMaximumSuppressionPerClass(nms_thresh)
self.filter_boxes = FilterBoxes(score_thresh)
self.to_boxes2D = ToBoxes2D(class_names)
self.round_boxes = RoundBoxes()

def call(self, output, image_scales):
pr.RemoveClass(class_names, class_arg)])
self.scale = pr.ScaleBox()
self.nms_per_class = pr.NonMaximumSuppressionPerClass(
nms_thresh, conf_thresh=score_thresh)
self.to_boxes2D = pr.ToBoxes2D(class_names)
self.round_boxes = pr.RoundBoxes2D()

def call(self, output, image_scale):
box_data = self.postprocess(output)
box_data = self.scale(box_data, image_scales)
box_data, class_data = self.nms_per_class(box_data)
box_data = self.filter_boxes(box_data, class_data)
box_data = self.scale(box_data, image_scale)
box_data = self.nms_per_class(box_data)
boxes2D = self.to_boxes2D(box_data)
boxes2D = self.round_boxes(boxes2D)
return boxes2D
Expand Down Expand Up @@ -329,11 +321,8 @@ def __init__(self, score_thresh=0.60, nms_thresh=0.45, draw=True):
names = get_class_names('VOC')
model = EFFICIENTDETD0(num_classes=len(names),
base_weights='VOC', head_weights='VOC')
preprocess = SSDPreprocess(model)
postprocess = SSDPostprocess(
model, names, score_thresh, nms_thresh, class_arg=0)
super(EFFICIENTDETD0VOC, self).__init__(
model, names, preprocess, postprocess, draw=draw)
model, names, score_thresh, nms_thresh, draw=draw)


def process_outputs(outputs):
Expand Down
Loading