TheoVincent commited on
Commit
3c8d18f
·
1 Parent(s): 539609b

gif creation for i-DQN

Browse files
Files changed (2) hide show
  1. .gitignore +1 -6
  2. gif_creation.ipynb +44 -2
.gitignore CHANGED
@@ -160,9 +160,4 @@ cython_debug/
160
  .idea/
161
  .venv/
162
  env/
163
- eaudedqn/
164
- polyprunedqn/
165
- dqn/
166
- eaudecql/
167
- polyprunecql/
168
- cql/
 
160
  .idea/
161
  .venv/
162
  env/
163
+ videos/
 
 
 
 
 
gif_creation.ipynb CHANGED
@@ -11,7 +11,7 @@
11
  "def concatenate_videos_with_labels(video_paths, labels, output_gif_path):\n",
12
  " # Load the video clips\n",
13
  " max_duration = 40 + 8\n",
14
- " clips = [VideoFileClip(f\"{video_path}/-episode-0.mp4\") for video_path in video_paths]\n",
15
  " clips = [clip.subclipped(8, max_duration) for clip in clips]\n",
16
  "\n",
17
  " # Create text clips for each video\n",
@@ -39,7 +39,49 @@
39
  "# Example usage\n",
40
  "video_paths = [\"eaudedqn\", \"polyprunedqn\", \"dqn\", \"eaudecql\", \"polyprunecql\", \"cql\"]\n",
41
  "labels = [[\"EauDeDQN\", 0.83], [\"PolyPruneDQN\", 0.95], [\"DQN\", 0], [\"EauDeCQL\", 0.84], [\"PolyPruneCQL\", 0.95], [\"CQL\", 0]]\n",
42
- "output_gif_path = \"output.gif\"\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  "concatenate_videos_with_labels(video_paths, labels, output_gif_path)"
44
  ]
45
  }
 
11
  "def concatenate_videos_with_labels(video_paths, labels, output_gif_path):\n",
12
  " # Load the video clips\n",
13
  " max_duration = 40 + 8\n",
14
+ " clips = [VideoFileClip(f\"videos/{video_path}/-episode-0.mp4\") for video_path in video_paths]\n",
15
  " clips = [clip.subclipped(8, max_duration) for clip in clips]\n",
16
  "\n",
17
  " # Create text clips for each video\n",
 
39
  "# Example usage\n",
40
  "video_paths = [\"eaudedqn\", \"polyprunedqn\", \"dqn\", \"eaudecql\", \"polyprunecql\", \"cql\"]\n",
41
  "labels = [[\"EauDeDQN\", 0.83], [\"PolyPruneDQN\", 0.95], [\"DQN\", 0], [\"EauDeCQL\", 0.84], [\"PolyPruneCQL\", 0.95], [\"CQL\", 0]]\n",
42
+ "output_gif_path = \"videos/eaudeqn.gif\"\n",
43
+ "concatenate_videos_with_labels(video_paths, labels, output_gif_path)"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": null,
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": [
52
+ "from moviepy import VideoFileClip, clips_array, TextClip, CompositeVideoClip\n",
53
+ "\n",
54
+ "def concatenate_videos_with_labels(video_paths, labels, output_gif_path):\n",
55
+ " # Load the video clips\n",
56
+ " max_duration = 35\n",
57
+ " clips = [VideoFileClip(f\"../../iDQN_project/Atari_i-QN/videos/{video_path}\") for video_path in video_paths]\n",
58
+ " clips = [clip.subclipped(0, max_duration) for clip in clips]\n",
59
+ "\n",
60
+ " # Create text clips for each video\n",
61
+ " text_clips = []\n",
62
+ " for i, label in enumerate(labels):\n",
63
+ " text_label = TextClip(\"Kinnari\", label, font_size=24, color='white', text_align=\"center\", bg_color='black', horizontal_align=\"center\", vertical_align=\"top\", duration=clips[i].duration, margin=(70 - 5 * len(label), 10))\n",
64
+ " text_clips.append(text_label)\n",
65
+ "\n",
66
+ " # Overlay text on each video clip\n",
67
+ " labeled_clips = [\n",
68
+ " CompositeVideoClip([text, clip.with_position((\"center\", \"bottom\"))], size=(clip.w, clip.h + 30))\n",
69
+ " for clip, text in zip(clips, text_clips)\n",
70
+ " ]\n",
71
+ "\n",
72
+ " # Arrange clips in a 2x3 grid\n",
73
+ " final_clip = clips_array([[labeled_clips[0], labeled_clips[1], labeled_clips[2]],\n",
74
+ " [labeled_clips[3], labeled_clips[4], labeled_clips[5]]])\n",
75
+ "\n",
76
+ " # Write the result to a GIF and mp4 file\n",
77
+ " final_clip.write_gif(output_gif_path, fps=10)\n",
78
+ " final_clip.write_videofile(output_gif_path.replace(\".gif\", \".mp4\"), fps=24, codec='libx264')\n",
79
+ "\n",
80
+ "\n",
81
+ "# Example usage\n",
82
+ "video_paths = [\"BankHeist_iiqn.mp4\", \"Centipede_iiqn.mp4\", \"ChopperCommand_iiqn.mp4\", \"BankHeist_idqn.mp4\", \"Centipede_idqn.mp4\", \"ChopperCommand_idqn.mp4\"]\n",
83
+ "labels = [\"\", \"i-IQN\", \"\", \"\", \"i-DQN\", \"\"]\n",
84
+ "output_gif_path = \"videos/i-qn.gif\"\n",
85
  "concatenate_videos_with_labels(video_paths, labels, output_gif_path)"
86
  ]
87
  }