encoding = "utf-8" infile_xml= open(base_path + gov + '/Annotations/' +file) root = ElementTree.parse(f) cls_names = [] total_images = 0 for gov in govs: file_list = os.listdir(base_path + gov + '/Annotations/') for file in file_list: total_images = total_images + 1 if file =='.DS_Store': pass else: infile_xml = open(base_path + gov + '/Annotations/' +file) tree = ElementTree.parse(infile_xml) root = tree.getroot() for obj in root.iter('object'): cls_name = obj.find('name').text cls_names.append(cls_name) print("total") print("# of images:" + str(total_images)) print("# of labels:" + str(len(cls_names))) ```Traceback (most recent call last): File "/anaconda3/envs/TensorFlow2/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-19-13a3872d49bb>", line 3, in <module> root = ElementTree.parse(f) File "/anaconda3/envs/TensorFlow2/lib/python3.6/xml/etree/ElementTree.py", line 1196, in parse tree.parse(source, parser) File "/anaconda3/envs/TensorFlow2/lib/python3.6/xml/etree/ElementTree.py", line 597, in parse self._root = parser._parse_whole(source) File "<string>", line unknown ParseError: no element found: line 1, column 0 上記のコードを打ち込むと no element found: line 1, column 0 とエラーが出てしまいます 環境としてはmacOS High Sierra バージョン10.13.5です 上記のエラーが出てしまうのですが、どのようにすれば改善できるのでしょうか? よろしくお願いします。 ・環境構築に関しては、ネットからanacondaをインストールしました。 今回githubで参考にしているのですがその途中でエラーが出てしまいました。 参考URLはこちらになります https://github.com/sekilab/RoadDamageDetector/blob/master/RoadDamageDatasetTutorial.ipynb 念のため、前の段階の作業コードを載せておきます ```ここに言語を入力 import six.moves.urllib as urllib
>>> import os >>> os.getcwd()
try: import urllib.request except ImportError: raise ImportError('You should use Python 3.x') if not os.path.exists('./RoadDamageDataset.tar.gz'): url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/RoadDamageDataset.tar.gz' urllib.request.urlretrieve(url_base, './RoadDamageDataset.tar.gz') print("Download RoadDamageDataset.tar.gz Done") else: print("You have RoadDamageDataset.tar.gz")
if not os.path.exists('./trainedModels.tar.gz'): url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/trainedModels.tar.gz' urllib.request.urlretrieve(url_base, './trainedModels.tar.gz') print("Download trainedModels.tar.gz Done") else: print("You have trainedModels.tar.gz")
!tar -zxf ./RoadDamageDataset.tar.gz !tar -zxf ./trainedModels.tar.gz
from xml.etree import ElementTree from xml.dom import minidom import collections import os import matplotlib.pyplot as plt import matplotlib as matplot import seaborn as sns %matplotlib inline
base_path = os.getcwd() + '/RoadDamageDataset/' damageTypes=["D00", "D01", "D10", "D11", "D20", "D40", "D43", "D44"] # govs corresponds to municipality name. govs = ["Adachi", "Chiba", "Ichihara", "Muroran", "Nagakute", "Numazu", "Sumida"]
encoding = "utf-8" infile_xml= open(base_path + gov + '/Annotations/' +file) root = ElementTree.parse(f) cls_names = [] total_images = 0 for gov in govs: file_list = os.listdir(base_path + gov + '/Annotations/') for file in file_list: total_images = total_images + 1 if file =='.DS_Store': pass else: infile_xml = open(base_path + gov + '/Annotations/' +file) tree = ElementTree.parse(infile_xml) root = tree.getroot() for obj in root.iter('object'): cls_name = obj.find('name').text cls_names.append(cls_name) print("total") print("# of images:" + str(total_images)) print("# of labels:" + str(len(cls_names)))
Traceback (most recent call last):
File "/anaconda3/envs/TensorFlow2/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-19-13a3872d49bb>", line 3, in <module>
root = ElementTree.parse(f)
File "/anaconda3/envs/TensorFlow2/lib/python3.6/xml/etree/ElementTree.py", line 1196, in parse
tree.parse(source, parser)
File "/anaconda3/envs/TensorFlow2/lib/python3.6/xml/etree/ElementTree.py", line 597, in parse
self._root = parser._parse_whole(source)
File "<string>", line unknown
ParseError: no element found: line 1, column 0
あなたの回答
tips
プレビュー