kaggle的output没办法直接下载文件夹,倒是可以下载文件,当你的训练模型很多个文件的时候, 一个一个下载太慢了, 所以先将output压缩一下,然后下载就行了
直接在cell中运行此代码即可
import os
import zipfile
import datetime
def file2zip(packagePath, zipPath):
'''
:param packagePath: 文件夹路径
:param zipPath: 压缩包路径
:return:
'''
zip = zipfile.ZipFile(zipPath, 'w', zipfile.ZIP_DEFLATED)
for path, dirNames, fileNames in os.walk(packagePath):
fpath = path.replace(packagePath, '')
for name in fileNames:
fullName = os.path.join(path, name)
name = fpath + '\\' + name
zip.write(fullName, name)
zip.close()
if __name__ == "__main__":
# 文件夹路径
packagePath = '/kaggle/working/'
zipPath = '/kaggle/working/output.zip'
if os.path.exists(zipPath):
os.remove(zipPath)
file2zip(packagePath, zipPath)
print("打包完成")
print(datetime.datetime.utcnow())
下载即可
清空kaggle/working下指定文件夹 直接在cell中运行下面代码
import shutil
import os
if __name__ == '__main__':
path = '/kaggle/working/model'
if os.path.exists(path):
shutil.rmtree(path)
print('删除完成')
else:
print('原本为空')