我正在使用python tensorflow训练一个模型来识别python中的图像。但是当我试图从github执行train.py时,我得到了以下错误
Traceback (most recent call last):
File "train.py", line 1023, in <module>
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "C:\Users\sande\Anaconda3\envs\tensorflow\lib\site-
packages\tensorflow\python\platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train.py", line 766, in main
bottleneck_tensor)
File "train.py", line 393, in cache_bottlenecks
jpeg_data_tensor, bottleneck_tensor)
File "train.py", line 341, in get_or_create_bottleneck
bottleneck_tensor)
File "train.py", line 290, in create_bottleneck_file
print('Creating bottleneck at ' + bottleneck_path)
OSError: raw write() returned invalid length 112 (should have been between 0
and 56)下面是create_bottleneck_file()的代码
def create_bottleneck_file(bottleneck_path, image_lists, label_name, index,
image_dir, category, sess, jpeg_data_tensor,
bottleneck_tensor):
"""Create a single bottleneck file."""
print('Creating bottleneck at ' + bottleneck_path)
image_path = get_image_path(image_lists, label_name, index,
image_dir, category)
if not gfile.Exists(image_path):
tf.logging.fatal('File does not exist %s', image_path)
image_data = gfile.FastGFile(image_path, 'rb').read()
try:
bottleneck_values = run_bottleneck_on_image(
sess, image_data, jpeg_data_tensor, bottleneck_tensor)
except:
raise RuntimeError('Error during processing file %s' % image_path)
bottleneck_string = ','.join(str(x) for x in bottleneck_values)
with open(bottleneck_path, 'w') as bottleneck_file:
bottleneck_file.write(bottleneck_string)我尝试减少文件名,使bottleneck_path将是一个较小的值,但这不起作用。我试着在网上搜索这个错误,但没有找到任何有用的东西。如果你有解决这个问题的方法,请告诉我
发布于 2017-12-19 22:59:14
如果你不能像我一样从Windows迁移到3.6,安装win_unicode_console包,导入它,并在你的脚本中添加下面这一行来启用它:
win_unicode_console.enable()该问题似乎通常是3.6版本之前的Python所特有的,因为负责处理文本输出的代码已在此最新版本中重写。这也意味着我们很可能不会看到这个问题的修复。
发布于 2017-11-28 10:15:28
我认为这是11月份的创建者更新引入的stdout/stderr流上的一个bug,它在powershell.exe和cmd.exe中都会发生
这似乎只发生在Windows 10版本1709 (OS Build 16299.64)上。我的猜测是它是unicode实现的(输出大小是预期长度的两倍)
一个(非常)快速而肮脏的修复方法是只在控制台上输出ASCII:
mystring.encode("utf-8").decode("ascii")
https://github.com/Microsoft/vscode/issues/39149#issuecomment-347260954
发布于 2018-02-21 10:53:36
向@AMSAntiago添加更多。您可以运行win_unicode_console.enable()。但是,您可以在每个Python调用(docs)上运行它,而不是在每个文件上使用它。这对我很有效。
https://stackoverflow.com/questions/47356993
复制相似问题