Commit c5fd99a0 authored by Hotwani's avatar Hotwani
Browse files

Commit for generating prediction report

parent 64cb9f8b
Pipeline #2002 failed with stages
......@@ -37,6 +37,7 @@ def extract_features(trainingDataDir, trainingDataSubDirs):
create_csv_header()
# Looping over every file inside the subdirectories for feature extraction
for trainingDataSubDir in trainingDataSubDirs:
if os.path.isdir(trainingDataSubDir):
for audio_file_name in os.listdir(trainingDataDir/f'{trainingDataSubDir}'):
if audio_file_name.endswith(".wav"):
audio_file = trainingDataDir/f'{trainingDataSubDir}/{audio_file_name}'
......@@ -121,17 +122,20 @@ def train_and_save_model(compiledModel, X_train, y_train, X_test, y_test):
callbacks=[tensorboard_callback])
# Saving the trained model to avoid re-training
#print(training_history)
compiledModel.save(constants.TRAINED_MODEL)
return training_history
def predict(X_test, y_test):
def predict(X_test, y_test, encoder):
print("Predictions.....")
final_predictions = np.argmax(compiled_model.predict(X_test), axis=-1)
target_names = [constants.LIGHT_WEIGHT, constants.MEDIUM_WEIGHT, constants.HEAVY_WEIGHT, constants.TWO_WHEELED,
constants.RAIL_BOUND]
test_labels = encoder.inverse_transform(y_test)
output_labels = encoder.inverse_transform(final_predictions)
print(classification_report(y_test, final_predictions, target_names=target_names))
df = pd.DataFrame({"Actual Output": test_labels, "Predicted Output": output_labels})
df.to_csv(r'prediction_report.csv', index=False)
# Changing Directory to Training Dataset Folder
......@@ -145,4 +149,4 @@ X_input_features = normalize_data(processed_features_data)
X_train_data, X_test_data, y_train_data, y_test_data = train_test_data_split(X_input_features, target_audio_labels)
compiled_model = create_and_compile_model()
model_training_history = train_and_save_model(compiled_model, X_train_data, y_train_data, X_test_data, y_test_data)
predict(X_test_data, y_test_data)
predict(X_test_data, y_test_data, encoder_object)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment