如何在下载后在colaboratory环境中解压缩特定文件夹中的文件?

问题描述 投票:0回答:1

当我使用GoogleDrive的连接时,我正在寻找解决方案来解决google colab上图像数据集的缓慢上传速度。使用以下代码:

from google.colab import drive

drive.mount('/content/gdrive')

使用此程序,我可以上传图像并使用我的def load_dataset创建标签:

'train_path=content/gdrive/MyDrive/Capstone/Enviroment/cell_images/train'

train_files, train_targets = load_dataset(train_path)

但是,正如我所说,它非常慢,特别是因为我的完整数据集由27560个图像组成。

为了解决我的问题,我试图使用this solution

但现在,为了仍然使用我的deffunction,下载.tar文件后,我想提取在colab环境中的特定文件夹中。我找到了this answer但没有解决我的问题。

例:

这是已下载test.tar的环境。 enter image description here

但我想提取tar文件中的文件,结构是train/Uninfected; train/Parasitized,得到这个:

  • 内容 cell_images 测试 寄生 未感染 培养 寄生 未感染 有效 寄生 未感染

要在def函数中使用路径:

train_path = train_path=content/cell_images/train/'

train_files, train_targets = load_dataset(train_path)

test_path = train_path=content/cell_images/test/'

test_files, test_targets = load_dataset(test_path)

valid_path = train_path=content/cell_images/valid/'

valid_files, valid_targets = load_dataset(valid_path)

我试着用:! mkdir -p content/cell_images!tar -xvf 'test.tar' content/cell_images

但它不起作用。

有谁知道怎么办?

谢谢!

python tar google-colaboratory
1个回答
2
投票

要将文件从tar归档文件解压缩到文件夹content/cell_images,请使用命令行选项-C

!tar -xvf  test.tar -C content/cell_images

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.