前提・実現したいこと
chainerを用いてunet構造での3クラス分類を行いたいと考えています.
学習の評価を行う際にchainerCVのeval_semantic_segmentationを使用したのですが以下のエラーが出てしまいました.発生しているエラーを見る限りeval_semantic_segmentationに代入する変数の次元が2次元である必要があるようなのですが,どちらの変数も2次元であるので,何故エラーになっているのか全く分からないです.
また,次元数を2に削減しているのですが,このやり方であっているのでしょうか?
エラーが出て学習できていないので,データの変形などの仕方がこれであっているか不安です.
プログラムの全体については一つ前の質問を見て頂ければ幸いです.
分かる方いらっしゃいましたらご教授願います.
宜しくお願い致します.
発生している問題・エラーメッセージ
raise ValueError ndim of labels should be two.
該当のソースコード
python
1class PixelwiseSigmoidClassifier(chainer.Chain): 2 """目的関数を計算するclassifierクラスを自作""" 3 4 def __init__(self, predictor): 5 """学習対象のモデルをpredictorとして保持しておく""" 6 super().__init__() 7 with self.init_scope(): 8 self.predictor = predictor 9 10 def __call__(self, inputimg, t): 11 """まずは学習対象のモデルで推論を行う""" 12 #今回はバッチ数は1 13 y_out = self.predictor(inputimg) 14 print("y_out", y_out.ndim, y_out.shape, "t", t.ndim, t.shape) 15 #出力結果 y_out 4 (バッチ数, 3, 512, 512) t 3 (バッチ数, 512, 512) 16 loss = F.softmax_cross_entropy(y_out, t) 17 18 #ここでy_outとtの次元数を2次元する 19 t = np.squeeze(t) 20 y_out = np.delete(y_out, slice(0, 2), 1) 21 y_out = np.squeeze(y_out) 22 #確認の為にndimとshapeをそれぞれ出力 23 print("y_out", y_out.ndim, y_out.shape, "t", t.ndim, t.shape) 24 #出力結果 y_out 2 (512, 512) t 2 (512, 512) 25 26 evals = evaluations.eval_semantic_segmentation(y_out, t) 27 28 reporter.report({'loss':loss, 'miou':evals['miou'], 'pa':evals['pixel_accuracy']}, self) 29 return loss 30
あなたの回答
tips
プレビュー