如何在 colab 中解压缩图像文件夹

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

我想在包含大约 9000 张图像的 Devanagari 数据集上训练深度学习模型。由于数据集很大,我想使用 Google colab,因为它支持 GPU。我以 Zip 格式将文件夹从本地计算机上传到 Colab。但是解压缩文件时发生错误。

from google.colab import files    
uploaded = files.upload()
   
for fn in uploaded.keys():
   print('User uploaded file "{name}" with length {length} bytes'.format(name=fn, length=len(uploaded[fn])))

我尝试使用

unzip devanagari-character-dataset.zip
压缩文件,但它会抛出以下错误。

File "<ipython-input-8-92b289004693>", line 1
unzip devanagari-character-dataset.zip
   ^
SyntaxError: invalid syntax

如何解决以上问题。谢谢!

python deep-learning zip google-colaboratory
2个回答
1
投票
import zipfile
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
    zip_ref.extractall(directory_to_extract_to)

0
投票

假设那部分是 python

unzip "devanagari-character-dataset.zip" 

unzip devanagari-character-dataset.zip   

如果您希望它由 pip 安装的东西提供服务,请将其用引号引起来 (然后看@Vaibhav 的回答)

或:可能在它前面加上一个!使它成为一个命令(如果你想让后端像普通命令行一样为它提供服务,由安装了 apt 的东西提供服务)

喜欢

!unzip devanagari-character-dataset.zip 
© www.soinside.com 2019 - 2024. All rights reserved.