> 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 चेहरा पुनर्स्थापन

Clore.ai पर GFPGAN का उपयोग करके फ़ोटो में चेहरों को पुनर्स्थापित और बेहतर बनाएँ

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)
   * यदि आवश्यक हो तो environment variables जोड़ें
   * स्टार्टअप कमांड दर्ज करें
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.11.0-cuda12.8-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 चेहरा पुनर्स्थापक')
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"असफल: {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()
```

## एपीआई सर्वर

```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
)
```

### एआई आर्ट संवर्धन

```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.3 सेकंड |
| 1024x1024 | 5     | RTX 3090 | \~0.8s      |
| 2048x2048 | 1     | RTX 4090 | \~0.3 सेकंड |

## समस्या निवारण

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

```python

# कम पहचान थ्रेशहोल्ड
from gfpgan.utils import GFPGANer

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

### अत्यधिक-चिकने परिणाम

* CodeFormer को कम fidelity weight के साथ उपयोग करें
* alpha compositing का उपयोग करके मूल के साथ मिश्रण करें

### 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) *वर्तमान दरों के लिए।*

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

* का उपयोग करें **स्पॉट** बाधित किए जा सकने वाले कार्य के लिए मार्केट — लगभग एक-तिहाई सर्वरों की स्पॉट कीमत ऑन-डिमांड से कम होती है (मध्य \~13% छूट), बाकी उससे मेल खाते हैं
* से भुगतान करें **CLORE** टोकन
* विभिन्न प्रदाताओं के बीच कीमतों की तुलना करें

## अगले चरण

* [Real-ESRGAN अपस्केलिंग](/guides/guides_v2-hi/image-processing/real-esrgan-upscaling.md)
* स्टेबल डिफ्यूजन वेबयूआई
* [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.
