Erwann Millon commited on
Commit
21d692f
1 Parent(s): 61b9782

update state animation

Browse files
Files changed (2) hide show
  1. ImageState.py +8 -6
  2. animation.py +18 -17
ImageState.py CHANGED
@@ -50,20 +50,22 @@ class ImageState:
50
  "./latent_vectors/asian10.pt", map_location=self.device
51
  )
52
 
53
- def create_gif(self, total_duration, extend_frames, gif_name="face_edit.gif"):
 
 
54
  images = []
55
- folder = self.img_dir
56
- paths = glob.glob(folder + "/*")
57
  frame_duration = total_duration / len(paths)
58
  print(len(paths), "frame dur", frame_duration)
59
  durations = [frame_duration] * len(paths)
60
  if extend_frames:
61
  durations[0] = 1.5
62
  durations[-1] = 3
63
- for file_name in os.listdir(folder):
64
  if file_name.endswith(".png"):
65
- file_path = os.path.join(folder, file_name)
66
- images.append(imageio.imread(file_path))
67
  imageio.mimsave(gif_name, images, duration=durations)
68
  return gif_name
69
 
 
50
  "./latent_vectors/asian10.pt", map_location=self.device
51
  )
52
 
53
+ def create_gif(
54
+ total_duration, extend_frames, folder="./img_history", gif_name="face_edit.gif"
55
+ ):
56
  images = []
57
+ paths = list(sorted(glob.glob(folder + "/*")))
58
+ print(paths)
59
  frame_duration = total_duration / len(paths)
60
  print(len(paths), "frame dur", frame_duration)
61
  durations = [frame_duration] * len(paths)
62
  if extend_frames:
63
  durations[0] = 1.5
64
  durations[-1] = 3
65
+ for file_name in paths:
66
  if file_name.endswith(".png"):
67
+ print(file_name)
68
+ images.append(imageio.imread(file_name))
69
  imageio.mimsave(gif_name, images, duration=durations)
70
  return gif_name
71
 
animation.py CHANGED
@@ -8,23 +8,24 @@ def clear_img_dir(img_dir):
8
  os.remove(filename)
9
 
10
 
11
- def create_gif(
12
- total_duration, extend_frames, folder="./img_history", gif_name="face_edit.gif"
13
- ):
14
- images = []
15
- paths = list(sorted(glob.glob(folder + "/*")))
16
- print(paths)
17
- frame_duration = total_duration / len(paths)
18
- print(len(paths), "frame dur", frame_duration)
19
- durations = [frame_duration] * len(paths)
20
- if extend_frames:
21
- durations[0] = 1.5
22
- durations[-1] = 3
23
- for file_name in paths:
24
- if file_name.endswith(".png"):
25
- images.append(imageio.imread(file_name))
26
- imageio.mimsave(gif_name, images, duration=durations)
27
- return gif_name
 
28
 
29
 
30
  if __name__ == "__main__":
 
8
  os.remove(filename)
9
 
10
 
11
+ # def create_gif(
12
+ # total_duration, extend_frames, folder="./img_history", gif_name="face_edit.gif"
13
+ # ):
14
+ # images = []
15
+ # paths = list(sorted(glob.glob(folder + "/*")))
16
+ # print(paths)
17
+ # frame_duration = total_duration / len(paths)
18
+ # print(len(paths), "frame dur", frame_duration)
19
+ # durations = [frame_duration] * len(paths)
20
+ # if extend_frames:
21
+ # durations[0] = 1.5
22
+ # durations[-1] = 3
23
+ # for file_name in paths:
24
+ # if file_name.endswith(".png"):
25
+ # print(file_name)
26
+ # images.append(imageio.imread(file_name))
27
+ # imageio.mimsave(gif_name, images, duration=durations)
28
+ # return gif_name
29
 
30
 
31
  if __name__ == "__main__":