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

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

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

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Q&A

解決済

1回答

747閲覧

tensorflow object detection API 独自データの学習について

PayaLiv

総合スコア13

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

0グッド

0クリップ

投稿2017/11/27 08:47

編集2017/11/29 13:14

実現したいこと

現在 github 上にある"tensorflow object detection api" を利用して独自のデータセットを用意して学習をさせていと思っています.
tensorflow object detection api
object_detection/train.py を実行するために前処理を行いました.
youtubeでのマカロニチーズを検出する動画を参考にさせていただきました.
TensorFlow Object Detection API Tutorial p.1
問題点

用意したものは model/research/object_detection に移動しました.

object_detection
-images
--images.png
--images.xml
--test
---images.png
---images.xml
--train
---images.png
---images.xml
-data
--test.record
--train.record
-training
--ssd_mobilenet_v1_pets.config
-ssd_mobilenet_v1_coco_11_06_2017
--frozen_inference_graph.pb
--graph.pbtxt
--model.ckpt.data-00000-of-00001
--model.ckpt.index
--model.ckpt.meta

上記のものを移動しました.
imagesの中に入っているimages.png は複数の画像が入っています.

python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config

上記のコマンドで学習を始めました.
その後

INFO:tensorflow:depth of additional conv before box predictor: 0 INFO:tensorflow:depth of additional conv before box predictor: 0 INFO:tensorflow:depth of additional conv before box predictor: 0 INFO:tensorflow:depth of additional conv before box predictor: 0 INFO:tensorflow:depth of additional conv before box predictor: 0 INFO:tensorflow:Summary name /clone_loss is illegal;usingclone_loss instead.

と表示され,tensorflow に関する情報が流れ

INFO:tensorflow:Starting Session. INFO:tensorflow:Saving checkpoint to path training/model.ckpt INFO:tensorflow:Starting Queues. INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:Saving checkpoint to path training/model.ckpt INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:Saving checkpoint to path training/model.ckpt INFO:tensorflow:Saving checkpoint to path training/model.ckpt INFO:tensorflow:Saving checkpoint to path training/model.ckpt ………

上記のようなものが表示されて学習が終了しませんでした.
メッセージからも正しく学習が開始されているように見えませんでした.
batch_size:24
num_terms:20000

"INFO:tensorflow:global_step/sec: 0" が表示されるまでにおよそ1分ほどかかっています.

以下は"ssd_mobilenet_v1_pets.config"の内容です.

ssd_mobilenet_v1_pets.config

