Why do my model gives always same outputs for different inputs
Here is some main parts of my code
datagen=ImageDataGenerator(preprocessing_function=tf.keras.applications.inception_resnet_v2.preprocess_input, rescale=1./255.) # I did rescale
attention_layer,map2 = SoftAttention(aggregate=True,m=16,concat_with_x=False,ch=int(conv.shape[-1]),name='soft_attention')(conv)
attention_layer=(MaxPooling2D(pool_size=(2, 2),padding="same")(attention_layer))
conv=(MaxPooling2D(pool_size=(2, 2),padding="same")(conv))
conv = concatenate([conv,attention_layer])
conv = Activation('relu')(conv)
conv = Dropout(0.4)(conv)
output = Flatten()(conv)
output = Dense(7, activation='softmax')(output)
model = Model(inputs=irv2.input, outputs=output)
opt1=tf.keras.optimizers.Adam(lr=0.01)
model.compile(optimizer=opt1,
loss='categorical_crossentropy',
metrics=['accuracy'])
class_weights = {
0: 1.0, # akiec
1: 1.0, # bcc
2: 1.0, # bkl
3: 1.5, # df
4: 1.0, # mel
5: 1.0, # nv
6: 1.0, # vasc
}
Earlystop = EarlyStopping(monitor='val_loss', mode='min',patience=70, min_delta=0.001)
history = model.fit(train_batches,
steps_per_epoch=(len(train_df)/10),
epochs=100,
verbose=1,
validation_data=test_batches,validation_steps=len(test_df)/batch_size,callbacks=[checkpoint,Earlystop],class_weight=class_weights)
predictions = []
for i in range(len(arr)):
p = model.predict(arr[i].reshape(1,299,299,3))
print(p)
predictions.append(np.argmax(p))
but I got:
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[0. 0. 0. 0. 0. 0. 1.]]
[[1.0111562e-35 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00
0.0000000e+00 1.0000000e+00]]
and every time like this.