DmccccccZK 2023-03-30 00:19 采纳率: 100%
浏览 6
已结题

tensorflow object detection API 模型训练最后开始训练 ,报错utf-8

tensorflow object detection api进行模型训练,用的模型是自带的,已经到了开始训练 文件设置路径都没问题

python C:\Users\Administrator\models\research\object_detection\model_main_tf2.py ^
    --model_dir=C:/Users/Administrator/models/research/object_detection/training ^
    --pipeline_config_path=C:/Users/Administrator/models/research/object_detection/training/ssd_efficientdet_d1_0x0_coco17_tpu-8.config ^
    --num_train_steps=20000 ^
    --sample_1_of_n_eval_examples=9 

结果报错
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 158: invalid continuation byte
请问如何能解决

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-03-30 04:06
    关注
    • 给你找了一篇非常好的博客,你可以看看是否有帮助,链接:tensorflow问题:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0
    • 除此之外, 这篇博客: Tensorflow object detection API训练自己的数据中的 _*_coding:utf-8 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
    • import os

      pic_path = “/Users/cathy/Desktop/models/research/object_detection/test_images/test”
      def rename():
      piclist = os.listdir(pic_path)
      total_num = len(piclist)

      i = 1
      for pic in piclist:
          if pic.endswith(".jpg"):
              old_path = os.path.join(os.path.abspath(pic_path), pic)  # os.path.abspath获得绝对路径
              new_path = os.path.join(os.path.abspath(pic_path), '000' + format(str(i), '0>3') + '.jpg')
      
              os.renames(old_path, new_path)
              print
              u"把原图片命名格式:" + old_path + u"转换为新图片命名格式:" + new_path
              # print "把原图片路径:%s,转换为新图片路径:%s" %(old_path,new_path)
              i = i + 1
      
      print("总共" + str(total_num) + "张图片被重命名为:" "00001.jpg~" + '000' + format(str(i - 1), '0>3') + ".jpg形式")
      

      rename()

      3.在训练模型的过程中,图片必须是RGB通道,否则也会出错。接下来我写了两个py文件进行图片处理。
      第一个py文件:判定文件夹中的图片是否为RGB,检查图片是否RGB.py
      from PIL import Image
      import os

      path = ‘/Users/cathy/Desktop/models/research/object_detection/test_images/train/’ # 图片目录
      for file in os.listdir(path):

      extension = file.split('.')[-1]
      if extension == 'jpg':
          fileLoc = path + file
          img = Image.open(fileLoc)
          if img.mode != 'RGB':
              print(file + ', ' + img.mode)
      

      第二个文件:将不是RGB的图片变为RGB,图片变为RGB.py
      from PIL import Image
      import os

      path = ‘/Users/cathy/Desktop/models/research/object_detection/test_images/train/’ # 图片目录
      for file in os.listdir(path):

      extension = file.split('.')[-1]
      if extension == 'jpg':
          fileLoc = path + file
          img = Image.open(fileLoc)
          if img.mode != 'RGB':
              print(file + ', ' + img.mode)
              img_rgb = img.convert("RGB")#转化成RGB模式
              os.remove(path + file)
              img_rgb.save(path + file)
      

      4.上面对于图片的处理告一段落,接下来对图片进行标注,使用的是labellmg,地址在这里https://github.com/tzutalin/labelImg#macos
      我用的是mac,因此用的mac底下的那些命令进行安装
      环境:python3.7 Qt5
      brew install qt # Install qt-5.x.x by Homebrew
      brew install libxml2

      pyrcc5-o/Users/cathy/Desktop/labelImg-master/resources.py /Users/cathy/Desktop/labelImg-master/resources.qrc#根据自己的地址进行相应的修改

      python3 /Users/cathy/Desktop/labelImg-master/labelImg.py

      做完以上工作,会跑出来一个小程序,接下来我指出较为重要的功能:
      选择目录和存放目录后,点击w,然后选择物体,然后标注名称,接着点击保存。点击d下一张继续以上的工作。
      我将xml文件分别存放在了一下文件夹中:
      /Users/cathy/Desktop/models/research/object_detection/test_images/train_xml
      /Users/cathy/Desktop/models/research/object_detection/test_images/test_xml

      5.生成了xml文件之后,还要将他们转为csv文件,xml_to_csv.py文件如下,运行即可:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月7日
  • 已采纳回答 3月30日
  • 创建了问题 3月30日

悬赏问题

  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”