Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get predict_data.num_classes if trained_model havent num_classes #1199

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ def predict_cnn(trained_model, predict_data: InputData, output_mode: str = 'labe
prediction = np.round(trained_model.predict(transformed_x_test))
elif output_mode in ['probs', 'full_probs', 'default']:
prediction = trained_model.predict(transformed_x_test)
if trained_model.num_classes < 2:
num_classes = 0

try:
num_classes = trained_model.num_classes
except AttributeError:
num_classes = predict_data.num_classes

if num_classes < 2:
logger.error('Data set contain only 1 target class. Please reformat your data.')
raise ValueError('Data set contain only 1 target class. Please reformat your data.')
elif trained_model.num_classes == 2 and output_mode != 'full_probs' and len(prediction.shape) > 1:
elif num_classes == 2 and output_mode != 'full_probs' and len(prediction.shape) > 1:
prediction = prediction[:, 1]
else:
raise ValueError(f'Output model {output_mode} is not supported')
Expand Down
Loading