Friday, 17 December 2021

string Operation using Python

 Primitive Constructs in Text

  • Sentences/Input strings
  • Words or Tokens
  • Characters
  • The document, larger files

1.split(): 

The split() method splits a string into a list. You can specify the separator, the default separator is any whitespace.















2.len() 

len() is a built-in function in python. You can use the len() to get the length of the given string, array, list, tuple, dictionary, etc.

3.Query to get Specific word on some criteria

Example 1: Find words that are more than 4 letters long








Example2: Find out a string which are starting with a capital letter









Sunday, 13 June 2021

Neural Style Transfer Using Pytorch

The process of transferring an image's aesthetic style to another is known as neural style transfer.  The algorithm takes three images: an input image, a content picture, and a style picture, and modifies the input to match the content of the content image and the artistic style of the style image.

The Basic Principle behind Neural Style Transfer

The basic idea behind neural style transfer is to establish two distance functions: one to describe how different the content of two images is, Lcontent, and another to characterize the difference in style between the two images, Lstyle.Then, given three images: the desired style image, a desired content picture, and the input picture (initialized with the content image), we strive to alter the input image so that its content distant from the content picture and its style distance from the style image are as small as possible.m takes three images: an input image, a content picture, and a style picture, and modifies the input to match the content of the content image and the artistic style of the style image.

Content Image

Style Image


Importing Packages and Selecting a Device

Below is a list of the packages needed to implement the neural transfer

  • torch, torch.nn, numpy (indispensables packages for neural networks with PyTorch)
  • torch.optim (efficient gradient descents)
  • PIL, PIL.Image, matplotlib.pyplot (load and display images)
  • torchvision.transforms (transform PIL images into tensors)
  • torchvision.models (train or load pre-trained models)
  • copy (to deep copy the models; system package)

General steps to perform style transfer:

  1. Visualize data
  2. Basic Preprocessing/preparing our data
  3. Set up loss functions
  4. Create model
  5. Optimize for loss function

Code:

You can find the complete code for this article in the given URL below.

https://www.kaggle.com/smitasahoo/neural-style-transfer-using-pytorch

💕