我必须提交我的预测(每个预测都是2289个班级之一!)。但是,我不知道该怎么做。救救我!
模型看起来像这样 :
model = Sequential()
model.add(Conv2D(32, kernel_size = (3, 3), input_shape=(32,64,1), activation = 'relu'))
model.add(Conv2D(64, (3,3), activation='relu'))
model.add(MaxPooling2D(pool_size=2))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(2000, activation = 'relu'))
model.add(Dropout(0.6))
model.add(Dense(2289, activation='softmax'))
model.summary()
model.compile(loss = 'sparse_categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
我使用了拟合函数
history = model.fit(trainimage,trainlabel, validation_data=(validimage,validlabel), epochs=10, batch_size=200)
我想知道的是如何提取给定测试图像的预测
# Indexing of predictions
argpreds = np.argmax(history)
# Load label dictionary
with open('./drive/My Drive/Colab Notebooks/CoE202_KakaoArena/y_vocab.pickle', 'rb') as f:
y_dict = pickle.load(f)
# Inverse label dictionary
inv_y_dict = dict((y,x) for x,y in y_dict.items())
submissions = [inv_y_dict[argpred] for argpred in argpreds]
# Write the results to 'submissions.csv'
f = open('./drive/My Drive/Colab Notebooks/CoE202_KakaoArena/submissions.csv', 'w')
for i, j in zip(pids, submissions):
line = '{},{}\n'.format(i,j)
f.write(line)
f.close()
这是我助教代码的修改。但是我收到一个错误“ TypeError:'numpy.int64'对象不可迭代”
感谢您的帮助
答案 0 :(得分:-1)
通常,当您使用列表等变量时,错误对象是不可迭代的。因此,它的唯一一维数据类型(例如整型列表)。