質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
PyTorch

PyTorchは、オープンソースのPython向けの機械学習ライブラリ。Facebookの人工知能研究グループが開発を主導しています。強力なGPUサポートを備えたテンソル計算、テープベースの自動微分による柔軟なニューラルネットワークの記述が可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

522閲覧

AttributeError: 'NoneType' object has no attribute 'shape'

tyuunibyou

総合スコア22

PyTorch

PyTorchは、オープンソースのPython向けの機械学習ライブラリ。Facebookの人工知能研究グループが開発を主導しています。強力なGPUサポートを備えたテンソル計算、テープベースの自動微分による柔軟なニューラルネットワークの記述が可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/06/07 04:14

発展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'

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

meg_

2020/06/07 04:35

val_img_list[ind]のパスは存在していますか? カレントディレクトリからアクセス可能なパスになっていますか? pythonスクリプトを実行しているユーザーにアクセス権限はありますか?
tyuunibyou

2020/06/07 04:39

ちょっと調べてみます!
tyuunibyou

2020/06/07 06:26

上記を再インストールしたのですが駄目でした また、カレントディレクトリからアクセスは上記のコードでprint(train_img_list[0])をrunした時に教材通りになったのでアクセス可能になっていると思います。 pythonスクリプトを実行しているユーザーにアクセス権限ありました。(os.accessで確認済)
tyuunibyou

2020/06/07 06:28

また、val__img_list[ind]を実行したところ、下記のように表示されパスがあることが確認できました。 'data/VOCdevkit/VOC2012/Annotations\\2008_000015.xml'
tyuunibyou

2020/06/07 06:42

追記です。 img=cv2.imread(image_file_path) の部分で print(img)だとnoneになり print(image_file_path)だと上記と同様に data/VOCdevkit/VOC2012/Annotations\2008_000015.xml が表示されました。
tyuunibyou

2020/06/08 04:50

度々すみません 上記のURLによるとval_img_list[ind]が正と記載されています。 どこが間違っているのでしょうか?
meg_

2020/06/08 11:51

カレントディレクトリは'data'フォルダがある場所になっていますか?
tyuunibyou

2020/06/20 01:20

返信遅くなりました。すみません。はいデータフォルダがある場所になってます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問