Number of images generated using data augmentation with object detection
Asked Answered
O

1

5

I've tried to search the answer in the documentation, the code and here but I had no luck. I'd like to know what is the final number of images that are generated by the data augmentation using the object detection API in Tensorflow. For the sake of clarity I'd put an example: let's say that I have a dataset with 2 classes, each one of then with 50 images originally. Then I apply this config:

  data_augmentation_options {
    ssd_random_crop {
    }
  }

  data_augmentation_options {
    random_rgb_to_gray {
    }
  }

  data_augmentation_options {
    random_distort_color {
    }
  }

  data_augmentation_options {
    ssd_random_crop_pad_fixed_aspect_ratio {
    }
  }

How can I know the final number of images generated to train my model? (if there is a way). BTW, I'm using model_main.py to train my model.

Thanks in advance.

Orten answered 21/3, 2019 at 11:45 Comment(0)
A
6

In file inputs.py, it can be seen in function augment_input_fn that all data augmentation options are passed to preprocessor.preprocess method. The details are all in file preprocessor.py, specifically in function preprocess:

for option in preprocess_options:
  func, params = option
  if func not in func_arg_map:
    raise ValueError('The function %s does not exist in func_arg_map' %
                   (func.__name__))
  arg_names = func_arg_map[func]
  for a in arg_names:
    if a is not None and a not in tensor_dict:
      raise ValueError('The function %s requires argument %s' %
                     (func.__name__, a))

  def get_arg(key):
    return tensor_dict[key] if key is not None else None

  args = [get_arg(a) for a in arg_names]
  if (preprocess_vars_cache is not None and
      'preprocess_vars_cache' in inspect.getargspec(func).args):
    params['preprocess_vars_cache'] = preprocess_vars_cache
  results = func(*args, **params)
  if not isinstance(results, (list, tuple)):
    results = (results,)
  # Removes None args since the return values will not contain those.
  arg_names = [arg_name for arg_name in arg_names if arg_name is not None]
  for res, arg_name in zip(results, arg_names):
    tensor_dict[arg_name] = res

Note that in the above code, arg_names contain all the original image names, that means each augmentation option will only be performed on the original images (not on those obtained after previous augmentation options).

Also in preprocessor.py, we can see each augmentation option will produce only an image of the same shape as the original image.

So as a result, in your case, four options and 100 original images, 400 augmented images will be added to tensor_dict.

Aggression answered 21/3, 2019 at 12:51 Comment(3)
Thanks so much for the code leading. It was really helpful.Orten
This post is helpful but the last sentence is not correct. The length of tensor_dict does not change as a result of the augmentations. However, the spirit is true. The input function generates a continuous stream of images and related objects (e.g. boxes). If your augmentations occur randomly (not forced to occur all the time), and your process runs long enough, you will get all types of augmentations, in addition to non-augmented images.Prober
How to find out number of augmented images from STDOUT? Is there a way to find out? Also, is there a way to see augmented images?Nostril

© 2022 - 2024 — McMap. All rights reserved.