Skip to content

Commit

Permalink
Fix predictor bug on windows (PaddlePaddle#209)
Browse files Browse the repository at this point in the history
* fix windows bug
  • Loading branch information
LielinJiang authored Mar 3, 2021
1 parent 5b3267b commit 62ce17f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
19 changes: 10 additions & 9 deletions ppgan/apps/dain_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run(self, video_path):

out_path = video2frames(video_path, frame_path_input)

vidname = video_path.split('/')[-1].split('.')[0]
vidname = video_path.split(os.sep)[-1].split('.')[0]

frames = sorted(glob.glob(os.path.join(out_path, '*.png')))

Expand Down Expand Up @@ -122,8 +122,8 @@ def run(self, video_path):
for i in tqdm(range(frame_num - 1)):
first = frames[i]
second = frames[i + 1]
first_index = int(first.split('/')[-1].split('.')[-2])
second_index = int(second.split('/')[-1].split('.')[-2])
first_index = int(first.split(os.sep)[-1].split('.')[-2])
second_index = int(second.split(os.sep)[-1].split('.')[-2])

img_first = imread(first)
img_second = imread(second)
Expand Down Expand Up @@ -224,7 +224,7 @@ def combine_frames(self, input, interpolated, combined, num_frames):

for i in range(num1):
src = frames1[i]
imgname = int(src.split('/')[-1].split('.')[-2])
imgname = int(src.split(os.sep)[-1].split('.')[-2])
assert i == imgname
dst = os.path.join(combined,
'{:08d}.png'.format(i * (num_frames + 1)))
Expand All @@ -249,14 +249,14 @@ def combine_frames_with_rm(self, input, interpolated, combined,

for i in range(num1):
src = frames1[i]
index = int(src.split('/')[-1].split('.')[-2])
index = int(src.split(os.sep)[-1].split('.')[-2])
dst = os.path.join(combined,
'{:08d}.png'.format(times_interp * index))
shutil.copy2(src, dst)

for i in range(num2):
src = frames2[i]
imgname = src.split('/')[-1]
imgname = src.split(os.sep)[-1]
dst = os.path.join(combined, imgname)
shutil.copy2(src, dst)

Expand All @@ -279,9 +279,10 @@ def dhash(image, hash_size=8):

for (h, hashed_paths) in hashes.items():
if len(hashed_paths) > 1:
first_index = int(hashed_paths[0].split('/')[-1].split('.')[-2])
last_index = int(
hashed_paths[-1].split('/')[-1].split('.')[-2]) + 1
first_index = int(hashed_paths[0].split(
os.sep)[-1].split('.')[-2])
last_index = int(hashed_paths[-1].split(
os.sep)[-1].split('.')[-2]) + 1
gap = 2 * (last_index - first_index) - 1
if gap > 2 * max_interp:
cut1 = len(hashed_paths) // 3
Expand Down
8 changes: 4 additions & 4 deletions ppgan/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from .logger import get_logger

PPGAN_HOME = os.path.expanduser("~/.cache/ppgan/")
PPGAN_HOME = os.path.expanduser(os.path.join('~', '.cache', 'ppgan'))

DOWNLOAD_RETRY_LIMIT = 3

Expand Down Expand Up @@ -243,14 +243,14 @@ def _uncompress_file_tar(filepath, mode="r:*"):


def _is_a_single_file(file_list):
if len(file_list) == 1 and file_list[0].find(os.sep) < -1:
if len(file_list) == 1 and file_list[0].find('/') < -1:
return True
return False


def _is_a_single_dir(file_list):
file_name = file_list[0].split(os.sep)[0]
file_name = file_list[0].split('/')[0]
for i in range(1, len(file_list)):
if file_name != file_list[i].split(os.sep)[0]:
if file_name != file_list[i].split('/')[0]:
return False
return True
4 changes: 2 additions & 2 deletions ppgan/utils/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def _dict2str(kargs):
return cmd_str

ffmpeg = ['ffmpeg ', ' -y -loglevel ', ' error ']
vid_name = video_path.split('/')[-1].split('.')[0]
vid_name = video_path.split(os.sep)[-1].split('.')[0]
out_full_path = os.path.join(outpath, vid_name)

if not os.path.exists(out_full_path):
os.makedirs(out_full_path)

# video file name
outformat = out_full_path + '/%08d.png'
outformat = os.path.join(out_full_path, '%08d.png')

cmd = ffmpeg
cmd = ffmpeg + [' -i ', video_path, ' -start_number ', ' 0 ', outformat]
Expand Down

0 comments on commit 62ce17f

Please sign in to comment.