plai-group / flexible-video-diffusion-modeling

MIT License
111 stars 14 forks source link

about video_fvd.py #5

Closed JunyaoHu closed 1 year ago

JunyaoHu commented 1 year ago

Hello. When I try to use your provided code to calculate FVD, the terminal shows a wrong, and I cannot solve it.

tensorflow version is the same as you mentioned in your readme.

tensorflow                   2.8.0
tensorflow-hub               0.12.0

Because I am in China, I can't directly use the code to download the model due to network problems, I only modified the code here to read the model I downloaded manually

https://github.com/plai-group/flexible-video-diffusion-modeling/blob/4c3d78b07fd3cd5dd0019ed5fcac9579813f26ff/improved_diffusion/frechet_video_distance.py#L124-L129

  video_batch_size = int(videos.shape[0])
  assert video_batch_size in [batch_size, -1, None], "Invalid batch size"
  tensor_name = module_scope + "RGB/inception_i3d/Mean:0"
  if not _is_in_graph(tensor_name):
    i3d_model = hub.Module(hub.resolve("./i3d-kinetics-400_1.tar.gz"), name=module_name)
    # i3d_model = hub.Module(hub.resolve(module_spec), name=module_name)
    i3d_model(videos)

I use your command python scripts/video_fvd.py --eval_dir ./results/ema_0.9999_550000/adaptive-hierarchy-2_20_10_1000_36 --num_videos 100, then the i3d-kinetics-400 model will be downloaded by a request for https://tfhub.dev/deepmind/i3d-kinetics-400/1?tf-hub-format=compressed. And then the wrong comes.

Loading 100 files (Carla dataset).
setting test mode
Loading 100 files (Carla dataset).
setting test mode
Traceback (most recent call last):
  File "./scripts/video_fvd.py", line 121, in <module>
    fvd = compute_fvd(test_dataset, sample_dataset, T=model_args.T, num_videos=args.num_videos, batch_size=args.batch_size)
  File "./scripts/video_fvd.py", line 68, in compute_fvd
    fvd_handler = FVD(batch_size=batch_size, T=T, frame_shape=[H, W, C])
  File "./scripts/video_fvd.py", line 40, in __init__
    self.vid_feature_vec = fvd.create_id3_embedding(fvd.preprocess(self.vid, (224, 224)), batch_size=self.batch_size)
  File "./frechet_video_distance.py", line 128, in create_id3_embedding
    i3d_model = hub.Module(hub.resolve("/home/ubuntu11/zzc/code/videoprediction/flexible-video-diffusion-modeling/i3d-kinetics-400_1.tar.gz"), name=module_name)
  File "/home/ubuntu11/anaconda3/envs/pred-vdm/lib/python3.9/site-packages/tensorflow_hub/module.py", line 157, in __init__
    self._spec = as_module_spec(spec)
  File "/home/ubuntu11/anaconda3/envs/pred-vdm/lib/python3.9/site-packages/tensorflow_hub/module.py", line 30, in as_module_spec
    return load_module_spec(spec)
  File "/home/ubuntu11/anaconda3/envs/pred-vdm/lib/python3.9/site-packages/tensorflow_hub/module.py", line 65, in load_module_spec
    return registry.loader(path)
  File "/home/ubuntu11/anaconda3/envs/pred-vdm/lib/python3.9/site-packages/tensorflow_hub/registry.py", line 51, in __call__
    return impl(*args, **kwargs)
  File "/home/ubuntu11/anaconda3/envs/pred-vdm/lib/python3.9/site-packages/tensorflow_hub/native_module.py", line 139, in __call__
    module_def_proto = self._get_module_def_proto(path)
  File "/home/ubuntu11/anaconda3/envs/pred-vdm/lib/python3.9/site-packages/tensorflow_hub/native_module.py", line 130, in _get_module_def_proto
    module_def_proto.ParseFromString(f.read())
  File "/home/ubuntu11/anaconda3/envs/pred-vdm/lib/python3.9/site-packages/tensorflow/python/lib/io/file_io.py", line 114, in read
    self._preread_check()
  File "/home/ubuntu11/anaconda3/envs/pred-vdm/lib/python3.9/site-packages/tensorflow/python/lib/io/file_io.py", line 76, in _preread_check
    self._read_buf = _pywrap_file_io.BufferedInputStream(
tensorflow.python.framework.errors_impl.FailedPreconditionError: ./i3d-kinetics-400_1.tar.gz/tfhub_module.pb; Not a directory

I am not sure why comes tfhub_module.pb; Not a directory, it means I cannot download the model manually?

JunyaoHu commented 1 year ago

Solved. If download the model manually, we need to decompress the tar file, then it can run.

yuyuyuyuyuty commented 3 months ago

Hello, I was wondering if you use tensorflow 2.8.0 Does the following error not occur when tensorflow-hub 0.12.0? i3d_model = hub.Module(hub.resolve("./i3d-kinetics-tensorflow1-400-v1"), name=module_name) AttributeError: module 'tensorflow_hub' has no attribute 'Module'