Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
animegan2-pytorch
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
git
animegan2-pytorch
Commits
c78943ef
Commit
c78943ef
authored
Nov 06, 2021
by
xhlulu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add face2paint
parent
4a9c882a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
2 deletions
+31
-2
hubconf.py
hubconf.py
+31
-2
No files found.
hubconf.py
View file @
c78943ef
import
torch
def
animegan2
(
pretrained
=
True
,
device
=
"cpu"
,
progress
=
True
,
check_hash
=
True
):
def
generator
(
pretrained
=
True
,
device
=
"cpu"
,
progress
=
True
,
check_hash
=
True
):
release_url
=
"https://github.com/xhlulu/animegan2-pytorch/releases/download/weights"
known
=
{
name
:
f
"{release_url}/{name}.pt"
...
...
@@ -32,3 +32,32 @@ def animegan2(pretrained=True, device="cpu", progress=True, check_hash=True):
model
.
load_state_dict
(
state_dict
)
return
model
def
face2paint
(
device
=
"cpu"
):
from
PIL
import
Image
from
torchvision.transforms.functional
import
to_tensor
,
to_pil_image
def
face2paint
(
model
:
torch
.
nn
.
Module
,
img
:
Image
.
Image
,
size
:
int
,
side_by_side
:
bool
=
True
,
device
:
str
=
device
,
)
->
Image
.
Image
:
w
,
h
=
img
.
size
s
=
min
(
w
,
h
)
img
=
img
.
crop
(((
w
-
s
)
//
2
,
(
h
-
s
)
//
2
,
(
w
+
s
)
//
2
,
(
h
+
s
)
//
2
))
img
=
img
.
resize
((
size
,
size
),
Image
.
LANCZOS
)
input
=
to_tensor
(
img
)
.
unsqueeze
(
0
)
*
2
-
1
output
=
model
(
input
.
to
(
device
))
.
cpu
()[
0
]
if
side_by_side
:
output
=
torch
.
cat
([
input
[
0
],
output
],
dim
=
2
)
output
=
(
output
*
0.5
+
0.5
)
.
clip
(
0
,
1
)
return
to_pil_image
(
output
)
return
face2paint
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment