我試圖運行Python文件,但我得到這個錯誤:AttributeError的:「NoneType」對象有沒有屬性「低」
File "/home/hadi/Software/tensorflow/TEST_FRCN_ROOT/tools/../lib/datasets/pascal_voc.py", line 212, in _load_pascal_annotation
cls = self._class_to_ind[obj.find('name').text.lower().strip()]
AttributeError: 'NoneType' object has no attribute 'lower'
這是使錯誤的部分代碼:
%% Load object bounding boxes into a data frame.
for ix, obj in enumerate(objs):
bbox = obj.find('bndbox')
# Make pixel indexes 0-based
x1 = float(bbox.find('xmin').text) - 1
y1 = float(bbox.find('ymin').text) - 1
x2 = float(bbox.find('xmax').text) - 1
y2 = float(bbox.find('ymax').text) - 1
cls = self._class_to_ind[obj.find('name').text.lower().strip()]
boxes[ix, :] = [x1, y1, x2, y2]
gt_classes[ix] = cls
overlaps[ix, cls] = 1.0
seg_areas[ix] = (x2 - x1 + 1) * (y2 - y1 + 1)
我可以添加到處理任何沒有這裏對象的條件?
那麼應該怎麼反而發生,如果在'obj.find(「名」)'沒有文字?當然你可以添加一個條件,但是如果條件不匹配呢? –
所以,我必須檢查每個文件,看看是否有一個缺少名稱屬性的對象?有1200個文件。有沒有其他方法? –
這不是我說的,你也沒有回答我的問題。 –