我在keras研究一个计算机视觉问题,遇到了一个有趣的问题。我的valu acc是0.0000e+00。这特别有趣,因为我的其他指标,如loss、acc和valu loss都正常工作
当我从序列数据生成器切换到一个自定义生成器时,这种情况就开始发生了,我非常确定它能按预期工作。
我的问题与这个问题非常相似validation accuracy is 0 with Keras fit_generator,但在该线程中没有找到答案。
我已经检查,以确保我的激活和损失指标是适合我的特定问题。我正在使用:loss='categorical\u crossentropy'metrics=['accurity'],并试图预测某个光谱图的来源月份。
验证数据的加载方式与训练数据完全相同,所以我真的无法弄清楚发生了什么,即使是随机猜测也应该给出1/12的值,对吗?不可能是零
以下是我的模型架构:
x = (Convolution2D(32,5,5,activation='relu',input_shape=(501,501,1)))(input_img)
x = (MaxPooling2D(pool_size=(2,2)))(x)
x = (Convolution2D(32,5,5,activation='relu'))(x)
x = (MaxPooling2D(pool_size=(2,2)))(x)
x = (Dropout(0.25))(x)
x = (Flatten())(x)
x = (Dense(128,activation='relu'))(x)
x = (Dropout(0.5))(x)
classify = (Dense(12,activation='softmax', kernel_regularizer=regularizers.l1_l2(l1 = 0.001,l2 = 0.001)))(x)
model = Model(input_img,classify)
model.compile(loss='categorical_crossentropy',optimizer='nadam',metrics=['accuracy'])
下面是我对fit\u generator的要求:
model.fit_generator(generator = pd.data_generator(folder,'train'),
validation_data = pd.data_generator(folder,'test'),
steps_per_epoch=(120),
validation_steps=(24),
nb_epoch=20,
verbose=1,
shuffle=True,
callbacks=[tensorboard_callback,early_stop_callback])
最后是我的数据生成器的重要部分:
if mode == 'test':
print('test')
while True:
for things in up.unpickle_batch(folder,50,6000,7200): #The last 1200 things in batches of 50
random.shuffle(things)
test_spect = []
test_months = []
for thing in things:
test_spect.append(thing.spect) #GET BATCH DATA
test_months.append(thing.month-1) #this is is here because the months go from 1-12 but should go from 0-11 for to_categorical
x_test = np.asarray(test_spect) #PREPARE BATCH DATA
x_test = x_test.astype('float32')
x_test /= np.amax(x_test) #- 0.5
X_test = np.reshape(x_test, (-1,501, 501,1))
Y_test = np_utils.to_categorical(test_months,12)
yield X_test,Y_test #RETURN BATCH DATA
目前没有回答
相关问题 更多 >
编程相关推荐