tensorflow / tensorflow/models
Object Detection API: ssd_random_crop_pad_fixed_aspect_ratio incorrect use of min and max_padded_size_ratio
@pkulzc is already working on this.
Since Jun 4, 2020.
- Dominant language
- Python
- Stars
- 77.7k
- Forks
- 44.8k
- PR merge metrics
- No merged PRs in 30d
Description
System information
- What is the top-level directory of the model you are using: /home//models/research/object_detection
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntnu 18.04
- TensorFlow installed from (source or binary): binary, pip
- TensorFlow version (use command below): 1.14
- Bazel version (if compiling from source):
- CUDA/cuDNN version:
- GPU model and memory:
- Exact command to reproduce:
Describe the problem
The documentation for the augmentation ssd_random_crop_pad_fixed_aspect_ratio says that
min_padded_size_ratio: min ratio of padded image height and width to the input image's height and width. max_padded_size_ratio: max ratio of padded image height and width to the input image's height and width.
However, looking at the code in core/preprocessor.py line 3655, the function random_pad_to_aspect_ratio is called on the cropped image. The final result is then incorrect.
Source code / logs
You can run this code from the object_detection directory assuming that lena is your test image. The final result should be 5 times bigger than the original but it is not.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import functools
import os
import cv2
from absl.testing import parameterized
import numpy as np
import tensorflow as tf
from scipy.misc import imsave, imread
from object_detection import inputs
from object_detection.core import preprocessor
from object_detection.core import standard_fields as fields
from object_detection.utils import config_util
from object_detection.utils import test_case
FLAGS = tf.flags.FLAGS
tf.disable_eager_execution()
class DataAugmentationFnTest(test_case.TestCase):
def test_apply_image_and_box_augmentation(self):
data_augmentation_options = [
(preprocessor.ssd_random_crop_pad_fixed_aspect_ratio, {
'min_object_covered': [1.0],
'aspect_ratio': 1.0,
'aspect_ratio_range': [(1.0, 1.0)],
'area_range': [(0.1, 1.0)],
'overlap_thresh': [1.0],
'clip_boxes': [False],
'random_coef': [0.0],
'min_padded_size_ratio': (5.0, 5.0),
'max_padded_size_ratio': (5.0, 5.0)})
]
data_augmentation_fn = functools.partial(
inputs.augment_input_data,
data_augmentation_options=data_augmentation_options)
tensor_dict = {
fields.InputDataFields.image:
tf.constant(imread('lena.png').astype(np.float32)),
fields.InputDataFields.groundtruth_boxes:
tf.constant(np.array([[.5, .5, .51, .51]], np.float32)),
fields.InputDataFields.groundtruth_classes:
tf.constant(np.array([1.0], np.float32))
}
augmented_tensor_dict = data_augmentation_fn(tensor_dict=tensor_dict)
with self.session() as sess:
augmented_tensor_dict_out = sess.run(augmented_tensor_dict)
print("Final Shape" + augmented_tensor_dict_out[fields.InputDataFields.image].shape)
if __name__ == '__main__':
tf.test.main()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.