1# SSD with Mobilenet v1, configured for Oxford-IIIT Pets Dataset. 2# Users should configure the fine_tune_checkpoint field in the train config as 3# well as the label_map_path and input_path fields in the train_input_reader and 4# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that 5# should be configured. 6 7model { 8 ssd { 9 num_classes: 1 10 box_coder { 11 faster_rcnn_box_coder { 12 y_scale: 10.0 13 x_scale: 10.0 14 height_scale: 5.0 15 width_scale: 5.0 16 } 17 } 18 matcher { 19 argmax_matcher { 20 matched_threshold: 0.5 21 unmatched_threshold: 0.5 22 ignore_thresholds: false 23 negatives_lower_than_unmatched: true 24 force_match_for_each_row: true 25 } 26 } 27 similarity_calculator { 28 iou_similarity { 29 } 30 } 31 anchor_generator { 32 ssd_anchor_generator { 33 num_layers: 6 34 min_scale: 0.2 35 max_scale: 0.95 36 aspect_ratios: 1.0 37 aspect_ratios: 2.0 38 aspect_ratios: 0.5 39 aspect_ratios: 3.0 40 aspect_ratios: 0.3333 41 } 42 } 43 image_resizer { 44 fixed_shape_resizer { 45 height: 300 46 width: 300 47 } 48 } 49 box_predictor { 50 convolutional_box_predictor { 51 min_depth: 0 52 max_depth: 0 53 num_layers_before_predictor: 0 54 use_dropout: false 55 dropout_keep_probability: 0.8 56 kernel_size: 1 57 box_code_size: 4 58 apply_sigmoid_to_scores: false 59 conv_hyperparams { 60 activation: RELU_6, 61 regularizer { 62 l2_regularizer { 63 weight: 0.00004 64 } 65 } 66 initializer { 67 truncated_normal_initializer { 68 stddev: 0.03 69 mean: 0.0 70 } 71 } 72 batch_norm { 73 train: true, 74 scale: true, 75 center: true, 76 decay: 0.9997, 77 epsilon: 0.001, 78 } 79 } 80 } 81 } 82 feature_extractor { 83 type: 'ssd_mobilenet_v1' 84 min_depth: 16 85 depth_multiplier: 1.0 86 conv_hyperparams { 87 activation: RELU_6, 88 regularizer { 89 l2_regularizer { 90 weight: 0.00004 91 } 92 } 93 initializer { 94 truncated_normal_initializer { 95 stddev: 0.03 96 mean: 0.0 97 } 98 } 99 batch_norm { 100 train: true, 101 scale: true, 102 center: true, 103 decay: 0.9997, 104 epsilon: 0.001, 105 } 106 } 107 } 108 loss { 109 classification_loss { 110 weighted_sigmoid { 111 anchorwise_output: true 112 } 113 } 114 localization_loss { 115 weighted_smooth_l1 { 116 anchorwise_output: true 117 } 118 } 119 hard_example_miner { 120 num_hard_examples: 3000 121 iou_threshold: 0.99 122 loss_type: CLASSIFICATION 123 max_negatives_per_positive: 3 124 min_negatives_per_image: 0 125 } 126 classification_weight: 1.0 127 localization_weight: 1.0 128 } 129 normalize_loss_by_num_matches: true 130 post_processing { 131 batch_non_max_suppression { 132 score_threshold: 1e-8 133 iou_threshold: 0.6 134 max_detections_per_class: 100 135 max_total_detections: 100 136 } 137 score_converter: SIGMOID 138 } 139 } 140} 141 142train_config: { 143 batch_size: 24 144 optimizer { 145 rms_prop_optimizer: { 146 learning_rate: { 147 exponential_decay_learning_rate { 148 initial_learning_rate: 0.004 149 decay_steps: 800720 150 decay_factor: 0.95 151 } 152 } 153 momentum_optimizer_value: 0.9 154 decay: 0.9 155 epsilon: 1.0 156 } 157 } 158 fine_tune_checkpoint: "ssd_mobilenet_v1_coco_11_06_2017/model.ckpt" 159 from_detection_checkpoint: true 160 # Note: The below line limits the training process to 200K steps, which we 161 # empirically found to be sufficient enough to train the pets dataset. This 162 # effectively bypasses the learning rate schedule (the learning rate will 163 # never decay). Remove the below line to train indefinitely. 164 num_steps: 200000 165 data_augmentation_options { 166 random_horizontal_flip { 167 } 168 } 169 data_augmentation_options { 170 ssd_random_crop { 171 } 172 } 173} 174 175train_input_reader: { 176 tf_record_input_reader { 177 input_path: "data/train.record" 178 } 179 label_map_path: "data/object-detection.pbtxt" 180} 181 182eval_config: { 183 num_examples: 2000 184 # Note: The below line limits the evaluation process to 10 evaluations. 185 # Remove the below line to evaluate indefinitely. 186 max_evals: 10 187} 188 189eval_input_reader: { 190 tf_record_input_reader { 191 input_path: "data/test.record" 192 } 193 label_map_path: "data/object-detection.pbtxt" 194 shuffle: false 195 num_readers: 1 196} 197

環境

OS : windows8
プロセッサ : Intel(R)Core(TM)i5-4590 CPU @ 3.30GHz
RAM : 8.00GB
64bit オペレーティングシステム


参考にさせていただいたyoutubeの動画ではUbuntuを利用していたため,ここまでにも動画と違いうところはありました.
現在解決の糸口が見つからず困っています.
少しでも何かわかる方は教えていただきたいです.
よろしくお願いいたします.

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

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

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

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

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

guest

回答1

0

ベストアンサー

まず、Saving checkpoint to path training/model.ckptがあるので、何かしらの重みが吐き出されています。
重みが出力されるということは、少なくとも指示されたことはやったと、プログラムは認識しているようです。
どうして正しく学習が開始されなかったと思われるのでしょうか。

global_step/sec: 0なので、一秒あたりに0ステップ学習できたという意味ですね。
修正前:global_step/sec: 0とステップあたりの時間が無に等しいのはデータが1枚しかないせいでしょうか。
例えば画像データを大量に追加しても時間は0のまま変わりませんか。

他に考慮することは学習ステップ数の指定ですが、ssd_mobilenet_v1_pets.configにて正しく指定されていますか?

特にエラーが見受けられないので、学習できていないとすれば学習パラメータ(学習ステップ数、バッチサイズなど)の設定が悪いような気がします。

投稿2017/11/27 10:32

編集2017/11/28 08:21
mkgrei

総合スコア8560

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

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

PayaLiv

2017/11/28 08:08

ご回答及びアドバイス有難うございます. config file についてもう少し詳しく見てみようと思います.
mkgrei

2017/11/28 08:49

動画を拝見しました。 >tensorflow に関する情報が流れ の部分では確かに学習についてまだ表示していないですね。 その続きはどうなっていますか。 何度も >INFO:tensorflow:global_step/sec: 0 が表示されているようですが、リトライをして1分経つごとに新しい行が出力されていますか。それとも、重複して出力されているだけですか。 CPUしかない場合、計算に非常に時間がかかることがあります。 また、バッチサイズ次第では8GBのメモリに乗らない可能性もあります。
PayaLiv

2017/11/29 08:57

INFO:tensorflow:global_step/sec: 0 が表示されるたびに1分ほどかかっています. bach_sizeを変更してやってみましたが,結果は変わりませんでした. また,bach_sizeを変更するとINFO:tensorflow:global_step/sec: 0 の表示されるスピードが違っているような気がしました.
mkgrei

2017/11/29 09:50

一般にbatch_sizeを大きくすると1epochあたりの時間が短縮されます。 何かをトライして、その結果に満足できなかったせいで、再試行しているように思えます。 本当はそのまま学習が続くはずなのに、初期化を何度も行っているような振る舞いですね。 INFO:tensorflow:Saving checkpoint to path training/model.ckpt INFO:tensorflow:Saving checkpoint to path training/model.ckpt INFO:tensorflow:Saving checkpoint to path training/model.ckpt ……… 以降も同じ出力の繰り返しですか?
PayaLiv

2017/11/29 10:03

INFO:tensorflow:global_step/sec: 0 が十回繰り返された後は ずっと INFO:tensorflow:Saving checkpoint to path training/model.ckpt が続いています. num_stepを変更しても変わりません. また training/model.ckpt は出力されていませんでした.
mkgrei

2017/11/29 12:29

今手元で試してみましたが、チュートリアル通りにやると正常に学習が開始されました。 差し支えがなければ、ssd_mobilenet_v1_pets.configの内容を追記していただけませんか。
PayaLiv

2017/11/29 13:26

本文に ssd_mobilenet_v1_pets.config の内容を記載しました. わざわざチュートリアルまで試していただき有難うございます. 他に一つ気になる点があるのですが,158行目に fine_tune_checkpoint があり,ssd_mobilenet_v1_coco_11_06_2017/model.ckpt を参照しているのですが,ssd_mobilenet_v1_coco_11_06_2017 には model.ckpt は存在していません. 動画でも ssd_mobilenet_v1_coco_11_06_2017 にはmodel.ckpt はなかったのですが,この path を参照していました. これは大丈夫でしょうか? 何かわかることがあればよろしくお願いいたします.
mkgrei

2017/11/29 13:33

まず、設定ファイルの中にあるパスをすべて絶対パスで指定してみてください。全部で5ヶ所です。 さらにmodel.ckpt.data-00000-of-00001をコピーしてmodel.ckptというファイルにしてみてください。 それで実行できるようになるでしょうか。
PayaLiv

2017/11/30 16:35

有難うございます. 指定された5箇所のpathを絶対パスにすることで,無事学習を始めることができました. 実際にそのあとに学習したモデルを使い,物体を検知することはできませんでした(恐らくtraining data が少なく学習回数も少なかった…?)が学習時のloss を見る限り学習はできていそうです. ここまでアドバイスをいただいた事,誠に感謝しております. どうも有難うございました!
mkgrei

2017/11/30 16:43

こちらこそ。 うまくいってよかったです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問