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

猜你喜欢

转载自blog.csdn.net/oMoDao1/article/details/83146740