gpt4 book ai didi

python - 操作系统错误 : raw write() returned invalid length when using print() in python

转载 作者:太空狗 更新时间:2023-10-29 20:34:38 27 4
gpt4 key购买 nike

我正在使用 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 成为一个小值,但这没有用。我试图在网上搜索这个错误,但没有找到任何有用的信息。如果您有解决此问题的方法,请告诉我

最佳答案

如果您无法迁移到 3.6 或像我一样从 Windows 迁移,请安装 win_unicode_console 包,将其导入并在脚本开头添加此行以启用它:

win_unicode_console.enable()

这个问题似乎通常是 3.6 之前的 Python 所特有的,因为负责处理文本输出的代码已为这个最新版本重写。这也意味着我们很可能不会看到针对此问题的修复。

来源:https://bugs.python.org/issue32245

关于python - 操作系统错误 : raw write() returned invalid length when using print() in python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47356993/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com