Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
DiffBIR_pytorch
Commits
6436ad1c
Unverified
Commit
6436ad1c
authored
Sep 16, 2023
by
0x3f3f3f3fun
Committed by
GitHub
Sep 16, 2023
Browse files
Merge pull request #39 from MasahideOkada/fix-output-path
fixed output path for inference_face.py
parents
16bc7657
2ec23e4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
inference_face.py
inference_face.py
+13
-12
No files found.
inference_face.py
View file @
6436ad1c
...
...
@@ -167,17 +167,18 @@ def main() -> None:
face_helper
.
get_face_landmarks_5
(
only_center_face
=
args
.
only_center_face
,
resize
=
640
,
eye_dist_threshold
=
5
)
face_helper
.
align_warp_face
()
os
.
makedirs
(
os
.
path
.
join
(
parent_path
,
'cropped_faces'
),
exist_ok
=
True
)
os
.
makedirs
(
os
.
path
.
join
(
parent_path
,
'restored_imgs'
),
exist_ok
=
True
)
save_path
=
os
.
path
.
join
(
args
.
output
,
os
.
path
.
relpath
(
file_path
,
args
.
input
))
parent_path
,
img_basename
,
_
=
get_file_name_parts
(
save_path
)
os
.
makedirs
(
parent_path
,
exist_ok
=
True
)
os
.
makedirs
(
os
.
path
.
join
(
parent_path
,
'restored_faces'
),
exist_ok
=
True
)
cropped_face_dir
=
os
.
path
.
join
(
args
.
output
,
'cropped_faces'
)
restored_face_dir
=
os
.
path
.
join
(
args
.
output
,
'restored_faces'
)
restored_img_dir
=
os
.
path
.
join
(
args
.
output
,
'restored_imgs'
)
_
,
img_basename
,
_
=
get_file_name_parts
(
file_path
)
if
not
args
.
has_aligned
:
os
.
makedirs
(
cropped_face_dir
,
exist_ok
=
True
)
os
.
makedirs
(
restored_img_dir
,
exist_ok
=
True
)
os
.
makedirs
(
restored_face_dir
,
exist_ok
=
True
)
for
i
in
range
(
args
.
repeat_times
):
basename
=
f
'
{
img_basename
}
_
{
i
}
'
if
i
else
img_basename
restored_img_path
=
os
.
path
.
join
(
parent_path
,
'
restored_img
s'
,
f
'
{
basename
}
.
{
img_save_ext
}
'
)
if
os
.
path
.
exists
(
restored_img_path
)
or
os
.
path
.
exists
(
os
.
path
.
join
(
parent_path
,
'
restored_face
s'
,
f
'
{
basename
}
.
{
img_save_ext
}
'
)):
restored_img_path
=
os
.
path
.
join
(
restored_img
_dir
,
f
'
{
basename
}
.
{
img_save_ext
}
'
)
if
os
.
path
.
exists
(
restored_img_path
)
or
os
.
path
.
exists
(
os
.
path
.
join
(
restored_face
_dir
,
f
'
{
basename
}
.
{
img_save_ext
}
'
)):
if
args
.
skip_if_exist
:
print
(
f
"Exists, skip face image
{
basename
}
..."
)
continue
...
...
@@ -233,7 +234,7 @@ def main() -> None:
for
idx
,
(
cropped_face
,
restored_face
)
in
enumerate
(
zip
(
face_helper
.
cropped_faces
,
face_helper
.
restored_faces
)):
# save cropped face
if
not
args
.
has_aligned
:
save_crop_path
=
os
.
path
.
join
(
parent_path
,
'
cropped_face
s'
,
f
'
{
basename
}
_
{
idx
:
02
d
}
.
{
img_save_ext
}
'
)
save_crop_path
=
os
.
path
.
join
(
cropped_face
_dir
,
f
'
{
basename
}
_
{
idx
:
02
d
}
.
{
img_save_ext
}
'
)
Image
.
fromarray
(
cropped_face
).
save
(
save_crop_path
)
# save restored face
if
args
.
has_aligned
:
...
...
@@ -242,7 +243,7 @@ def main() -> None:
restored_face
=
restored_face
[:
lq_resized
.
height
,
:
lq_resized
.
width
,
:]
else
:
save_face_name
=
f
'
{
basename
}
_
{
idx
:
02
d
}
.
{
img_save_ext
}
'
save_restore_path
=
os
.
path
.
join
(
parent_path
,
'
restored_face
s'
,
save_face_name
)
save_restore_path
=
os
.
path
.
join
(
restored_face
_dir
,
save_face_name
)
Image
.
fromarray
(
restored_face
).
save
(
save_restore_path
)
# save restored whole image
...
...
@@ -251,7 +252,7 @@ def main() -> None:
restored_img
=
restored_img
[:
lq_resized
.
height
,
:
lq_resized
.
width
,
:]
# save restored image
Image
.
fromarray
(
restored_img
).
resize
(
lq
.
size
,
Image
.
LANCZOS
).
convert
(
"RGB"
).
save
(
restored_img_path
)
print
(
f
"Face image
{
basename
}
saved to
{
p
ar
ent_path
}
"
)
print
(
f
"Face image
{
basename
}
saved to
{
ar
gs
.
output
}
"
)
if
__name__
==
"__main__"
:
...
...
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