我编写了一个python脚本来下载文件,提取文件并训练AI。代码如下:
def maybe_download_and_extract(data_url):
dest_directory = FLAGS.model_dir
if not os.path.exists(dest_directory):
os.makedirs(dest_directory)
filename = data_url.split('/')[-1]
filepath = os.path.join(dest_directory, filename)
if not os.path.exists(filepath):
def _progress(count, block_size, total_size):
sys.stdout.write('\r>> Downloading %s %.1f%%' %
(filename, float(count * block_size) / float(total_size) * 100.0))
sys.stdout.flush()
filepath, _ = urllib.request.urlretrieve(data_url, filepath, _progress)
print()
statinfo = os.stat(filepath)
tf.logging.info('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
tarfile.open(filepath, 'r:gz').extractall(dest_directory)
运行它时,出现此错误:
Traceback (most recent call last):
File "scripts/retrain.py", line 1326, in <module>
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "C:\Users\kulkaa\AppData\Local\conda\conda\envs\mlcc\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
_sys.exit(main(argv))
File "scripts/retrain.py", line 982, in main
maybe_download_and_extract(model_info['data_url'])
File "scripts/retrain.py", line 340, in maybe_download_and_extract
tarfile.open(filepath, 'r:gz').extractall(dest_directory)
File "C:\Users\kulkaa\AppData\Local\conda\conda\envs\mlcc\lib\tarfile.py", line 2010, in extractall
numeric_owner=numeric_owner)
File "C:\Users\kulkaa\AppData\Local\conda\conda\envs\mlcc\lib\tarfile.py", line 2052, in extract
numeric_owner=numeric_owner)
File "C:\Users\kulkaa\AppData\Local\conda\conda\envs\mlcc\lib\tarfile.py", line 2122, in _extract_member
self.makefile(tarinfo, targetpath)
File "C:\Users\kulkaa\AppData\Local\conda\conda\envs\mlcc\lib\tarfile.py", line 2171, in makefile
copyfileobj(source, target, tarinfo.size, ReadError, bufsize)
File "C:\Users\kulkaa\AppData\Local\conda\conda\envs\mlcc\lib\tarfile.py", line 249, in copyfileobj
buf = src.read(bufsize)
File "C:\Users\kulkaa\AppData\Local\conda\conda\envs\mlcc\lib\gzip.py", line 276, in read
return self._buffer.read(size)
File "C:\Users\kulkaa\AppData\Local\conda\conda\envs\mlcc\lib\_compression.py", line 68, in readinto
data = self.read(len(byte_view))
File "C:\Users\kulkaa\AppData\Local\conda\conda\envs\mlcc\lib\gzip.py", line 482, in read
raise EOFError("Compressed file ended before the "
EOFError: Compressed file ended before the end-of-stream marker was reached
似乎文件已部分下载。该文件在哪里?我删除了tmp
文件夹中的内容,然后再次运行了该程序,但是遇到了同样的错误。