【问题标题】:Resuing a zip file from google colab从 google colab 抢救一个 zip 文件
【发布时间】:2020-03-15 11:08:59
【问题描述】:

我正在尝试在 Google Colab 上训练 CNN。我有一个包含 50,000 张图像的文件。通过谷歌搜索,我发现使用它们的最佳方法是压缩文件,然后将它们解压缩到笔记本中。这非常乏味,因为解压缩文件夹需要一段时间,而且每次我想运行一个新模型时,我都必须重新解压缩文件夹,这需要大量时间。有没有办法加快这个速度??

from google.colab import drive
drive.mount('/content/drive')
!unzip -uq "/zip folder on drive" -d "/new location folder"

【问题讨论】:

  • 如果它帮助您解决问题,请将答案标记为已接受。

标签: file directory google-colaboratory


【解决方案1】:

Google colab 是具有临时存储空间的临时机器。您只能将驱动器或任何其他云存储连接到 Colab,并编写脚本来自动化流程,以便在每次新笔记本运行时运行。

我使用谷歌云存储,每当我需要处理它时,我都会将它安装在 colab 中。

这将比从记事本通过 GUI 上传和下载要快一些。

将您的谷歌驱动器安装到 colab 的代码是

from google.colab import drive
drive.mount('/content/drive')

这是一个复制的例子

!cp -r /content/gdrive/My\ Drive/headTrainingDatastructure/eval /content/models/research/object_detection/

【讨论】:

  • 所以在将驱动器挂载到colab之后,您只需将驱动器中的文件复制到您正在使用的本地colab中?
  • 您能否详细解释一下在复制部分代码时发生了什么?
  • 您可以将 zip 从 Google 驱动器移动到 colab 的运行时存储。然后在那里解压。这减少了时间。我已经给出了一个你可以使用的复制命令的例子。
  • 我不明白的是“/content/gdrive/My\ Drive/headTrainingDatastructure/eval /content/models/research/object_detection/
  • 这是一个示例路径。我用它来强调如何处理带有空格的文件夹。
【解决方案2】:

对于任何想知道如何做到这一点的人......

首先,压缩包含图片的文件并上传到 Google 云端硬盘

其次,在 Google Colab 中,挂载您的驱动器

from google.colab import drive
drive.mount('/content/drive')

第三,将zip文件夹复制到本地环境中

!cp "/file path with the zip image folder.zip" "whatever you want to      call the file when unzipped"

第四,在本地colab中解压到你制作的文件夹中

!unzip -uq "whatever you want to call the file when unzipped" -d "folder where you want them unzipped (or just make one up)"

您每次都必须这样做,但与我之前所做的相比,它非常快

【讨论】: