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

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

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

Chainerは、国産の深層学習フレームワークです。あらゆるニューラルネットワークをPythonで柔軟に書くことができ、学習させることが可能。GPUをサポートしており、複数のGPUを用いた学習も直感的に記述できます。

Jupyter

Jupyter (旧IPython notebook)は、Notebook形式でドキュメント作成し、プログラムの記述・実行、その実行結果を記録するツールです。メモの作成や保存、共有、確認などもブラウザ上で行うことができます。

Python

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

Q&A

解決済

1回答

1848閲覧

物体検出の独自データセット作成時のエラー<ValueError: tuple.index(x): x not in tuple>

yuya_murakami

総合スコア12

Chainer

Chainerは、国産の深層学習フレームワークです。あらゆるニューラルネットワークをPythonで柔軟に書くことができ、学習させることが可能。GPUをサポートしており、複数のGPUを用いた学習も直感的に記述できます。

Jupyter

Jupyter (旧IPython notebook)は、Notebook形式でドキュメント作成し、プログラムの記述・実行、その実行結果を記録するツールです。メモの作成や保存、共有、確認などもブラウザ上で行うことができます。

Python

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

0グッド

0クリップ

投稿2019/11/26 02:30

#概要
物体検出プログラム作成時、独自データセットの中を見ようとして
(first_datum = train_dataset[0])
エラー。参考サイトのプログラムでは動作したため、データセットの中身がおかしい?とかんがえられます。まったくわからないため教えていただきたいです。よろしくお願いします。
#エラーの出たプログラム

python

1import chainer 2import cupy 3import chainercv 4import matplotlib 5import os 6import xml.etree.ElementTree as ET 7 8import numpy as np 9 10from chainercv.datasets import VOCBboxDataset 11 12 13bccd_labels = ('ROCK', 'MOUNTAIN')#変更箇所 14 15 16class BCCDDataset(VOCBboxDataset): 17 18 def _get_annotations(self, i): 19 id_ = self.ids[i] 20 anno = ET.parse( 21 os.path.join(self.data_dir, 'Annotations', id_ + '.xml')) 22 23 bbox = [] 24 label = [] 25 difficult = [] 26 for obj in anno.findall('object'): 27 bndbox_anno = obj.find('bndbox') 28 29 bbox.append([ 30 int(bndbox_anno.find(tag).text) - 1 31 for tag in ('ymin', 'xmin', 'ymax', 'xmax')]) 32 name = obj.find('name').text.lower().strip() 33 label.append(bccd_labels.index(name)) 34 print(bccd_labels.index(obj.find('name').text.lower().strip())) 35 bbox = np.stack(bbox).astype(np.float32) 36 label = np.stack(label).astype(np.int32) 37 38 difficult = np.array(difficult, dtype=np.bool) 39 return bbox, label, difficult 40train_dataset = BCCDDataset('rock_detect_dataset/BCCD', 'train') 41valid_dataset = BCCDDataset('rock_detect_dataset/BCCD', 'val') 42test_dataset = BCCDDataset('rock_detect_dataset/BCCD', 'test') 43print('Number of images in "train" dataset:', len(train_dataset)) 44print('Number of images in "valid" dataset:', len(valid_dataset)) 45print('Number of images in "test" dataset:', len(test_dataset)) 46first_datum = train_dataset[0]

#参考サイト・コード
https://japan-medical-ai.github.io/medical-ai-course-materials/notebooks/06_Blood_Cell_Detection.html

jupyter

