LoginSignup
1
1

More than 3 years have passed since last update.

【前編】Mask R-CNNで発生したエラー「UserWarning: An input could not be retrieved. It could be because a worker has died」を解決してみた。

Last updated at Posted at 2020-05-26

Mask R-CNNのnucleus検出デモを練習中

Deep learning初心者の私が、google colaboratoryを使ってMask R-CNNに試行錯誤している挑戦の続きです。
今回は以下を活用して、細胞の検出に挑戦しています。

おなじみ、Matterport社のものです。

このデモでは、Mask R-CNNの検出の裏側である、ROIやAnchorなどを表示してくれるとともに、Detectionの際にもStep by stepでやってくれるものです。
初心者にとって、どうやって学習&認識してくれているのか理解することができるので、とても勉強になります。

トレーニングのipynbがない

_dataと_modelの2つipynbファイルがあり特につまずくことなくデモを実行できたのですが、detectionで使うweightをトレーニングするipynbがないのです。
そこで、自分で作ってみようと思い、ヒントが隠されているnucleus.pyの中身を見てみました。

10~25行目に、トレーニングするために実行するコマンドが書かれていました。

nucleus_train.py
#Train a new model starting from ImageNet weights
python3 nucleus.py train --dataset=/path/to/dataset --subset=train --weights=imagenet

#Train a new model starting from specific weights file
python3 nucleus.py train --dataset=/path/to/dataset --subset=train --weights=/path/to/weights.h5

#Resume training a model that you had trained earlier
python3 nucleus.py train --dataset=/path/to/dataset --subset=train --weights=last

#Generate submission file
python3 nucleus.py detect --dataset=/path/to/dataset --subset=train --weights=<last or /path/to/weights.h5>

なるほど、0から学習させるためには一番目のコマンドを実行すればいいんですね。

実行してみよう

ステップ①:とりあえず実行

--dataset=/path/to/datasetの部分を

nucleus_train.py
--dataset=/content/drive/My drive/.../dataset

に変更して実行します。
※utils.Dataset.add_imageの中で、
dataset_dir(上記)とsubset_dir(stage1_train)を合体させるので、stage1_trainまで指定する必要はなさそうです。

ステップ②:重みDownload

これで実行してみると出力にURLが出現するので、
resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5
をダウンロードします。

ステップ③:学習開始

この後、--weights=/path/toの部分を

nucleus_train.py
--weights=/content/.../resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5

に同様に変更します。
Pathも指定できたので、成功かと思いきや…!?

トラブル発生

nucleus_train.py
Epoch 1/20

と表示されたまま固まってしまいました。
そこに出ているエラーは、

nucleus_train.py
UserWarning: An input could not be retrieved. It could be because a worker has died

??なので、そのままgoogleにコピペして調査します。
最初に参考にしたのは以下の記事です。

参考記事①

Colabolatoryで UserWarning: An input could not be retrieved. It could be because a worker has died

どうやら、「Colabolatoryのファイルストリームが学習速度に追いついていない。」ことが原因らしい。
google driveから画像を読み込むところがボトルネックになっていったぽい。

参考記事②

“UserWarning: An input could not be retrieved. It could be because a worker has died. We do not have any information on the lost sample.”

うーん、pathをcolaboratory内にコピーすればよいことしかわかりませんね…

参考記事③

【秒速で無料GPUを使う】深層学習実践Tips on Colaboratory

nucleus_train.py
!cp drive/My Drive/<指定フォルダ>/<指定ファイル等>

大きなデータセットなどはzipのままGoogle Driveに保存しておき、Colabを起動都度、Colabローカルに解凍して持ってくると良い。

nucleus_train.py
!unzip -q drive/My Drive/<指定フォルダ>/<指定ファイル>.zip

-q は解凍時のメッセージを出さないオプション。2GB程度、数千ファイルを含むアーカイブでも、1分程度でGoogle Driveからの取得と解凍が終わる。

なるほど、大きなデータを使う時はcolaboratoryの中にデータを移せばいいんですね!
※この記事はcolaboratoryを活用するのに役立つ情報がわんさかです!

参考記事④

unzipでディレクトリを指定して解凍

ただのコマンド紹介ですが、zipの解凍先はこのように指定できるっぽいです。

nucleus_train.py
% unzip dataset.zip -d /content/dataset

実装してみた

長くなってしまったので、次の記事で実装例を紹介します!

今記事を書いています。乞うご期待!
【記事書き終わりました。】

【後編】Mask R-CNNで発生したエラー「UserWarning: An input could not be retrieved. It could be because a worker has died」を解決してみた。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1