前提
SSD300を使った物体検出をに取り組んでいます。
勉強を始めたばかりで質問に不手際があったら申し訳ありません。
実現したいこと
画像に対する推論を実施した際に検出自体には成功していうるのですがすごい数の警告が出てきてしまいます。
これらの警告を出来れば出てこないようにしたいです。
発生している問題・エラーメッセージ
/content/drive/MyDrive/本実験/utils/ssd_model.py:590: UserWarning: An output with one or more elements was resized since it had shape [11], which does not match the required output shape [9]. This behavior is deprecated, and in a future PyTorch release outputs will not be resized unless they have zero elements. You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with t.resize_(0). (Triggered internally at ../aten/src/ATen/native/Resize.cpp:17.) torch.index_select(x1, 0, idx, out=tmp_x1) /content/drive/MyDrive/本実験/utils/ssd_model.py:591: UserWarning: An output with one or more elements was resized since it had shape [11], which does not match the required output shape [9]. This behavior is deprecated, and in a future PyTorch release outputs will not be resized unless they have zero elements. You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with t.resize_(0). (Triggered internally at ../aten/src/ATen/native/Resize.cpp:17.) torch.index_select(y1, 0, idx, out=tmp_y1) /content/drive/MyDrive/本実験/utils/ssd_model.py:592: UserWarning: An output with one or more elements was resized since it had shape [11], which does not match the required output shape [9]. This behavior is deprecated, and in a future PyTorch release outputs will not be resized unless they have zero elements. You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with t.resize_(0). (Triggered internally at ../aten/src/ATen/native/Resize.cpp:17.) torch.index_select(x2, 0, idx, out=tmp_x2) /content/drive/MyDrive/本実験/utils/ssd_model.py:593: UserWarning: An output with one or more elements was resized since it had shape [11], which does not match the required output shape [9]. This behavior is deprecated, and in a future PyTorch release outputs will not be resized unless they have zero elements. You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with t.resize_(0). (Triggered internally at ../aten/src/ATen/native/Resize.cpp:17.) torch.index_select(y2, 0, idx, out=tmp_y2) /content/drive/MyDrive/本実験/utils/ssd_model.py:590: UserWarning: An output with one or more elements was resized since it had shape [9], which does not match the required output shape [8]. This behavior is deprecated, and in a future PyTorch release outputs will not be resized unless they have zero elements. You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with t.resize_(0). (Triggered internally at ../aten/src/ATen/native/Resize.cpp:17.) torch.index_select(x1, 0, idx, out=tmp_x1) /content/drive/MyDrive/本実験/utils/ssd_model.py:591: UserWarning: An output with one or more elements was resized since it had shape [9], which does not match the required output shape [8]. This behavior is deprecated, and in a future PyTorch release outputs will not be resized unless they have zero elements. You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with t.resize_(0). (Triggered internally at ../aten/src/ATen/native/Resize.cpp:17.) torch.index_select(y1, 0, idx, out=tmp_y1)
該当のソースコード
python3
1from utils.ssd_model import DataTransform 2 3# 1. 画像読み込み 4image_file_path = "/content/drive/MyDrive/犬/1796780.jpg" 5img = cv2.imread(image_file_path) # [高さ][幅][色BGR] 6height, width, channels = img.shape # 画像のサイズを取得 7 8# 2. 元画像の表示 9plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) 10plt.show() 11 12# 3. 前処理クラスの作成 13color_mean = (104, 117, 123) # (BGR)の色の平均値 14input_size = 300 # 画像のinputサイズを300×300にする 15transform = DataTransform(input_size, color_mean) 16 17# 4. 前処理 18phase = "val" 19img_transformed, boxes, labels = transform(img, phase, "", "") # アノテーションはないので、""にする 20img = torch.from_numpy(img_transformed[:, :, (2, 1, 0)]).permute(2, 0, 1) 21 22# 5. SSDで予測 23net.eval() # ネットワークを推論モードへ 24x = img.unsqueeze(0) # ミニバッチ化:torch.Size([1, 3, 300, 300]) 25detections = net(x) 26 27#print(detections.shape) 28#print(detections) 29 30# output : torch.Size([batch_num, 21, 200, 5]) 31# =(batch_num、クラス、confのtop200、規格化されたBBoxの情報) 32# 規格化されたBBoxの情報(確信度、xmin, ymin, xmax, ymax) 33
補足情報(FW/ツールのバージョンなど)
google colab で実行しています。
あなたの回答
tips
プレビュー