> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-hi/image-processing/gfpgan-face-restore.md).

# GFPGAN Face Restore

GFPGAN का उपयोग करके फ़ोटो में चेहरे बहाल और सुधारें।

{% hint style="success" %}
सभी उदाहरण GPU सर्वरों पर चलाए जा सकते हैं जिन्हें द्वारा किराए पर लिया गया है [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace).
{% endhint %}

## CLORE.AI पर किराये पर लेना

1. पर जाएँ [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace)
2. GPU प्रकार, VRAM, और मूल्य के अनुसार फ़िल्टर करें
3. चुनें **ऑन-डिमांड** (निश्चित दर) या **स्पॉट** (बिड प्राइस)
4. अपना ऑर्डर कॉन्फ़िगर करें:
   * Docker इमेज चुनें
   * पोर्ट सेट करें (SSH के लिए TCP, वेब UI के लिए HTTP)
   * यदि आवश्यक हो तो एनवायरनमेंट वेरिएबल जोड़ें
   * स्टार्टअप कमांड दर्ज करें
5. भुगतान चुनें: **CLORE**, **BTC**, या **USDT/USDC**
6. ऑर्डर बनाएं और डिप्लॉयमेंट का इंतज़ार करें

### अपने सर्वर तक पहुँचें

* कनेक्शन विवरण में खोजें **मेरे ऑर्डर**
* वेब इंटरफेस: HTTP पोर्ट URL का उपयोग करें
* SSH: `ssh -p <port> root@<proxy-address>`

## GFPGAN क्या है?

GFPGAN (Generative Facial Prior GAN) विशेषज्ञता रखता है:

* पुरानी/क्षतिग्रस्त फ़ोटोज़ की मरम्मत करना
* धुंधले चेहरे सुधारना
* AI-जनित चेहरों में सुधार करना
* कम-रिज़ॉल्यूशन पोर्ट्रेट ठीक करना

## त्वरित तैनाती

**Docker इमेज:**

```
pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
```

**पोर्ट:**

```
22/tcp
7860/http
```

**कमांड:**

```bash
pip install gfpgan gradio && \
python -c "
import gradio as gr
from gfpgan import GFPGANer
import cv2
import numpy as np

restorer = GFPGANer(
    model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth',
    upscale=2,
    arch='clean',
    channel_multiplier=2,
    bg_upsampler=None
)

def restore(image):
    img = np.array(image)
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    _, _, output = restorer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
    output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
    return output

demo = gr.Interface(fn=restore, inputs=gr.Image(), outputs=gr.Image(), title='GFPGAN Face Restorer')
demo.launch(server_name='0.0.0.0', server_port=7860)
"
```

## अपनी सेवा तक पहुँचना

डिप्लॉयमेंट के बाद, अपना खोजें `http_pub` URL में **मेरे ऑर्डर**:

1. जाएँ **मेरे ऑर्डर** पृष्ठ
2. अपने ऑर्डर पर क्लिक करें
3. खोजें `http_pub` URL (उदा., `abc123.clorecloud.net`)

उपयोग करें `https://YOUR_HTTP_PUB_URL` की बजाय `localhost` नीचे दिए उदाहरणों में।

## CLI उपयोग

### इंस्टॉलेशन

```bash
pip install gfpgan
```

### मॉडल डाउनलोड करें

```bash

# फेस रिस्टोरेशन मॉडल डाउनलोड करें
wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth -P ./models

# डिटेक्शन मॉडल डाउनलोड करें
wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/detection_Resnet50_Final.pth -P ./models

# पार्सिंग मॉडल डाउनलोड करें
wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/parsing_parsenet.pth -P ./models
```

### मूल उपयोग

```bash

# एकल छवि बहाल करें
python inference_gfpgan.py -i input.jpg -o results -v 1.4 -s 2

# फ़ोल्डर बहाल करें
python inference_gfpgan.py -i ./inputs -o ./results -v 1.4 -s 2
```

### विकल्प

```bash
python inference_gfpgan.py \
    -i input.jpg \      # इनपुट इमेज/फ़ोल्डर
    -o results \        # आउटपुट फ़ोल्डर
    -v 1.4 \            # GFPGAN संस्करण (1.2, 1.3, 1.4)
    -s 2 \              # अपस्केल फ़ैक्टर
    --bg_upsampler realesrgan \  # बैकग्राउंड अपस्केलर
    --only_center_face  # केवल केंद्र चेहरे को बहाल करें
```

