Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Hotwani
HPC_Vehicle_Classification
Commits
c5fd99a0
Commit
c5fd99a0
authored
4 years ago
by
Hotwani
Browse files
Options
Download
Email Patches
Plain Diff
Commit for generating prediction report
parent
64cb9f8b
development
No related merge requests found
Pipeline
#2002
failed with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+32
-28
main.py
with
32 additions
and
28 deletions
+32
-28
main.py
+
32
-
28
View file @
c5fd99a0
...
@@ -37,6 +37,7 @@ def extract_features(trainingDataDir, trainingDataSubDirs):
...
@@ -37,6 +37,7 @@ def extract_features(trainingDataDir, trainingDataSubDirs):
create_csv_header
()
create_csv_header
()
# Looping over every file inside the subdirectories for feature extraction
# Looping over every file inside the subdirectories for feature extraction
for
trainingDataSubDir
in
trainingDataSubDirs
:
for
trainingDataSubDir
in
trainingDataSubDirs
:
if
os
.
path
.
isdir
(
trainingDataSubDir
):
for
audio_file_name
in
os
.
listdir
(
trainingDataDir
/
f
'
{
trainingDataSubDir
}
'
):
for
audio_file_name
in
os
.
listdir
(
trainingDataDir
/
f
'
{
trainingDataSubDir
}
'
):
if
audio_file_name
.
endswith
(
".wav"
):
if
audio_file_name
.
endswith
(
".wav"
):
audio_file
=
trainingDataDir
/
f
'
{
trainingDataSubDir
}
/
{
audio_file_name
}
'
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):
...
@@ -121,17 +122,20 @@ def train_and_save_model(compiledModel, X_train, y_train, X_test, y_test):
callbacks
=
[
tensorboard_callback
])
callbacks
=
[
tensorboard_callback
])
# Saving the trained model to avoid re-training
# Saving the trained model to avoid re-training
#print(training_history)
compiledModel
.
save
(
constants
.
TRAINED_MODEL
)
compiledModel
.
save
(
constants
.
TRAINED_MODEL
)
return
training_history
return
training_history
def
predict
(
X_test
,
y_test
):
def
predict
(
X_test
,
y_test
,
encoder
):
print
(
"Predictions....."
)
print
(
"Predictions....."
)
final_predictions
=
np
.
argmax
(
compiled_model
.
predict
(
X_test
),
axis
=-
1
)
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
,
target_names
=
[
constants
.
LIGHT_WEIGHT
,
constants
.
MEDIUM_WEIGHT
,
constants
.
HEAVY_WEIGHT
,
constants
.
TWO_WHEELED
,
constants
.
RAIL_BOUND
]
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
))
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
# Changing Directory to Training Dataset Folder
...
@@ -145,4 +149,4 @@ X_input_features = normalize_data(processed_features_data)
...
@@ -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
)
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
()
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
)
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
)
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets