我有一个多标签分类问题,我使用了以下代码。但是验证准确率在第一次 epoch 就跳到了 99%,这很奇怪,因为输入特征是从 Inception 模型 (pool3:0) 的 2048 层中提取而来的,标签是 [1000]。(这里是包含特征和标签样本的文件链接:https://drive.google.com/file/d/0BxI_8PO3YBPPYkp6dHlGeExpS1k/view?usp=sharing)那么我做错了什么吗?
注意:标签是稀疏向量,只包含 1-10 个元素的值为 1,其余为零。
注意:标签是稀疏向量,只包含 1-10 个元素的值为 1,其余为零。
model.compile(optimizer='adadelta', loss='binary_crossentropy', metrics=['accuracy'])
预测的输出结果为零!
我在训练模型时做错了什么才会影响预测?
#input is the features file and labels file
def generate_arrays_from_file(path ,batch_size=100):
x=np.empty([batch_size,2048])
y=np.empty([batch_size,1000])
while True:
f = open(path)
i = 1
for line in f:
# create Numpy arrays of input data
# and labels, from each line in the file
words=line.split(',')
words=map(float, words[1:])
x_= np.array(words[0:2048])
y_=words[2048:]
y_= np.array(map(int,y_))
x_=x_.reshape((1, -1))
#print np.squeeze(x_)
y_=y_.reshape((1,-1))
x[i]= x_
y[i]=y_
i += 1
if i == batch_size:
i=1
yield (x, y)
f.close()
model = Sequential()
model.add(Dense(units=2048, activation='sigmoid', input_dim=2048))
model.add(Dense(units=1000, activation="sigmoid",
kernel_initializer="uniform"))
model.compile(optimizer='adadelta', loss='binary_crossentropy', metrics=
['accuracy'])
model.fit_generator(generate_arrays_from_file('train.txt'),
validation_data= generate_arrays_from_file('test.txt'),
validation_steps=1000,epochs=100,steps_per_epoch=1000,
verbose=1)