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
| <annotation> | |
| <folder>GeneratedData_Train</folder> | |
| <filename>000001.png</filename> | |
| <path>/my/path/GeneratedData_Train/000001.png</path> | |
| <source> | |
| <database>Unknown</database> | |
| </source> | |
| <size> | |
| <width>224</width> | |
| <height>224</height> |
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
| def get_mask_coord(imshape): | |
| vertices = np.array([[(0.09 * imshape[1], 0.99 * imshape[0]), | |
| (0.43 * imshape[1], 0.32 * imshape[0]), | |
| (0.56 * imshape[1], 0.32 * imshape[0]), | |
| (0.85 * imshape[1], 0.99 * imshape[0])]], dtype = np.int32) | |
| return vertices | |
| def get_perspective_matrices(X_img): | |
| offset = 15 | |
| img_size = (X_img.shape[1], X_img.shape[0]) |
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
| import cv2 | |
| def add_gaussian_noise(X_imgs): | |
| gaussian_noise_imgs = [] | |
| row, col, _ = X_imgs[0].shape | |
| # Gaussian distribution parameters | |
| mean = 0 | |
| var = 0.1 | |
| sigma = var ** 0.5 | |
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
| def add_salt_pepper_noise(X_imgs): | |
| # Need to produce a copy as to not modify the original image | |
| X_imgs_copy = X_imgs.copy() | |
| row, col, _ = X_imgs_copy[0].shape | |
| salt_vs_pepper = 0.2 | |
| amount = 0.004 | |
| num_salt = np.ceil(amount * X_imgs_copy[0].size * salt_vs_pepper) | |
| num_pepper = np.ceil(amount * X_imgs_copy[0].size * (1.0 - salt_vs_pepper)) | |
| for X_img in X_imgs_copy: |
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
| from math import pi | |
| def rotate_images(X_imgs, start_angle, end_angle, n_images): | |
| X_rotate = [] | |
| iterate_at = (end_angle - start_angle) / (n_images - 1) | |
| tf.reset_default_graph() | |
| X = tf.placeholder(tf.float32, shape = (None, IMAGE_SIZE, IMAGE_SIZE, 3)) | |
| radian = tf.placeholder(tf.float32, shape = (len(X_imgs))) | |
| tf_img = tf.contrib.image.rotate(X, radian) |
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
| def flip_images(X_imgs): | |
| X_flip = [] | |
| tf.reset_default_graph() | |
| X = tf.placeholder(tf.float32, shape = (IMAGE_SIZE, IMAGE_SIZE, 3)) | |
| tf_img1 = tf.image.flip_left_right(X) | |
| tf_img2 = tf.image.flip_up_down(X) | |
| tf_img3 = tf.image.transpose_image(X) | |
| with tf.Session() as sess: | |
| sess.run(tf.global_variables_initializer()) | |
| for img in X_imgs: |
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
| def rotate_images(X_imgs): | |
| X_rotate = [] | |
| tf.reset_default_graph() | |
| X = tf.placeholder(tf.float32, shape = (IMAGE_SIZE, IMAGE_SIZE, 3)) | |
| k = tf.placeholder(tf.int32) | |
| tf_img = tf.image.rot90(X, k = k) | |
| with tf.Session() as sess: | |
| sess.run(tf.global_variables_initializer()) | |
| for img in X_imgs: | |
| for i in range(3): # Rotation at 90, 180 and 270 degrees |
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
| from math import ceil, floor | |
| def get_translate_parameters(index): | |
| if index == 0: # Translate left 20 percent | |
| offset = np.array([0.0, 0.2], dtype = np.float32) | |
| size = np.array([IMAGE_SIZE, ceil(0.8 * IMAGE_SIZE)], dtype = np.int32) | |
| w_start = 0 | |
| w_end = int(ceil(0.8 * IMAGE_SIZE)) | |
| h_start = 0 | |
| h_end = IMAGE_SIZE |
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
| def central_scale_images(X_imgs, scales): | |
| # Various settings needed for Tensorflow operation | |
| boxes = np.zeros((len(scales), 4), dtype = np.float32) | |
| for index, scale in enumerate(scales): | |
| x1 = y1 = 0.5 - 0.5 * scale # To scale centrally | |
| x2 = y2 = 0.5 + 0.5 * scale | |
| boxes[index] = np.array([y1, x1, y2, x2], dtype = np.float32) | |
| box_ind = np.zeros((len(scales)), dtype = np.int32) | |
| crop_size = np.array([IMAGE_SIZE, IMAGE_SIZE], dtype = np.int32) | |
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
| import tensorflow as tf | |
| import matplotlib.image as mpimg | |
| import numpy as np | |
| IMAGE_SIZE = 224 | |
| def tf_resize_images(X_img_file_paths): | |
| X_data = [] | |
| tf.reset_default_graph() | |
| X = tf.placeholder(tf.float32, (None, None, 3)) |
NewerOlder