Skip to content

Commit

Permalink
update cog predict
Browse files Browse the repository at this point in the history
  • Loading branch information
xinntao committed Sep 12, 2022
1 parent d226e86 commit 3fd33ab
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions cog_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def setup(self):
if not os.path.exists('gfpgan/weights/GFPGANv1.4.pth'):
os.system(
'wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth -P ./gfpgan/weights')
if not os.path.exists('gfpgan/weights/RestoreFormer.pth'):
os.system(
'wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/RestoreFormer.pth -P ./gfpgan/weights'
)
if not os.path.exists('gfpgan/weights/CodeFormer.pth'):
os.system(
'wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/CodeFormer.pth -P ./gfpgan/weights')

# background enhancer with RealESRGAN
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
Expand All @@ -64,11 +71,18 @@ def predict(
img: Path = Input(description='Input'),
version: str = Input(
description='GFPGAN version. v1.3: better quality. v1.4: more details and better identity.',
choices=['v1.2', 'v1.3', 'v1.4'],
choices=['v1.2', 'v1.3', 'v1.4', 'RestoreFormer', 'CodeFormer'],
default='v1.4'),
scale: float = Input(description='Rescaling factor', default=2)
scale: float = Input(description='Rescaling factor', default=2),
weight: float = Input(
description='Weight, only for CodeFormer. 0 for better quality, 1 for better identity',
default=0.5,
ge=0,
le=1.0)
) -> Path:
print(img, version, scale)
if not isinstance(weight, (int, float)):
weight = 0.5
print(img, version, scale, weight)
try:
extension = os.path.splitext(os.path.basename(str(img)))[1]
img = cv2.imread(str(img), cv2.IMREAD_UNCHANGED)
Expand Down Expand Up @@ -109,14 +123,26 @@ def predict(
channel_multiplier=2,
bg_upsampler=self.upsampler)
self.current_version = 'v1.4'
elif version == 'RestoreFormer':
self.face_enhancer = GFPGANer(
model_path='gfpgan/weights/RestoreFormer.pth',
upscale=2,
arch='RestoreFormer',
channel_multiplier=2,
bg_upsampler=self.upsampler)
elif version == 'CodeFormer':
self.face_enhancer = GFPGANer(
model_path='gfpgan/weights/CodeFormer.pth',
upscale=2,
arch='CodeFormer',
channel_multiplier=2,
bg_upsampler=self.upsampler)

try:
_, _, output = self.face_enhancer.enhance(
img, has_aligned=False, only_center_face=False, paste_back=True)
img, has_aligned=False, only_center_face=False, paste_back=True, weight=weight)
except RuntimeError as error:
print('Error', error)
else:
extension = 'png'

try:
if scale != 2:
Expand Down

8 comments on commit 3fd33ab

@amanseerwali
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hlo

@mehedihasanrokon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1706249539142
Face clearly

@mehedihasanrokon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replicate

@mehedihasanrokon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1706249539142
Face Replicate

@ganesh603474
Copy link

@ganesh603474 ganesh603474 commented on 3fd33ab Jan 26, 2024 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suhban
Copy link

@suhban suhban commented on 3fd33ab Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uploading 11.JPG…

@talaganaramu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much Amount

On Fri, 26 Jan, 2024, 11:52 am mehedihasanrokon, @.***> wrote: 1706249539142.jpg (view on web) https://github.com/TencentARC/GFPGAN/assets/142229187/99e6896a-fe45-4965-b653-21228e3a2222 Face Replicate — Reply to this email directly, view it on GitHub <3fd33ab#commitcomment-137838357>, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBCXJ5KZUIMYXJYIGYYUTTDYQNDUBAVCNFSM6AAAAAAZ5FWOZWVHI2DSMVQWIX3LMV43OQ3PNVWWS5CDN5WW2ZLOOQ5TCMZXHAZTQMZVG4 . You are receiving this because you are subscribed to this thread.Message ID: <TencentARC/GFPGAN/commit/3fd33abc47ba796c4ba9e37dbffa1d848fc10c03/137838357 @github.com>

@bishnupadamirda
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uploading IMG_20240228_092240-01.jpeg…

Please sign in to comment.