Created
August 9, 2023 04:12
-
-
Save rhee-elten/60b6f197fbbb09b71694fd5bca520fcf to your computer and use it in GitHub Desktop.
fasterrcnn 에서 동작하도록 하기 위해서는 keras_cv 에 다음 패치 필요: keras_cv/layers/object_detection/anchor_generator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
fasterrcnn 에서 동작하도록 하기 위해서는 keras_cv 에 다음 패치 필요: | |
keras_cv/layers/object_detection/anchor_generator.py | |
line 258: | |
stride = self.stride | |
# make sure range of `cx` is within limit of `image_width` with | |
# `stride`, also for sizes where `image_width % stride != 0`. | |
# [W] | |
### XXX math.ceil ==> ops.ceil --shr 2023-08-09 | |
cx = ops.cast( | |
ops.arange( | |
# 0.5 * stride, math.ceil(image_width / stride) * stride, stride | |
0.5 * stride, ops.ceil(image_width / stride) * stride, stride | |
), | |
"float32", | |
) | |
# make sure range of `cy` is within limit of `image_height` with | |
# `stride`, also for sizes where `image_height % stride != 0`. | |
# [H] | |
### XXX math.ceil ==> ops.ceil --shr 2023-08-09 | |
cy = ops.cast( | |
ops.arange( | |
# 0.5 * stride, math.ceil(image_height / stride) * stride, stride | |
0.5 * stride, ops.ceil(image_height / stride) * stride, stride | |
), | |
"float32", | |
) | |
"""; | |
if MODEL_TYPE == "fasterrcnn": | |
""" | |
model.predict(image) 호출시에는 다음과 같은 res 반환: | |
{'boxes': <tf.RaggedTensor [[]]>, | |
'confidence': <tf.RaggedTensor [[]]>, | |
'classes': <tf.RaggedTensor [[]]>, | |
'num_detections': array([0], dtype=int32)} | |
""" | |
res = model.predict(images, batch_size=1) | |
print( | |
"model.predict(images) output:", {k: (v.shape, v.dtype) for k, v in res.items()} | |
) | |
num_detections = res["num_detections"] | |
det_boxes = res["boxes"] | |
det_confidence = res["confidence"] | |
det_clsses = res["classes"] | |
print("images:", type(images), images.shape, images.dtype) | |
print( | |
"num_detections:", | |
type(num_detections), | |
num_detections.shape, | |
num_detections.dtype, | |
) | |
print("det_boxes:", type(det_boxes), det_boxes.shape, det_boxes.dtype) | |
print( | |
"det_confidence:", | |
type(det_confidence), | |
det_confidence.shape, | |
det_confidence.dtype, | |
) | |
print("det_clsses:", type(det_clsses), det_clsses.shape, det_clsses.dtype) | |
# num_detections = num_detections.numpy() # num_detections 는 tensor 아님 | |
det_boxes = det_boxes.numpy() | |
det_confidence = det_confidence.numpy() | |
det_clsses = det_clsses.numpy() | |
print( | |
"num_predictions:", | |
num_detections[0], | |
"det_clsses:", | |
det_clsses[0], | |
"det_boxes:", | |
det_boxes[0], | |
"det_confidence:", | |
det_confidence[0], | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment