构建石头剪刀布手势图像检测ANN时,Google Drive Zip文件解压触发BadZipFile错误的求助
解决BadZipFile错误:Google Drive链接下载问题
嘿,我一眼就揪出问题啦——你用的Google Drive链接是网页预览地址,不是直接下载文件的链接!当你用wget请求这个地址时,下载下来的其实是Google Drive的预览页面HTML,根本不是真正的zip文件,自然会触发BadZipFile错误。
解决步骤:
替换Google Drive链接为直接下载格式
把原来的预览链接:https://drive.google.com/file/d/1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59/view?usp=sharing替换成直接下载链接(提取文件ID
1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59,套入以下格式):https://drive.google.com/uc?export=download&id=1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59修改后的完整代码
import tensorflow as tf !wget --no-check-certificate \ https://drive.google.com/uc?export=download&id=1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59 \ -O /tmp/rockpaperscissors.zip import zipfile,os local_zip = '/tmp/rockpaperscissors.zip' zip_ref = zipfile.ZipFile(local_zip, 'r') zip_ref.extractall('/tmp') zip_ref.close() base_dir = '/tmp/image' train_dir = os.path.join(base_dir, 'train') validation_dir = os.path.join(base_dir, 'val')
额外提示:
如果你的zip文件超过100MB,Google Drive可能会弹出验证页面,这时候可以用下面的命令自动处理验证:
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59" -O /tmp/rockpaperscissors.zip && rm -rf /tmp/cookies.txt
不过你的这个文件应该不大,直接用第一种修改后的链接就足够啦。
内容的提问来源于stack exchange,提问作者Aya
相关产品推荐
相关产品推荐

