I have implemented an EfficientNet in Keras for a binary problem using image generator. In the test case when i predict the output it return an array with a set of probability but referred to only one class, here the code and the output:
test_image_generator = ImageDataGenerator(
rescale=1./255
)
real_test=test_image_generator.flow_from_directory(
directory='/content/real_test',
target_size=(224, 224),
color_mode="rgb",
batch_size=1,
class_mode=None,
shuffle=False,
#seed=42
)
The output is:
real_test.reset()
from keras.models import load_model
efficient_net_custom_model = load_model('model_efficientnet4.h5',compile=False)
pred = efficient_net_custom_model.predict_(real_test, steps = len(real_test), verbose = 1)
print (pred)
Now when printing the prediction for 4 different images it returns:
[[0.45415235]
[0.52390164]
[0.9999932 ]
[0.99946016]]
Basically only one output probability (I think) for each image, and it is impossible to say which is the actual class. isn't it? How can I do to solve that issue?
Thank you
Edit:
Including model code
def output_custom_model(prebuilt_model):
print(f"Processing {prebuilt_model}")
prebuilt = prebuilt_model(include_top=False,
input_shape=(224, 224, 3),
weights='imagenet')
output = prebuilt.output
output = GlobalMaxPooling2D()(output)
output = Dense(128, activation='relu')(output)
output = Dropout(0.2)(output)
output = Dense(1, activation='sigmoid')(output)
model = Model(inputs=prebuilt.input, outputs=output)
model.compile(optimizer='sgd', loss='binary_crossentropy',
metrics=METRICS)
return model
efficient_net_custom_model = output_custom_model(EfficientNetB4)
filepath='model_efficientnet4.h5'
efficient_net_history =
efficient_net_custom_model.fit_generator(train_generator,
epochs=20,
validation_data=validation_generator,
)