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
09cc72da
Commit
09cc72da
authored
Mar 03, 2021
by
sr9
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
additional cli
parent
adc0516d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
12 deletions
+26
-12
model.py
model.py
+9
-5
test.py
test.py
+17
-7
No files found.
model.py
View file @
09cc72da
...
...
@@ -87,18 +87,22 @@ class Generator(nn.Module):
nn
.
Tanh
()
)
def
forward
(
self
,
input
):
def
forward
(
self
,
input
,
align_corners
=
True
):
out
=
self
.
block_a
(
input
)
half_size
=
out
.
size
()[
-
2
:]
out
=
self
.
block_b
(
out
)
out
=
self
.
block_c
(
out
)
out
=
F
.
interpolate
(
out
,
half_size
,
mode
=
"bilinear"
,
align_corners
=
True
)
# out = F.interpolate(out, scale_factor=2, mode="bilinear", align_corners=False)
if
align_corners
:
out
=
F
.
interpolate
(
out
,
half_size
,
mode
=
"bilinear"
,
align_corners
=
True
)
else
:
out
=
F
.
interpolate
(
out
,
scale_factor
=
2
,
mode
=
"bilinear"
,
align_corners
=
False
)
out
=
self
.
block_d
(
out
)
out
=
F
.
interpolate
(
out
,
input
.
size
()[
-
2
:],
mode
=
"bilinear"
,
align_corners
=
True
)
# out = F.interpolate(out, scale_factor=2, mode="bilinear", align_corners=False)
if
align_corners
:
out
=
F
.
interpolate
(
out
,
input
.
size
()[
-
2
:],
mode
=
"bilinear"
,
align_corners
=
True
)
else
:
out
=
F
.
interpolate
(
out
,
scale_factor
=
2
,
mode
=
"bilinear"
,
align_corners
=
False
)
out
=
self
.
block_e
(
out
)
out
=
self
.
out_layer
(
out
)
...
...
test.py
View file @
09cc72da
...
...
@@ -11,15 +11,16 @@ torch.backends.cudnn.enabled = False
torch
.
backends
.
cudnn
.
benchmark
=
False
torch
.
backends
.
cudnn
.
deterministic
=
True
def
load_image
(
image_path
):
def
load_image
(
image_path
,
x32
=
False
):
img
=
cv2
.
imread
(
image_path
)
.
astype
(
np
.
float32
)
img
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
)
h
,
w
=
img
.
shape
[:
2
]
def
to_32s
(
x
):
return
256
if
x
<
256
else
x
-
x
%
32
if
x32
:
# resize image to multiple of 32s
def
to_32s
(
x
):
return
256
if
x
<
256
else
x
-
x
%
32
img
=
cv2
.
resize
(
img
,
(
to_32s
(
w
),
to_32s
(
h
)))
img
=
cv2
.
resize
(
img
,
(
to_32s
(
w
),
to_32s
(
h
)))
img
=
torch
.
from_numpy
(
img
)
img
=
img
/
127.5
-
1.0
return
img
...
...
@@ -36,14 +37,14 @@ def test(args):
os
.
makedirs
(
args
.
output_dir
,
exist_ok
=
True
)
for
image_name
in
sorted
(
os
.
listdir
(
args
.
input_dir
)):
if
os
.
path
.
splitext
(
image_name
)[
-
1
]
not
in
[
".jpg"
,
".png"
,
".bmp"
,
".tiff"
]:
if
os
.
path
.
splitext
(
image_name
)[
-
1
]
.
lower
()
not
in
[
".jpg"
,
".png"
,
".bmp"
,
".tiff"
]:
continue
image
=
load_image
(
os
.
path
.
join
(
args
.
input_dir
,
image_name
))
image
=
load_image
(
os
.
path
.
join
(
args
.
input_dir
,
image_name
)
,
args
.
x32
)
with
torch
.
no_grad
():
input
=
image
.
permute
(
2
,
0
,
1
)
.
unsqueeze
(
0
)
.
to
(
device
)
out
=
net
(
input
)
.
squeeze
(
0
)
.
permute
(
1
,
2
,
0
)
.
cpu
()
.
numpy
()
out
=
net
(
input
,
args
.
upsample_align
)
.
squeeze
(
0
)
.
permute
(
1
,
2
,
0
)
.
cpu
()
.
numpy
()
out
=
(
out
+
1
)
*
127.5
out
=
np
.
clip
(
out
,
0
,
255
)
.
astype
(
np
.
uint8
)
...
...
@@ -74,6 +75,15 @@ if __name__ == '__main__':
type
=
str
,
default
=
'cuda:0'
,
)
parser
.
add_argument
(
'--upsample_align'
,
type
=
bool
,
default
=
False
,
)
parser
.
add_argument
(
'--x32'
,
action
=
"store_true"
,
)
args
=
parser
.
parse_args
()
test
(
args
)
...
...
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