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 numpy import array | |
from scipy.misc import imresize | |
# Takes list of images and provide HR images in form of numpy array | |
def hr_images(images): | |
images_hr = array(images) | |
return images_hr | |
# Takes list of images and provide LR images in form of numpy array | |
def lr_images(images_real , downscale): | |
images = [] |
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 keras.layers.core import Activation | |
from keras.layers.normalization import BatchNormalization | |
from keras.layers.convolutional import UpSampling2D | |
from keras.layers import Input | |
from keras.layers.convolutional import Conv2D, Conv2DTranspose | |
from keras.models import Model | |
from keras.layers.advanced_activations import LeakyReLU, PReLU | |
from keras.layers import add | |
# Residual block |
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 keras.layers import Dense | |
from keras.layers.core import Activation | |
from keras.layers.normalization import BatchNormalization | |
from keras.layers.core import Flatten | |
from keras.layers import Input | |
from keras.layers.convolutional import Conv2D | |
from keras.models import Model | |
from keras.layers.advanced_activations import LeakyReLU | |
def discriminator_block(model, filters, kernel_size, strides): |
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 keras.applications.vgg19 import VGG19 | |
import keras.backend as K | |
from keras.models import Model | |
def vgg_loss(self, y_true, y_pred): | |
vgg19 = VGG19(include_top=False, weights='imagenet', input_shape=self.image_shape) | |
vgg19.trainable = False | |
for l in vgg19.layers: | |
l.trainable = False | |
model = Model(inputs=vgg19.input, outputs=vgg19.get_layer('block5_conv4').output) |
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 keras.models import Model | |
from keras.layers import Input | |
def get_gan_network(discriminator, shape, generator, optimizer, vgg_loss): | |
discriminator.trainable = False | |
gan_input = Input(shape=shape) | |
x = generator(gan_input) | |
gan_output = discriminator(x) | |
gan = Model(inputs=gan_input, outputs=[x,gan_output]) | |
gan.compile(loss=[vgg_loss, "binary_crossentropy"], loss_weights=[1., 1e-3], optimizer=optimizer) |
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_optimizer(): | |
adam = Adam(lr=1E-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08) | |
return adam |
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 tqdm import tqdm | |
import numpy as np | |
# Better to use downscale factor as 4 | |
downscale_factor = 4 | |
# Remember to change image shape if you are having different size of images | |
image_shape = (384,384,3) | |
def train(epochs, batch_size, input_dir, output_dir, model_save_dir, number_of_images, train_test_ratio): | |
# Loads training and test data |
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 | |
cv2.namedWindow("image") | |
cv2.setMouseCallback("image", get_mouse_points) | |
def get_mouse_points(event, x, y, flags, param): | |
global mouse_pts | |
if event == cv2.EVENT_LBUTTONDOWN: | |
if len(mouse_pts) < 4: | |
cv2.circle(image, (x, y), 5, (0, 0, 255), 10) |
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 | |
import numpy as np | |
weightsPath = "path to yolov3.weights" | |
configPath = "path to yolov3.cfg" | |
vid_path = "path to video" | |
net_yl = cv2.dnn.readNetFromDarknet(configPath, weightsPath) | |
ln = net_yl.getLayerNames() | |
ln1 = [ln[i[0] - 1] for i in net_yl.getUnconnectedOutLayers()] |
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 | |
import numpy as np | |
(H, W) = frame.shape[:2] | |
points = mouse_pts | |
# Using first 4 points or coordinates for perspective transformation. The region marked by these 4 points are | |
# considered ROI. This polygon shaped ROI is then warped into a rectangle which becomes the bird eye view. | |
# This bird eye view then has the property property that points are distributed uniformally horizontally and | |
# vertically(scale for horizontal and vertical direction will be different). So for bird eye view points are |
OlderNewer