発展pytorchを行っていたのですが、表題のエラーが発生しました。調べてパスが通っていないという回答が多かったのでパスを見直してみたのですが、下記のprint(train_img_list[0])でパスは教材通りに通っているのを確認しています
どこが間違っているのでしょうか?
def make_datapath_list(rootpath): img_template=osp.join(rootpath,"JPEGImages","%s.jpg") anno_template=osp.join(rootpath,"Annotations","%s.xml") train_id_names=osp.join(rootpath+"ImageSets/Main/train.txt") val_id_names=osp.join(rootpath+"ImageSets/Main/val.txt") train_img_list=list() train_anno_list=list() for line in open(train_id_names): file_id=line.strip() img_path=(img_template%file_id) anno_path=(anno_template%file_id) train_img_list.append(img_path) train_anno_list.append(anno_path) val_img_list=list() val_anno_list=list() for line in open(val_id_names): file_id=line.strip() img_path=(img_template%file_id) anno_path=(anno_template%file_id) val_img_list.append(img_path) val_anno_list.append(anno_path) return train_img_list,val_anno_list,train_anno_list,val_anno_list rootpath="data/VOCdevkit/VOC2012/" train_img_list,train_anno_list,val_img_list,val_anno_list=make_datapath_list(rootpath) print(train_img_list[0]) class Anno_xml2list(object): def __init__(self,classes): self.classes=classes def __call__(self,xml_path,width,height): ret=[] xml=ET.parse(xml_path).getroot() for ojt in xml.iter("object"): difficult=int(pbj.find("difficult").text) if difficult==1: continue bndbox=[] name=obj.find("name").text.lower().strip() bbox=obj.find("bndbox") pts=["xmin","ymin","xmax","ymax"] for pt in (pts): cur_pixel=int(bbox.find(pt).text)-1 if pt=="xmin"or pt=="xmax": cur_pixel/=width else: curpixel/height bndbox.append(cur_pixel) label_idx=self.classes.index(name) bndbox.append(label.idx) ret+=[] return np.array(ret) voc_classes=["aeroplane","bicycle","bird","boat","bottle","bus","cat","chair","cow","diningtable","dog","horse","motorbike","person","pottedplant","sheep","sofa","train","tvmonitor"] transform_anno=Anno_xml2list(voc_classes) ind=1 image_file_path=val_img_list[ind] img=cv2.imread(image_file_path) height,width,channels=img.shape --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-76-8e711cfcea9f> in <module> 5 image_file_path=val_img_list[ind] 6 img=cv2.imread(image_file_path) ----> 7 height,width,channels=img.shape AttributeError: 'NoneType' object has no attribute 'shape'
あなたの回答
tips
プレビュー