View MeanGradientError.py
import tensorflow as tf | |
def MeanGradientError(outputs, targets, weight): | |
filter_x = tf.tile(tf.expand_dims(tf.constant([[-1, -2, -2], [0, 0, 0], [1, 2, 1]], dtype = outputs.dtype), axis = -1), [1, 1, outputs.shape[-1]) | |
filter_x = tf.tile(tf.expand_dims(filter_x, axis = -1), [1, 1, 1, outputs.shape[-1]]) | |
filter_y = tf.tile(tf.expand_dims(tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], dtype = outputs.dtype), axis = -1), [1, 1, targets.shape[-1]]) | |
filter_y = tf.tile(tf.expand_dims(filter_y, axis = -1), [1, 1, 1, targets.shape[-1]]) | |
# output gradient | |
output_gradient_x = tf.math.square(tf.nn.conv2d(outputs, filter_x, strides = 1, padding = 'SAME')) |
View demo.py
import tensorflow | |
from tensorflow.keras.layers import Lambda, Dense, Input | |
from tensorflow.keras.models import Model | |
from tensorflow.keras import backend as K | |
def loss_fn(args): | |
return K.constant(1, dtype = 'float32')# creating model | |
inputs = Input(shape = (784,)) | |
dense1 = Dense(512, activation = 'relu')(inputs) | |
dense2 = Dense(128, activation = 'relu')(dense1) |
View bilinear_interpolate.py
""" | |
linear_interpolate - function to bilinear interpolatation trasformation | |
Parameters: | |
origi_img I/P image input | |
scaled_img I/P scaled image input - 2d array of mapped pixels | |
h_ratio I/P scaling ratio for height | |
w_ratio I/P scaling ratio for width | |
O/P transformed image | |
""" | |
def linear_interpolate(origi_img, scaled_img, h_ratio, w_ratio): |
View nn.py
""" | |
nn - function nearest neigbor to map pixels of scaled images to the original images for image interpolation. By default, assume that scale around (0, 0) | |
Parameters: | |
orgi_img I/P original image input | |
scaled_img I/P scaled image input - 2d array of mapped pixels | |
h_ratio I/P scaling ratio for height | |
w_ratio I/P scaling ratio for width | |
O/P color-filled image | |
""" | |
def nn(origi_img, scaled_img, h_ratio, w_ratio): |
View segmentation_test.py
#test.py | |
#import dependencies | |
import cv2 | |
import os | |
import MoCV | |
""" | |
_segment_image_test - function to test optimal thresholding for image segmentation | |
Parameters: |
View segmentation.py
#segmentation.py | |
""" | |
In Computer Vision, segmentation objects and background could be done by different methods: | |
Intensity-based Segmentation: Thresholding - Based on the intensity of colors in histogram | |
Edge-based Segmentation - Based on edges | |
Region-based Segmentation | |
""" | |
#import dependencies | |
from . import histogram |
View contrastImage.py
def upcontrastImage(image): | |
hist = histogram.histogram(image) | |
stretched_hist = histogram.eq_hist(hist, 256, image.size) | |
enhanced_image = np.zeros(shape = image.shape) | |
height = len(image) | |
width = len(image[0]) | |
for row in range(height): | |
for col in range(width): | |
enhanced_image[row, col] = stretched_hist[image[row, col]] |
View eq_hist.py
def eq_hist(hist, colors, img_size): | |
hist = hist * colors / (2 * img_size) | |
cum_hist = hist.cumsum() #Cummulative histogram | |
equalized_hist = np.floor(cum_hist) | |
return equalized_hist |
View histogram.py
def histogram(img_channel): | |
#hist, _ = np.histogram(im_channele, bins = 256, range = (0, 256)) | |
hist = np.array([0] * 256) | |
height = len(img_channel) | |
width = len(img_channel[0]) | |
for row in range(height): | |
for col in range(width): | |
hist[img_channel[row, col]] += 1 |
View genres.txt
2 tone | |
2-step garage | |
4-beat | |
4x4 garage | |
8-bit | |
acapella | |
acid | |
acid breaks | |
acid house | |
acid jazz |