Skip to main content

Intro to Generative Adversarial Networks | GANs 001

   GANs consist of three terms Generative Adversarial Network. Let's understand these three terms first. Generative : A Generative Model takes input training sample from some distribution and learns to represents that distribution. Adversarial : It basically means Conflicting or Opposing. Networks : These are basically neural networks. So,Generative Adversarial Networks are deep neural network architecture comprising of two neural networks compete with each other to make a generative model. A GAN consist of two class models : Discriminative Model :- It is the one that discriminate between two different classes of data.It tries to identify real data from fakes created by the generator Generative Model :- The Generator turns noise into an imitation of the data to try to trick the discriminator Mathematically, A Generative Model 'G' to be trained on training data 'X' sampled from some true distribution 'D' is the one which, given some standard random distrib...

How to resize an Image using OpenCV

Media files tends to have a lot of information and processing it need a lot of time and computation. Resizing of image and videos is done to prevent computational strain Resizing is basically modifying the width and height. Many image recognition and machine learning applications benefit from scaling. By Resizing, the training time of a neural network can be significantly reduced.

We'll use CV2.resize() method :-

cv2.resize(src, dsize, interpolation)

  src - takes the input image

  dsize - take the output dimension as input in Tuple

  Interpolation take three method as input

  •  cv2.INTER_AREA : This is used when we need to shrink an image.It is the preferred method
  •  cv2.INTER_CUBIC : A Bicubic method, is slow but more efficient.
  •  cv2.INTER_LINEAR : This is primarily used when zooming is required. This is the default interpolation technique in OpenCV

  The Function defined below will always work for Images, Video and Live Camera Feed.

CODE FOR RESIZING.


import cv2

frame= cv2.imread("cam.jpg") #read the input image

def rescaleFrame(frame,scale_value=0.50):
width = int(frame.shape[1] * scale_value)
height = int(frame.shape[0] * scale_value)
dim = (width,height)

return cv2.resize(frame,dim)

img = rescaleFrame(frame)

cv2.imshow('image',img)
cv2.waitKey(0)

NOTE :

Change the value of 'scale_value' according to your preference it is basically the percent by which you want to change the size of image.

'frame.shape[1] ' - is the width of the input image 

'frame.shape[0] ' - is the height of the input image 



Comments

Popular posts from this blog

Frequently Asked Python Interview Questions - 2 | 2021

What is the difference between List and Tuple in Python?   A list can hold ordered sets of all data types in Python (including another list). A list's elements can be modified after creation. The implication of iterations is time-consuming in the list. Operations like insertion and deletion are better performed and consumes more memory. They are mutable The tuple type is very similar to the list type but the elements cannot be modified after creation (similar to strings). Implications of iterations are much faster in tuples. Elements can be accessed better and consumes less memory.They are immutable. What type of language is Python? Python is a dynamically typed interpreted language. These types of languages are typically referred to as “scripting” languages because code is not compiled to a binary form. By dynamically typed I mean that types do not need to be declared when coding, the interpreter figures them out at runtime. Python is neither a true compiled time nor pure...