Skip to content

Commit

Permalink
Comments and unused variables removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Manojkumarmuru committed Oct 20, 2022
1 parent db8ae36 commit 7b91a7f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 77 deletions.
16 changes: 8 additions & 8 deletions examples/efficientdet/debugger.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import tensorflow as tf
# gpus = tf.config.experimental.list_physical_devices('GPU')
# tf.config.experimental.set_memory_growth(gpus[0], True)


import numpy as np
from efficientdet import EFFICIENTDETD0
from paz.datasets import VOC
from paz.abstract import Processor, SequentialProcessor
import tensorflow as tf
from paz import processors as pr
from paz.abstract import Processor, SequentialProcessor
from paz.datasets import VOC

from detection import AugmentDetection
from efficientdet import EFFICIENTDETD0

# gpus = tf.config.experimental.list_physical_devices('GPU')
# tf.config.experimental.set_memory_growth(gpus[0], True)


class ShowBoxes(Processor):
Expand Down
28 changes: 13 additions & 15 deletions examples/efficientdet/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ def call(self, image):
return self.wrap(image, outputs)


class DetectSingleShot(DetectSingleShot):
def __init__(
self, model, class_names, score_thresh, nms_thresh,
mean=pr.BGR_IMAGENET_MEAN, variances=[0.1, 0.1, 0.2, 0.2],
draw=True):
super().__init__(
model, class_names, score_thresh, nms_thresh,
mean, variances, draw)
self.draw_boxes2D = DrawBoxes2D(class_names)


class DrawBoxes2D(pr.DrawBoxes2D):
def __init__(
self, class_names=None, colors=None,
Expand All @@ -131,14 +142,12 @@ def call(self, image, boxes2D):
for box2D in boxes2D:
prediction_parameters = self.compute_prediction_parameters(box2D)
x_min, y_min, x_max, y_max, color, text = prediction_parameters
draw_opaque_box(
image, (x_min, y_min), (x_max, y_max), color)
draw_opaque_box(image, (x_min, y_min), (x_max, y_max), color)
image = make_box_transparent(raw_image, image)
for box2D in boxes2D:
prediction_parameters = self.compute_prediction_parameters(box2D)
x_min, y_min, x_max, y_max, color, text = prediction_parameters
add_box_border(
image, (x_min, y_min), (x_max, y_max), color, 2)
add_box_border(image, (x_min, y_min), (x_max, y_max), color, 2)
text_size = get_text_size(text, self.scale, 1)
(text_W, text_H), _ = text_size
draw_opaque_box(
Expand All @@ -147,14 +156,3 @@ def call(self, image, boxes2D):
put_text(
image, text, (x_min+2, y_min + 17), self.scale, (0, 0, 0), 1)
return image


class DetectSingleShot(DetectSingleShot):
def __init__(
self, model, class_names, score_thresh, nms_thresh,
mean=pr.BGR_IMAGENET_MEAN, variances=[0.1, 0.1, 0.2, 0.2],
draw=True):
super().__init__(
model, class_names, score_thresh, nms_thresh,
mean, variances, draw)
self.draw_boxes2D = DrawBoxes2D(class_names)
3 changes: 0 additions & 3 deletions examples/efficientdet/draw.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import cv2

GREEN = (0, 255, 0)
FONT = cv2.FONT_HERSHEY_SIMPLEX
LINE = cv2.LINE_AA
FILLED = cv2.FILLED


def put_text(image, text, point, scale, color, thickness):
Expand All @@ -20,7 +18,6 @@ def put_text(image, text, point, scale, color, thickness):
# Returns
Numpy array with shape ``[H, W, 3]``. Image with text.
"""
# cv2.putText returns an image in contrast to other drawing cv2 functions.
return cv2.putText(image, text, point, FONT, scale, color, thickness, LINE)


Expand Down
47 changes: 0 additions & 47 deletions examples/efficientdet/efficientdet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,50 +203,3 @@ def test_efficientdet_result(model_input_output_base_path, model,
assert np.all(model()(preprocessed_input).numpy() ==
target_model_output), 'Model result not as expected'
del model

# def test_feature_fusion_sum():
# nodes1 = tf.constant([1, 3])
# nodes2 = tf.constant([1, 3])
# feature_node = FeatureNode(6, [3, 4], 3, True, True, True, False, 'sum',
# None)
# output_node = feature_node.fuse_features([nodes1, nodes2])
# expected_node = tf.constant([2, 6], dtype=tf.int32)
# check_equality = tf.math.equal(output_node, expected_node)
# check_flag = tf.reduce_all(check_equality)
# assert check_flag, 'Feature fusion - \'sum\' mismatch'


# def test_feature_fusion_attention():
# nodes1 = tf.constant([1, 3], dtype=tf.float32)
# nodes2 = tf.constant([1, 3], dtype=tf.float32)
# feature_node = FeatureNode(6, [3, 4], 3, True, True, True, False,
# 'attention', None)
# feature_node.build((10, 128, 128, 3))
# output_node = feature_node.fuse_features([nodes1, nodes2])
# expected_node = tf.constant([1.0, 3.0], dtype=tf.float32)
# check_equality = tf.math.equal(output_node, expected_node)
# check_flag = tf.reduce_all(check_equality)
# assert check_flag, 'Feature fusion - attention method mismatch'


# def test_feature_fusion_fastattention():
# nodes1 = tf.constant([1, 3], dtype=tf.float32)
# nodes2 = tf.constant([1, 3], dtype=tf.float32)
# feature_node = FeatureNode(6, [3, 4], 3, True, True, True, False,
# 'fastattention', None)
# feature_node.build((10, 128, 128, 3))
# output_node = feature_node.fuse_features([nodes1, nodes2])
# expected_node = tf.constant([0.99995005, 2.9998503], dtype=tf.float32)
# check_equality = tf.math.equal(output_node, expected_node)
# check_flag = tf.reduce_all(check_equality)
# assert check_flag, 'Feature fusion - fastattention method mismatch'


# test_efficientdet_model()
# test_efficientnet_model()
# test_efficientnet_bottleneck_block()
# test_efficientnet_se_block()
# test_all_efficientdet_models(get_model_path)
# test_feature_fusion_sum()
# test_feature_fusion_attention()
# test_feature_fusion_fastattention()
7 changes: 4 additions & 3 deletions examples/efficientdet/evaluate_mAP.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os

import tensorflow as tf
from paz.datasets import VOC
from paz.optimization.callbacks import EvaluateMAP
from paz.pipelines import DetectSingleShot
from efficientdet import EFFICIENTDETD0
import tensorflow as tf
import os

from efficientdet import EFFICIENTDETD0

if __name__ == "__main__":
weights_path = "./trained_models/efficientdet-d0/"
Expand Down
1 change: 0 additions & 1 deletion examples/efficientdet/infer_efficientdet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from efficientdet import EFFICIENTDETD0
from utils import raw_images


if __name__ == "__main__":
model = EFFICIENTDETD0(num_classes=21, base_weights='COCO',
head_weights=None)
Expand Down

0 comments on commit 7b91a7f

Please sign in to comment.