1!pip install chainercv # ChainerCVのインストール 2 3import chainer 4import cupy 5import chainercv 6import matplotlib 7!if [ ! -d BCCD_Dataset ]; then git clone https://github.com/Shenggan/BCCD_Dataset.git; fi 8 9import os 10import xml.etree.ElementTree as ET 11 12import numpy as np 13 14from chainercv.datasets import VOCBboxDataset 15 16 17bccd_labels = ('rbc', 'wbc', 'platelets') 18 19 20class BCCDDataset(VOCBboxDataset): 21 22 def _get_annotations(self, i): 23 id_ = self.ids[i] 24 25 anno = ET.parse( 26 os.path.join(self.data_dir, 'Annotations', id_ + '.xml')) 27 28 bbox = [] 29 label = [] 30 difficult = [] 31 for obj in anno.findall('object'): 32 bndbox_anno = obj.find('bndbox') 33 34 bbox.append([ 35 int(bndbox_anno.find(tag).text) - 1 36 for tag in ('ymin', 'xmin', 'ymax', 'xmax')]) 37 name = obj.find('name').text.lower().strip() 38 label.append(bccd_labels.index(name)) 39 bbox = np.stack(bbox).astype(np.float32) 40 label = np.stack(label).astype(np.int32) 41 42 difficult = np.array(difficult, dtype=np.bool) 43 return bbox, label, difficult 44 45train_dataset = BCCDDataset('BCCD_Dataset/BCCD', 'train') 46valid_dataset = BCCDDataset('BCCD_Dataset/BCCD', 'val') 47test_dataset = BCCDDataset('BCCD_Dataset/BCCD', 'test') 48 49first_datum = train_dataset[0] 50

xml例

<annotation> <folder>JPGImages</folder> <filename>hogehoge.jpg</filename> <path>hogehoge</path> <source> <database>Unknown</database> </source> <size> <width>720</width> <height>1080</height> <depth>3</depth> </size> <segmented>0</segmented> <object> <name>MOUNTAIN</name> <pose>Unspecified</pose> <truncated>0</truncated> <difficult>0</difficult> <bndbox> <xmin>242.6123427801162</xmin> <ymin>279.4234910191407</ymin> <xmax>720</xmax> <ymax>706.8194993286604</ymax> </bndbox> </object> </annotation> # エラーコード ```python

ValueErrorTraceback (most recent call last)
<ipython-input-59-8cd07929f6af> in <module>
----> 1 first_datum = train_dataset[0]
2 print(first_datum[0].shape, first_datum[0].dtype)

/usr/local/lib/python3.6/dist-packages/chainer/dataset/dataset_mixin.py in getitem(self, index)
65 return [self.get_example(i) for i in index]
66 else:
---> 67 return self.get_example(index)
68
69 def len(self):

/usr/local/lib/python3.6/dist-packages/chainercv/chainer_experimental/datasets/sliceable/sliceable_dataset.py in get_example(self, index)
96 if isinstance(self.keys, tuple):
97 return self.get_example_by_keys(
---> 98 index, tuple(range(len(self.keys))))
99 else:
100 return self.get_example_by_keys(index, (0,))[0]

/usr/local/lib/python3.6/dist-packages/chainercv/chainer_experimental/datasets/sliceable/getter_dataset.py in get_example_by_keys(self, index, key_indices)
87 _, getter_index, key_index = self._keys[key_index]
88 if getter_index not in cache:
---> 89 cache[getter_index] = self._gettersgetter_index
90 if key_index is None:
91 example.append(cache[getter_index])

<ipython-input-55-501a46a571b5> in _get_annotations(self, i)
33 for tag in ('ymin', 'xmin', 'ymax', 'xmax')])
34 name = obj.find('name').text.lower().strip()
---> 35 label.append(bccd_labels.index(name))
36 print(bccd_labels.index(obj.find('name').text.lower().strip()))
37 bbox = np.stack(bbox).astype(np.float32)

ValueError: tuple.index(x): x not in tuple

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

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

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

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

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

t_obara

2019/11/26 03:37

print('Number of images in "train" dataset:', len(train_dataset)) この結果はどのように表示されているのですか?
yuya_murakami

2019/11/27 01:49

回答ありがとうございます。 Number of images in "train" dataset: 2144 と表示されました
guest

回答1

0

自己解決

自己解決しました。
bccd_labels = ('ROCK', 'MOUNTAIN')#変更箇所
が大文字だったため小文字に変更したら解決しました。

投稿2019/11/27 01:45

yuya_murakami

総合スコア12

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問