How to perform custom data augmentation using Tensorflow Object Detection API and tf.estimator?

346 views Asked by At

I'm aware that they are already provided in model.config by using something like:

  data_augmentation_options {
    random_adjust_contrast {
    }
  }

However, I need to perform my own data augmentation methods. Below is the current code I used to train a detector:

config = tf.estimator.RunConfig(model_dir=modelpath, keep_checkpoint_max=2, save_summary_steps=100/5)
train_and_eval_dict = model_lib.create_estimator_and_inputs(
    run_config=config,
    hparams=model_hparams.create_hparams(None),
    pipeline_config_path=pipelinepath,
    train_steps=trainsteps,
    eval_steps=evalsteps)
estimator = train_and_eval_dict['estimator']
train_input_fn = train_and_eval_dict['train_input_fn']
eval_input_fns = train_and_eval_dict['eval_input_fns']
eval_on_train_input_fn = train_and_eval_dict['eval_on_train_input_fn']
predict_input_fn = train_and_eval_dict['predict_input_fn']
train_steps = train_and_eval_dict['train_steps']

train_spec, eval_specs = model_lib.create_train_and_eval_specs(
        train_input_fn,
        eval_input_fns,
        eval_on_train_input_fn,
        predict_input_fn,
        train_steps,
        eval_on_train_data=False)

trainer_estimator = tf.estimator.train_and_evaluate(
    estimator, train_spec, eval_specs[0])

I try to read the train_input_fn with something like this:

iterator = train_input_fn().__iter__()
next_element = iterator.get_next()
x_next = next_element[0]
y_next = next_element[1]
x_true_image_shape = x_next.get('true_image_shape', 0)

I can only obtain the tensor but I do not know how to read the value or even to replace them.

My thought is:

  • Read the train_input_fn.
  • Add my own augmentation methods in each batch.

Is it the right to do so or is there any other way to achieve this goal?

0

There are 0 answers