keras运行时,遇到的一个oserror问题

问题描述:

   verbose=1, validation_data=(x_test, y_test))
  File "C:\Users\ASC2017\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\models.py", line 960, in fit
    validation_steps=validation_steps)
  File "C:\Users\ASC2017\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\training.py", line 1657, in fit
    validation_steps=validation_steps)
  File "C:\Users\ASC2017\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\training.py", line 1219, in _fit_loop
    callbacks.on_batch_end(batch_index, batch_logs)
  File "C:\Users\ASC2017\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\callbacks.py", line 109, in on_batch_end
    callback.on_batch_end(batch, logs)
  File "C:\Users\ASC2017\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\callbacks.py", line 299, in on_batch_end
    self.progbar.update(self.seen, self.log_values)
  File "C:\Users\ASC2017\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\utils\generic_utils.py", line 395, in update
    sys.stdout.flush()
OSError: raw write() returned invalid length 170 (should have been between 0 and 85)

经过自己查资料,发现可能与最近的Windows 10更新有关。我有版本1709(操作系统版本16299.64),

  我认为这可能是unicode字符的返回值(正常长度的两倍)?

  我实际上可以在外部powershell.exe中重现此错误,所以这本身不是Code相关的。

  总的来说,与win10系统、版本有关系,踩中雷区了(本人win10,版本 10.0.16299 版本 16299)

解决方法:
使用win_unicode_console这个包可以解决这个问题。

import win_unicode_console
win_unicode_console.enable()

参考:
https://github.com/Microsoft/vscode/issues/39149
https://stackoverflow.com/questions/47356993/oserror-raw-write-returned-invalid-length-when-using-print-in-python

你可能感兴趣的:(深度学习过程)