Please add requirements.txt
HRezaei opened this issue · comments
Hi Daniel,
Many thanks for sharing this!
I encountered Module not found: moviepy
error and installed it by !pip install moviepy
, but then this error happens which is most likely because of using a different version than the one in your python env:
Moviepy - Building video video.mp4.
Moviepy - Writing video video.mp4
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[13], line 16
13 image_files = [image_folder+'/'+str(train_index[index])+'.jpg' for index in train_index]
15 clip = moviepy.video.io.ImageSequenceClip.ImageSequenceClip(image_files, fps=fps)
---> 16 clip.write_videofile(video_name+'.mp4')
File /mypython/lib/python3.9/site-packages/decorator.py:232, in fun(*args, **kw)
230 evaldict = dict(_call_=caller, _func_=func)
231 es = ''
--> 232 for i, extra in enumerate(extras):
233 ex = '_e%d_' % i
234 evaldict[ex] = extra
File /mypython/lib/python3.9/site-packages/moviepy/decorators.py:54, in requires_duration(f, clip, *a, **k)
52 raise ValueError("Attribute 'duration' not set")
53 else:
---> 54 return f(clip, *a, **k)
File /mypython/lib/python3.9/site-packages/decorator.py:232, in fun(*args, **kw)
230 evaldict = dict(_call_=caller, _func_=func)
231 es = ''
--> 232 for i, extra in enumerate(extras):
233 ex = '_e%d_' % i
234 evaldict[ex] = extra
File /mypython/lib/python3.9/site-packages/moviepy/decorators.py:135, in use_clip_fps_by_default(f, clip, *a, **k)
130 new_a = [fun(arg) if (name=='fps') else arg
131 for (arg, name) in zip(a, names)]
132 new_kw = {k: fun(v) if k=='fps' else v
133 for (k,v) in k.items()}
--> 135 return f(clip, *new_a, **new_kw)
File /mypython/lib/python3.9/site-packages/decorator.py:232, in fun(*args, **kw)
230 evaldict = dict(_call_=caller, _func_=func)
231 es = ''
--> 232 for i, extra in enumerate(extras):
233 ex = '_e%d_' % i
234 evaldict[ex] = extra
File /mypython/lib/python3.9/site-packages/moviepy/decorators.py:22, in convert_masks_to_RGB(f, clip, *a, **k)
20 if clip.ismask:
21 clip = clip.to_RGB()
---> 22 return f(clip, *a, **k)
File /mypython/lib/python3.9/site-packages/moviepy/video/VideoClip.py:300, in VideoClip.write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, rewrite_audio, remove_temp, write_logfile, verbose, threads, ffmpeg_params, logger)
292 if make_audio:
293 self.audio.write_audiofile(audiofile, audio_fps,
294 audio_nbytes, audio_bufsize,
295 audio_codec, bitrate=audio_bitrate,
296 write_logfile=write_logfile,
297 verbose=verbose,
298 logger=logger)
--> 300 ffmpeg_write_video(self, filename, fps, codec,
301 bitrate=bitrate,
302 preset=preset,
303 write_logfile=write_logfile,
304 audiofile=audiofile,
305 verbose=verbose, threads=threads,
306 ffmpeg_params=ffmpeg_params,
307 logger=logger)
309 if remove_temp and make_audio:
310 if os.path.exists(audiofile):
File /mypython/lib/python3.9/site-packages/moviepy/video/io/ffmpeg_writer.py:213, in ffmpeg_write_video(clip, filename, fps, codec, bitrate, preset, withmask, write_logfile, audiofile, verbose, threads, ffmpeg_params, logger)
211 logfile = None
212 logger(message='Moviepy - Writing video %s\n' % filename)
--> 213 with FFMPEG_VideoWriter(filename, clip.size, fps, codec = codec,
214 preset=preset, bitrate=bitrate, logfile=logfile,
215 audiofile=audiofile, threads=threads,
216 ffmpeg_params=ffmpeg_params) as writer:
218 nframes = int(clip.duration*fps)
220 for t,frame in clip.iter_frames(logger=logger, with_times=True,
221 fps=fps, dtype="uint8"):
File /mypython/lib/python3.9/site-packages/moviepy/video/io/ffmpeg_writer.py:88, in FFMPEG_VideoWriter.__init__(self, filename, size, fps, codec, audiofile, preset, bitrate, withmask, logfile, threads, ffmpeg_params)
77 self.ext = self.filename.split(".")[-1]
79 # order is important
80 cmd = [
81 get_setting("FFMPEG_BINARY"),
82 '-y',
83 '-loglevel', 'error' if logfile == sp.PIPE else 'info',
84 '-f', 'rawvideo',
85 '-vcodec', 'rawvideo',
86 '-s', '%dx%d' % (size[0], size[1]),
87 '-pix_fmt', 'rgba' if withmask else 'rgb24',
---> 88 '-r', '%.02f' % fps,
89 '-an', '-i', '-'
90 ]
91 if audiofile is not None:
92 cmd.extend([
93 '-i', audiofile,
94 '-acodec', 'copy'
95 ])
TypeError: must be real number, not NoneType
Would you please add a requirements.txt to repository or !pip install moviepy==XXX
with the working version to the notebooks?
Thanks in advance!
Hi Hosein,
I am using the following versions of packages:
torch==2.2.1+cu121
matplotlib==3.7.1
sklearn==1.2.2
moviepy==1.0.3
If this doesn't resolve this issue please let me know along with which version of moviepy you are using so I can try and replicate this issue.
Alternatively, you can remove the code that makes the GIF as it is only for illustrative purposes and not really necessary. All you need to do is remove this cell
video_name='video'
fps=10
fps = fps
files = os.listdir(image_folder)
train_index = []
for file in files:
if file[0].isdigit() and file.endswith('.jpg'):
train_index.append(int(file[:-4]))
train_index = np.sort(train_index)
image_files = [image_folder+'/'+str(train_index[index])+'.jpg' for index in train_index]
clip = moviepy.video.io.ImageSequenceClip.ImageSequenceClip(image_files, fps=fps)
clip.write_videofile(video_name+'.mp4')
and change the training cell to the following:
def train_acc():
return torch.mean((torch.argmax(model(iris_dataset['train_input']), dim=1) == iris_dataset['train_label']).float())
def test_acc():
return torch.mean((torch.argmax(model(iris_dataset['test_input']), dim=1) == iris_dataset['test_label']).float())
results = model.train(iris_dataset, opt="Adam", device=device, metrics=(train_acc, test_acc),
loss_fn=torch.nn.CrossEntropyLoss(), steps=100, lamb=0.01, lamb_entropy=10.)
This removes any of the interactions with moviepy. I hope one of these solutions helps :)