cls_names
1total_images = 0 2for gov in govs: 3 4 file_list = os.listdir(base_path + gov + '/Annotations/') 5 6 for file in file_list: 7 8 total_images = total_images + 1 9 if file =='.DS_Store': 10 pass 11 else: 12 infile_xml = open(base_path + gov + '/Annotations/' +file) 13 tree = ElementTree.parse(infile_xml) 14 root = tree.getroot() 15 for obj in root.iter('object'): 16 cls_name = obj.find('name').text 17 cls_names.append(cls_name) 18print("total") 19print("# of images:" + str(total_images)) 20print("# of labels:" + str(len(cls_names))) 21コード 22```--------------------------------------------------------------------------- 23UnicodeDecodeError Traceback (most recent call last) 24<ipython-input-43-73bb8957341c> in <module>() 25 13 else: 26 14 infile_xml = open(base_path + gov + '/Annotations/' +file) 27---> 15 tree = ElementTree.parse(infile_xml) 28 16 root = tree.getroot() 29 17 for obj in root.iter('object'): 30 31/anaconda3/lib/python3.6/xml/etree/ElementTree.py in parse(source, parser) 32 1194 """ 33 1195 tree = ElementTree() 34-> 1196 tree.parse(source, parser) 35 1197 return tree 36 1198 37 38/anaconda3/lib/python3.6/xml/etree/ElementTree.py in parse(self, source, parser) 39 595 # It can be used to parse the whole source without feeding 40 596 # it with chunks. 41--> 597 self._root = parser._parse_whole(source) 42 598 return self._root 43 599 while True: 44 45/anaconda3/lib/python3.6/codecs.py in decode(self, input, final) 46 319 # decode input (taking the buffer into account) 47 320 data = self.buffer + input 48--> 321 (result, consumed) = self._buffer_decode(data, self.errors, final) 49 322 # keep undecoded input until the next call 50 323 self.buffer = data[consumed:] 51 52UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 45: invalid start byte 53コード 54### 前提・実現したいこと 55python初心者です。 56GitHubから引用し。指示通り、jupyternotebookで動かしているのですが 57エラーが出てしまい、進むことができません 58どこかコードが間違えていると思われるのですが、検討もつかず困っています。 59データセットから画像などを読み込んでいると思うのですが、'utf-8' と言うものが引っかかっており、エラーが出ていると思います。 コードの追加、削除するところがあれば教えて下さい。 60 61### 発生している問題・エラーメッセージ 62'utf-8'だと思われます 63### 該当のソースコード 64'utf-8' codec can't decode byte 0xb0 in position 45: invalid start byte 65 66 67 68 69ここに問題に対して試したことを記載してください。 70#!/usr/bin/env python 71# -*- coding: utf-8 -*- 72import sys 73import codecs 74 75sys.stdout = codecs.getwriter('utf_8')(sys.stdout) 76 77などを追加してみたのですがダメでした 78### 補足情報(FW/ツールのバージョンなど) 79 80ここにより詳細な情報を記載してください。 81参考にしているgithubです 82https://github.com/sekilab/RoadDamageDetector/blob/master/RoadDamageDatasetTutorial.ipynb
回答3件
あなたの回答
tips
プレビュー