## Python API

### बेसिक फेस रिस्टोरेशन

```python
from gfpgan import GFPGANer
import cv2

# आरंभ करें
restorer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=2,
    arch='clean',
    channel_multiplier=2,
    bg_upsampler=None
)

# छवि लोड करें
img = cv2.imread('photo.jpg')

# चेहरों की बहाली करें
cropped_faces, restored_faces, restored_img = restorer.enhance(
    img,
    has_aligned=False,
    only_center_face=False,
    paste_back=True
)

# परिणाम सेव करें
cv2.imwrite('restored.jpg', restored_img)
```

### बैकग्राउंड सुधार के साथ

```python
from gfpgan import GFPGANer
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
import cv2

# बैकग्राउंड अपस्केलर सेटअप करें
bg_model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
bg_upsampler = RealESRGANer(
    scale=2,
    model_path='RealESRGAN_x2plus.pth',
    model=bg_model,
    half=True
)

# बैकग्राउंड सुधार के साथ फेस रिस्टोरर सेटअप करें
restorer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=2,
    arch='clean',
    channel_multiplier=2,
    bg_upsampler=bg_upsampler
)

# प्रोसेस
img = cv2.imread('old_photo.jpg')
_, _, output = restorer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
cv2.imwrite('enhanced.jpg', output)
```

### केवल चेहरों को प्रोसेस करें (पेस्ट बैक नहीं)

```python

# व्यक्तिगत बहाल किए गए चेहरे प्राप्त करें
cropped_faces, restored_faces, _ = restorer.enhance(
    img,
    has_aligned=False,
    only_center_face=False,
    paste_back=False
)

# प्रत्येक चेहरे को अलग से सेव करें
for i, face in enumerate(restored_faces):
    cv2.imwrite(f'face_{i}.jpg', face)
```

## बैच प्रोसेसिंग

```python
import os
from gfpgan import GFPGANer
import cv2
from tqdm import tqdm

restorer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=2,
    arch='clean',
    channel_multiplier=2
)

input_dir = './old_photos'
output_dir = './restored'
os.makedirs(output_dir, exist_ok=True)

for filename in tqdm(os.listdir(input_dir)):
    if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
        img = cv2.imread(os.path.join(input_dir, filename))

        try:
            _, _, output = restorer.enhance(
                img,
                has_aligned=False,
                only_center_face=False,
                paste_back=True
            )
            cv2.imwrite(os.path.join(output_dir, filename), output)
        except Exception as e:
            print(f"Failed: {filename} - {e}")
```

## CodeFormer (विकल्प)

CodeFormer एक और उत्कृष्ट फेस रिस्टोरर है:

```python

# इंस्टॉलेशन
pip install codeformer-pip

# उपयोग
from codeformer import CodeFormer
import cv2

restorer = CodeFormer()
img = cv2.imread('blurry_face.jpg')
result = restorer.restore(img)
cv2.imwrite('restored.jpg', result)
```

## वीडियो फेस रिस्टोरेशन

```python
import cv2
from gfpgan import GFPGANer
from tqdm import tqdm

restorer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=1,  # वीडियो के लिए मूल आकार रखें
    arch='clean',
    channel_multiplier=2
)

cap = cv2.VideoCapture('video.mp4')
fps = cap.get(cv2.CAP_PROP_FPS)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))

out = cv2.VideoWriter('restored_video.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height))

for _ in tqdm(range(total)):
    ret, frame = cap.read()
    if not ret:
        break

    try:
        _, _, restored = restorer.enhance(frame, paste_back=True)
        out.write(restored)
    except:
        out.write(frame)  # यदि बहाली विफल हो तो मूल रखें

cap.release()
out.release()
```

## API सर्वर

```python
from fastapi import FastAPI, UploadFile
from fastapi.responses import Response
from gfpgan import GFPGANer
import cv2
import numpy as np

app = FastAPI()

restorer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=2,
    arch='clean',
    channel_multiplier=2
)

@app.post("/restore")
async def restore_face(file: UploadFile, upscale: int = 2):
    contents = await file.read()
    nparr = np.frombuffer(contents, np.uint8)
    img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)

    _, _, output = restorer.enhance(img, paste_back=True)

    _, encoded = cv2.imencode('.jpg', output)
    return Response(content=encoded.tobytes(), media_type="image/jpeg")

# चलाएँ: uvicorn server:app --host 0.0.0.0 --port 8000
```

