質問編集履歴
1
該当のソースコードに全コードを載せました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,11 +22,52 @@
|
|
22
22
|
AttributeError: '_SingleProcessDataLoaderIter' object has no attribute 'next'
|
23
23
|
|
24
24
|
### 該当のソースコード
|
25
|
+
|
26
|
+
|
27
|
+
data_type = "学習データ"
|
28
|
+
batch_size = 8
|
29
|
+
|
30
|
+
モデルの選択 = "自作のモデル"
|
31
|
+
|
32
|
+
# 入力画像を表示する関数の作成
|
33
|
+
def imshow(img):
|
34
|
+
img = img / 2 + 0.5
|
35
|
+
plt.title("予測に使った画像")
|
36
|
+
plt.imshow(img.transpose(0, 1).transpose(1, 2))
|
37
|
+
plt.axis("off")
|
38
|
+
plt.show()
|
39
|
+
|
40
|
+
def prediction(model, inputs):
|
41
|
+
|
42
|
+
imshow(torchvision.utils.make_grid(inputs))
|
43
|
+
outputs = model(inputs.to(device))
|
44
|
+
outputs = outputs.to("cpu").argmax(dim=1)
|
45
|
+
|
46
|
+
# 数値から名称に変換
|
47
|
+
ans = []
|
48
|
+
sorted_keys = sorted(keywords)
|
49
|
+
for label in outputs:
|
50
|
+
for index in range(len(keywords)):
|
51
|
+
if label==index:
|
52
|
+
ans.append(sorted_keys[index])
|
53
|
+
print("AIの予測結果", ans)
|
54
|
+
|
55
|
+
if data_type=="学習データ":
|
56
|
+
prediction_subset = train_subset
|
57
|
+
else :
|
58
|
+
prediction_subset = test_subset
|
59
|
+
model = cnn if モデルの選択 =="自作のモデル" else transfer_model
|
60
|
+
|
61
|
+
# データローダー
|
25
|
-
prediction_loader = torch.utils.data.DataLoader(prediction_subset, batch_size=
|
62
|
+
prediction_loader = torch.utils.data.DataLoader(prediction_subset, batch_size=predict_num, shuffle=True)
|
63
|
+
# データローダーから1バッチ分データを取り出す
|
26
|
-
inputs, _ = iter(prediction_loader).next(
|
64
|
+
inputs, _ = iter(prediction_loader).next()
|
65
|
+
# 予測する
|
27
|
-
prediction(
|
66
|
+
prediction(cnn, inputs)
|
28
67
|
|
29
68
|
### 補足情報(FW/ツールのバージョンなど)
|
30
69
|
|
31
70
|
google コラボラトリを用いています
|
71
|
+
inputs, _ = iter(prediction_loader).next()でエラーが起きるのですが
|
72
|
+
昨年まではこんなところでエラーが起きず、バージョン変更によるエラーなのでしょうk、、、
|
32
73
|
|