1. 程式人生 > >write() argument must be str, not bytes

write() argument must be str, not bytes

在使用https://github.com/endernewton/tf-faster-rcnn原始碼裡的test_net.py儲存測試結果的時候出現了一下錯誤

通過定位錯誤位置找到具體位置:

  if not os.path.isfile(cachefile):
    # load annotations
    recs = {}
    for i, imagename in enumerate(imagenames):
      recs[imagename] = parse_rec(annopath.format(imagename))
      if i % 100 == 0:
        print('Reading annotation for {:d}/{:d}'.format(
          i + 1, len(imagenames)))
    # save
    print('Saving cached annotations to {:s}'.format(cachefile))
    with open(cachefile, 'w') as f:
      pickle.dump(recs, f)

解決辦法:

把語句:

with open(cachefile, 'w') as f:

改為(使用二進位制方式開啟):

    with open(cachefile, 'wb+') as f:

 

參考資料:https://blog.csdn.net/qq_29755359/article/details/70224333