Skip to content

Conversation

@starkgate
Copy link

On top of issue #1, I encountered a few bugs and crashes when using SensorEffectAugmentation (SEA), which I fixed in these commits. The issues are probably caused by newer versions of the various tools and libraries used by SEA. Either way, I hope this is useful!

### Dockerfile used for augmentation pipeline code
###
FROM gcr.io/tensorflow/tensorflow:latest-gpu
FROM tensorflow/tensorflow:1.15.2-gpu
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gcr.io doesn't host tensorflow dockers anymore

FROM tensorflow/tensorflow:1.15.2-gpu
MAINTAINER Vincent Vanhoucke <vanhoucke@google.com>
RUN pip install scikit-learn scikit-image opencv-python==3.2.0.8
RUN pip install scipy==1.1.0 scikit-learn scikit-image opencv-python==3.2.0.8
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scipy 1.2.0+ removes scipy.imread and probably other functions needed by SEA. It was faster to install an older version than refactor the code for newer scipy

#
# generate the CFA arrays for R,G,B based upon the r pixel location:
#
h = int(im_h / 2)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving h and w as floats causes a crash in np.tile

Comment on lines -9 to +23
flags = tf.app.flags
flags.DEFINE_integer("epoch", 1, "number of epochs; corresponds to number of augmentations to perform on the dataset (i.e., epoch =2 means the dataset will be augmented twice")
flags.DEFINE_integer("batch_size", 2, "The size of batch images; must be a multiple of n and >1")
flags.DEFINE_integer("c_dim", 3, "Dimension of image color. [3]")
#
flags.DEFINE_string("Img_dataset","generator_images","The name (full path) of dataset to augment")
flags.DEFINE_integer("Img_height",512, "The size of the output images to produce [64]")
flags.DEFINE_integer("Img_width", 1024, "The size of the output images to produce. If None, same value as output_height [None]")
flags.DEFINE_boolean("chromab_flag", True, "flag that specifies whether to perform Chromatic aberration augmentation")
flags.DEFINE_boolean("blur_flag", True, "flag that specifies whether to perform Blur augmentation")
flags.DEFINE_boolean("exposure_flag", True, "flag that specifies whether to perform Exposure augmentation")
flags.DEFINE_boolean("noise_flag", True, "flag that specifies whether to perform noise augmentation")
flags.DEFINE_boolean("color_flag", True, "flag that specifies whether to perform color shift augmentation")
flags.DEFINE_boolean("save_aug_params_flag", False, "flag that specifies whether to save aug. parameters for each image")
#
flags.DEFINE_string("input_fname_pattern", "*.png", "Glob pattern of filename of input images [*]")
flags.DEFINE_string("results_dir", "results", "Directory name to save the augmented images [results]")
FLAGS = flags.FLAGS
parser = argparse.ArgumentParser(description='Augment a dataset')
parser.add_argument('-n', type=int, default=1, nargs='?', help='sets the number of augmentations to perform on the dataset i.e., setting n to 2 means the dataset will be augmented twice')
parser.add_argument('-b', '--batch_size', type=int, default=64, nargs='?', help='size of batches; must be a multiple of n and >1')
parser.add_argument('-c', '--channels', type=int, default=3, nargs='?', help='dimension of image color channel (note that any channel >3 will be discarded')
parser.add_argument('-i', '--input', type=str, help='path to the dataset to augment')
parser.add_argument('-o', '--output', type=str, default='results', nargs='?', help='path where the augmented dataset will be saved')
parser.add_argument('--pattern', type=str, default="*.png", nargs='?', help='glob pattern of filename of input images')
parser.add_argument('--image_height', type=int, default=512, nargs='?', help='size of the output images to produce (note that all images will be resized to the specified image_height x image_width)')
parser.add_argument('--image_width', type=int, default=1024, nargs='?', help='size of the output images to produce. If None, same value as output_height')
parser.add_argument('--chromatic_aberration', type=bool, default=False, nargs='?', help='perform chromatic aberration augmentation')
parser.add_argument('--blur', type=bool, default=False, nargs='?', help='perform blur augmentation')
parser.add_argument('--exposure', type=bool, default=False, nargs='?', help='perform exposure augmentation')
parser.add_argument('--noise', type=bool, default=False, nargs='?', help='perform noise augmentation')
parser.add_argument('--colour_shift', type=bool, default=False, nargs='?', help='perform colour shift augmentation')
parser.add_argument('--save_params', type=bool, default=False, nargs='?', help='save augmentation parameters for each image')
args = parser.parse_args()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced tf's deprecated flags with the much more robust argparse. Cleaned up the arguments to hopefully be clearer

input_fname_pattern='*.png', results_dir=None):
def __init__(self, sess, image_height, image_width, batch_size, channels,
input, colour_shift, chromatic_aberration, blur, exposure, noise, save_params,
pattern, output):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaults aren't required with argparse

## construct the graph of the image augmentation architecture
##
print 'building model/graph'
print('building model/graph')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 3 requires parentheses around print

NoiseParams = np.array(out[0][4])
ColorParams = np.array(out[0][5])
## save images
self.save_augmented_final_images(G_output_images, G_batch_files, ChromAbParams, BlurParams, ExpParams, NoiseParams, ColorParams, n)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if/else isn't necessary, the check for save_params is already done is save_augmented_final_images

code_location="/home/u42/Windows/Data/datasets/SensorEffectAugmentation"
input="/home/u42/Documents/mmdetection/data/synth_rocks/train/"
output="/home/u42/Documents/mmdetection/data/synth_rocks/train_augmented/"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factorise paths

from time import gmtime, strftime

pp = pprint.PrettyPrinter()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant