<jupyter_start><jupyter_text>![](https://images.aicrowd.com/raw_images/challenges/banner_file/1019/7150d50451d2b2dffcd1.png)<jupyter_code>!nvidia-smi<jupyter_output><empty_output><jupyter_text>Getting Started with Face Deblurring ChallengeIn this puzzle, we have to de blur the blurred images. This is a starter kit explaining how to download the data and also submit direcly via this notebook. We will be submitting the sample prediction directly in the required format.  AIcrowd code utilities for downloading data for Language Classification  Download the files 💾¶ Download AIcrowd CLIWe will first install aicrowd-cli which will help you download and later make submission directly via the notebook.<jupyter_code>!pip install -q aicrowd-cli<jupyter_output><empty_output><jupyter_text>Login to AIcrowd ㊗¶<jupyter_code>%load_ext aicrowd.magic
%aicrowd login<jupyter_output>Please login here: [34m[1m[4mhttps://api.aicrowd.com/auth/FqYcFOKh8-SnWnTKZKvlnn1DzhberXSxohtatHjSlLg[0m
[32mAPI Key valid[0m
[32mGitlab access token valid[0m
[32mSaved details successfully![0m<jupyter_text>Download Dataset¶We will create a folder name data and download the files there.<jupyter_code>%cd /content
!rm -rf data
!mkdir data
%aicrowd ds dl -c face-de-blurring -o data
!unzip data/train.zip -d data/train > /dev/null
!unzip data/val.zip -d data/val > /dev/null
!unzip data/test.zip -d data/test > /dev/null<jupyter_output><empty_output><jupyter_text>Using GFPGANhttps://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOoscrollTo=ZwH2ifWEYEfJ<jupyter_code># Clone GFPGAN and enter the GFPGAN folder
%cd /content
!rm -rf GFPGAN
!git clone https://github.com/TencentARC/GFPGAN.git
%cd GFPGAN

# Set up the environment
# Install basicsr - https://github.com/xinntao/BasicSR
# We use BasicSR for both training and inference
!pip install basicsr
# Install facexlib - https://github.com/xinntao/facexlib
# We use face detection and face restoration helper in the facexlib package
!pip install facexlib
# Install other depencencies
!pip install -r requirements.txt
!python setup.py develop
!pip install realesrgan  # used for enhancing the background (non-face) regions
# Download the pre-trained model
# !wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P experiments/pretrained_models
# Now we use the V1.3 model for the demo
!wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models<jupyter_output><empty_output><jupyter_text>Importing Libraries:<jupyter_code>import pandas as pd
import numpy as np
import os<jupyter_output><empty_output><jupyter_text>Diving in the dataset 🕵️‍♂️<jupyter_code>train_blur_images = 'data/train/blur'
train_original_images = 'data/train/original'
val_blur_images = 'data/train/blur'
val_original_images = 'data/val/original'
test_blur_images = '/content/data/test/blur'
test_original_images = '/content/data/test/original'<jupyter_output><empty_output><jupyter_text>Predictions with GFPGAN<jupyter_code>!mkdir $test_original_images

%cd /content/GFPGAN
#!rm -rf $test_original_images
!python inference_gfpgan.py -i $test_blur_images -o $test_original_images -v 1.3 -s 1 --bg_upsampler realesrgan<jupyter_output>[1;30;43mA saída de streaming foi truncada nas últimas 5000 linhas.[0m
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing np2qu.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nplku.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nptza.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing npzqk.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nqnao.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nqo81.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nqwjo.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nqyru.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nremt.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nrrfu.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing ns6qp.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nsizw.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing nsx58.jpg ...
	Tile 1/4
	Tile 2/4
	Tile 3/4
	Tile 4/4
Processing ntixl.jpg ...
	Tile 1/4
	Tile 2[...]<jupyter_text>Generating Prediction FileIn this starter kit we will directly be submitting the blurred images. In case you would like to see a submission via baseline model.<jupyter_code>%cd /content/
!mkdir original
!cp -r /content/data/test/original/restored_imgs/* /content/original/
from PIL import Image
import os, sys
from tqdm import tqdm

path = "/content/original/"
dirs = os.listdir(path)

def resize():
    for item in tqdm(dirs):
        if os.path.isfile(path+item):
            im = Image.open(path+item)
            f, e = os.path.splitext(path+item)
            imResize = im.resize((512,512), Image.ANTIALIAS)
            imResize.save(f + '.jpg', 'JPEG', quality=100)

resize()
from google.colab import files
# download the result
print('Download results')
os.system('zip -r download.zip /content/original/')
files.download("download.zip")<jupyter_output><empty_output><jupyter_text>Submitting our PredictionsNote : Please save the notebook before submitting it (Ctrl + S)<jupyter_code>%aicrowd notebook submit -c face-de-blurring -a original --no-verify<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10598992349318903, 'fraction_numerical': 0.03564097779436462, 'mean_word_length': 4.328031809145129, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 42, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '213889', 'license': 'MIT', 'n_tokens_mistral': 2174, 'n_tokens_neox': 1998, 'n_words': 534, 'path': '[Getting_Started_Notebook]_Face_De_Blur.ipynb', 'repo_name': 'ibombonato/aicrowd-blitz-faceimages', 'size': '5359'}