Tattoo Removal Using Python
Don’t worry if you aren’t able to implement the project right now as the initial few weeks of the course solely consists of R and Python is covered in the closing stages of the course.
We recommend using Pycharm for completing this project to ensure maximum simplicity.

Setup
To set up the programme, you need to install the following libraries:
Name | Function |
---|---|
NumPy | Adds support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. |
PIL(Python Imaging Library) | Adds support for opening, manipulating, and saving many different image file formats. |
FastAI | FastAI is a library that simplifies the training of neural networks. |
URLLib | It is a module that can be used for opening URLs |
TorchVision | The torchvision package consists of popular datasets, model architectures, and common image transformations for computer vision. |
Transform | Returns a self-produced dataframe with transformed values after applying the function specified in its parameter. |
THE CODE
import fastai
from fastai.vision import *
from fastai.utils.mem import *
from fastai.vision import open_image, load_learner, image, torch
import numpy as np
import urllib.request
import PIL.Image
from io import BytesIO
import torchvision.transforms as T
from PIL import Image
import requests
from io import BytesIO
import fastai
from fastai.vision import *
from fastai.utils.mem import *
from fastai.vision import open_image, load_learner, image, torch
import numpy as np
import urllib.request
import PIL.Image
from io import BytesIO
import torchvision.transforms as T
class FeatureLoss(nn.Module):
def __init__(self, m_feat, layer_ids, layer_wgts):
super().__init__()
self.m_feat = m_feat
self.loss_features = [self.m_feat[i] for i in layer_ids]
self.hooks = hook_outputs(self.loss_features, detach=False)
self.wgts = layer_wgts
self.metric_names = ['pixel',] + [f'feat_{i}' for i in range(len(layer_ids))
] + [f'gram_{i}' for i in range(len(layer_ids))]
def make_features(self, x, clone=False):
self.m_feat(x)
return [(o.clone() if clone else o) for o in self.hooks.stored]
def forward(self, input, target):
out_feat = self.make_features(target, clone=True)
in_feat = self.make_features(input)
self.feat_losses = [base_loss(input,target)]
self.feat_losses += [base_loss(f_in, f_out)*w
for f_in, f_out, w in zip(in_feat, out_feat, self.wgts)]
self.feat_losses += [base_loss(gram_matrix(f_in), gram_matrix(f_out))*w**2 * 5e3
for f_in, f_out, w in zip(in_feat, out_feat, self.wgts)]
self.metrics = dict(zip(self.metric_names, self.feat_losses))
return sum(self.feat_losses)
def __del__(self): self.hooks.remove()
MODEL_URL = "https://www.dropbox.com/s/vxgw0s7ktpla4dk/SkinDeep2.pkl?dl=1"
urllib.request.urlretrieve(MODEL_URL, "SkinDeep2.pkl")
path = Path(".")
learn=load_learner(path, 'SkinDeep2.pkl')
url:"https://cdn.sportmob.com/resource/news/20201013_896180/cover.jpg?cache=1602721802"
p,img_hr,b = learn.predict(img_fast)
Image(img_hr).show(figsize=(8,8))