## मॉडल वर्ज़न

| संस्करण | गुणवत्ता   | स्पीड    | नोट्स        |
| ------- | ---------- | -------- | ------------ |
| v1.4    | सर्वोत्तम  | मध्यम    | अनुशंसित     |
| v1.3    | बहुत अच्छा | तेज़     | संतुलन अच्छा |
| v1.2    | अच्छा      | सबसे तेज | पारंपरिक     |

## उपयोग के मामले

### पुरानी फोटो बहाली

```python

# पुरानी फ़ोटो के लिए सर्वश्रेष्ठ सेटिंग्स
restorer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=4,  # पुरानी कम-रिज़ॉल्यूशन फ़ोटो के लिए उच्च अपस्केल
    bg_upsampler=bg_upsampler
)
```

### AI कला सुधार

```python

# चेहरे के आर्टिफैक्ट्स वाले AI-जनित इमेज के लिए
restorer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=1,  # मूल आकार रखें
    only_center_face=True  # मुख्य चेहरे पर ध्यान केंद्रित करें
)
```

### ग्रुप फ़ोटो

```python

# ग्रुप फ़ोटो में सभी चेहरों को प्रोसेस करें
restorer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=2,
    only_center_face=False  # सभी चेहरों को प्रोसेस करें
)
```

## प्रदर्शन

| छवि आकार  | चेहरे | GPU      | समय    |
| --------- | ----- | -------- | ------ |
| 512x512   | 1     | RTX 3090 | \~0.2s |
| 1024x1024 | 1     | RTX 3090 | \~0.3s |
| 1024x1024 | 5     | RTX 3090 | \~0.8s |
| 2048x2048 | 1     | RTX 4090 | \~0.3s |

## समस्याओं का निवारण

### कोई चेहरा नहीं मिला

```python

# डिटेक्शन थ्रेशोल्ड घटाएं
from gfpgan.utils import GFPGANer

# या पहले मैनुअल रूप से चेहरे का क्षेत्र क्रॉप करें
```

### अधिक-स्मूथ परिणाम

* कम फिडेलिटी वज़न के साथ CodeFormer का उपयोग करें
* अल्फा कम्पोज़िटिंग का उपयोग करके मूल के साथ ब्लेंड करें

### VRAM समस्याएँ

```python

# फेस डिटेक्शन के लिए CPU का उपयोग करें
import torch
torch.cuda.empty_cache()

# एक समय में एक-एक करके चेहरे प्रोसेस करें
only_center_face=True
```

## लागत अनुमान

सामान्य CLORE.AI मार्केटप्लेस दरें (2024 के अनुसार):

| GPU       | घंटात्मक दर | दैनिक दर | 4-घंटे सत्र |
| --------- | ----------- | -------- | ----------- |
| RTX 3060  | \~$0.03     | \~$0.70  | \~$0.12     |
| RTX 3090  | \~$0.06     | \~$1.50  | \~$0.25     |
| RTX 4090  | \~$0.10     | \~$2.30  | \~$0.40     |
| A100 40GB | \~$0.17     | \~$4.00  | \~$0.70     |
| A100 80GB | \~$0.25     | \~$6.00  | \~$1.00     |

*कीमतें प्रदाता और मांग के अनुसार बदलती हैं। जाँच करें* [*CLORE.AI मार्केटप्लेस*](https://clore.ai/marketplace) *वर्तमान दरों के लिए।*

**पैसे बचाएँ:**

* उपयोग करें **स्पॉट** लचीले वर्कलोड के लिए मार्केट (अक्सर 30-50% सस्ता)
* भुगतान करें **CLORE** टोकन के साथ
* विभिन्न प्रदाताओं के बीच कीमतों की तुलना करें

## अगले कदम

* [Real-ESRGAN अपस्केलिंग](/guides/guides_v2-hi/image-processing/real-esrgan-upscaling.md)
* Stable Diffusion WebUI
* [AI वीडियो जनरेशन](/guides/guides_v2-hi/video-generation/ai-video-generation.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-hi/image-processing/gfpgan-face-restore.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
