首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PyAV未安装错误,但已安装(GoogleColab)

PyAV未安装错误,但已安装(GoogleColab)
EN

Stack Overflow用户
提问于 2020-05-09 10:20:47
回答 2查看 2.2K关注 0票数 2

我试图使用以下方法导入ucf101数据集

代码语言:javascript
复制
dataset = torchvision.datasets.UCF101('/content/drive/My Drive/Colab Notebooks/ucf101', annotation_path='/content/drive/My Drive/Colab Notebooks/ucfTrainTestlist', frames_per_clip=16, step_between_clips=1, frame_rate=None, fold=1, train=True, transform=transforms.Compose([transforms.ToTensor(),]))

但它给了我这个错误

代码语言:javascript
复制
    ImportError                               Traceback (most recent call last)
<ipython-input-8-2c7f10121439> in <module>()
----> 1 dataset = torchvision.datasets.UCF101('/content/drive/My Drive/Colab Notebooks/ucf101', annotation_path='/content/drive/My Drive/Colab Notebooks/ucfTrainTestlist', frames_per_clip=16, step_between_clips=1, frame_rate=None, fold=1, train=True, transform=transforms.Compose([transforms.ToTensor(),]))

6 frames
/usr/local/lib/python3.6/dist-packages/torchvision/datasets/ucf101.py in __init__(self, root, annotation_path, frames_per_clip, step_between_clips, frame_rate, fold, train, transform, _precomputed_metadata, num_workers, _video_width, _video_height, _video_min_dimension, _audio_samples)
     70             _video_height=_video_height,
     71             _video_min_dimension=_video_min_dimension,
---> 72             _audio_samples=_audio_samples,
     73         )
     74         self.video_clips_metadata = video_clips.metadata

/usr/local/lib/python3.6/dist-packages/torchvision/datasets/video_utils.py in __init__(self, video_paths, clip_length_in_frames, frames_between_clips, frame_rate, _precomputed_metadata, num_workers, _video_width, _video_height, _video_min_dimension, _video_max_dimension, _audio_samples, _audio_channels)
    116 
    117         if _precomputed_metadata is None:
--> 118             self._compute_frame_pts()
    119         else:
    120             self._init_from_metadata(_precomputed_metadata)

/usr/local/lib/python3.6/dist-packages/torchvision/datasets/video_utils.py in _compute_frame_pts(self)
    140 
    141         with tqdm(total=len(dl)) as pbar:
--> 142             for batch in dl:
    143                 pbar.update(1)
    144                 clips, fps = list(zip(*batch))

/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in __next__(self)
    343 
    344     def __next__(self):
--> 345         data = self._next_data()
    346         self._num_yielded += 1
    347         if self._dataset_kind == _DatasetKind.Iterable and \

/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in _next_data(self)
    854             else:
    855                 del self._task_info[idx]
--> 856                 return self._process_data(data)
    857 
    858     def _try_put_index(self):

/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in _process_data(self, data)
    879         self._try_put_index()
    880         if isinstance(data, ExceptionWrapper):
--> 881             data.reraise()
    882         return data
    883 

/usr/local/lib/python3.6/dist-packages/torch/_utils.py in reraise(self)
    393             # (https://bugs.python.org/issue2651), so we work around it.
    394             msg = KeyErrorMessage(msg)
--> 395         raise self.exc_type(msg)

ImportError: Caught ImportError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.6/dist-packages/torchvision/datasets/video_utils.py", line 61, in __getitem__
    return read_video_timestamps(self.x[idx])
  File "/usr/local/lib/python3.6/dist-packages/torchvision/io/video.py", line 318, in read_video_timestamps
    _check_av_available()
  File "/usr/local/lib/python3.6/dist-packages/torchvision/io/video.py", line 40, in _check_av_available
    raise av
ImportError: PyAV is not installed, and is necessary for the video operations in torchvision.
See https://github.com/mikeboers/PyAV#installation for instructions on how to
install PyAV on your system.

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

问题是,我已经安装并导入了上面的一些单元格pyAV。

代码语言:javascript
复制
pip install av
import av
print (av.__version__)
>>8.0.1
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-05-09 11:20:48

在您安装av之后

代码语言:javascript
复制
!pip install av

您需要首先重新启动运行时。

代码语言:javascript
复制
MENU > Runtime > Restart runtime

然后再调用您的代码

代码语言:javascript
复制
import torchvision
dataset = torchvision.datasets.UCF101(...)
票数 2
EN

Stack Overflow用户

发布于 2020-07-31 16:06:11

如果有人对kaggle上的这个问题感到困惑,重新设置会话将不会有帮助(至少在那里进行了测试),因为它将删除安装PyAV的所有进度。

正确的解决方案是首先执行!pip install av,然后执行像import torchvision这样的任何导入。不需要会话重置。

我怀疑(但我太懒于检查)原因是PyAV的可用性是在torchvision验证的早期阶段进行的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61695153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档