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

标签 python python-3.x image-processing tensorflow

我正在使用 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/

相关文章:

python - 根据字典的值对列表进行排序

python - 我可以在 pandas 中获得一个额外的标题作为所有列顶部的名称吗

matlab - 平均滤波器Matlab

Python 3 - 非复制流接口(interface)到 bytearray?

python - 如何优化我的 Python 代码以使用更少的内存执行计算?

python - 在 PyQt 中绘制多边形

图像梯度角计算

c++ - 以下图像处理功能如何工作?

python - 一维数据中的阈值

python-3.x - AsyncIO 流写入器/读取器是否需要手动确保发送/接收所有数据?