Spaces:
Running
Running
Sadjad Alikhani
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -132,14 +132,15 @@ def plot_confusion_matrix(y_true, y_pred, title):
|
|
132 |
plt.savefig(f"{title}.png")
|
133 |
return Image.open(f"{title}.png")
|
134 |
|
135 |
-
def identical_train_test_split(output_emb, output_raw, labels,
|
136 |
N = output_emb.shape[0] # Get the total number of samples
|
137 |
|
138 |
# Generate the indices for shuffling and splitting
|
139 |
indices = torch.randperm(N) # Randomly shuffle the indices
|
140 |
|
141 |
# Calculate the split index
|
142 |
-
split_index = int(N *
|
|
|
143 |
|
144 |
# Split indices into train and test
|
145 |
train_indices = indices[:split_index] # First 80% for training
|
@@ -229,7 +230,7 @@ def process_hdf5_file(uploaded_file, percentage_idx):
|
|
229 |
# Step 8: Perform classification using the Euclidean distance for both raw and embeddings
|
230 |
pred_raw = classify_based_on_distance(train_data_raw, train_labels, test_data_raw)
|
231 |
pred_emb = classify_based_on_distance(train_data_emb, train_labels, test_data_emb)
|
232 |
-
|
233 |
# Step 9: Generate confusion matrices for both raw and embeddings
|
234 |
raw_cm_image = plot_confusion_matrix(test_labels, pred_raw, title="Confusion Matrix (Raw Channels)")
|
235 |
emb_cm_image = plot_confusion_matrix(test_labels, pred_emb, title="Confusion Matrix (Embeddings)")
|
|
|
132 |
plt.savefig(f"{title}.png")
|
133 |
return Image.open(f"{title}.png")
|
134 |
|
135 |
+
def identical_train_test_split(output_emb, output_raw, labels, percentage_idx):
|
136 |
N = output_emb.shape[0] # Get the total number of samples
|
137 |
|
138 |
# Generate the indices for shuffling and splitting
|
139 |
indices = torch.randperm(N) # Randomly shuffle the indices
|
140 |
|
141 |
# Calculate the split index
|
142 |
+
split_index = int(N * percentage_values[percentage_idx])
|
143 |
+
print(f'Training Size: {split_index}')
|
144 |
|
145 |
# Split indices into train and test
|
146 |
train_indices = indices[:split_index] # First 80% for training
|
|
|
230 |
# Step 8: Perform classification using the Euclidean distance for both raw and embeddings
|
231 |
pred_raw = classify_based_on_distance(train_data_raw, train_labels, test_data_raw)
|
232 |
pred_emb = classify_based_on_distance(train_data_emb, train_labels, test_data_emb)
|
233 |
+
print(f'pred_emb: {pred_emb}')
|
234 |
# Step 9: Generate confusion matrices for both raw and embeddings
|
235 |
raw_cm_image = plot_confusion_matrix(test_labels, pred_raw, title="Confusion Matrix (Raw Channels)")
|
236 |
emb_cm_image = plot_confusion_matrix(test_labels, pred_emb, title="Confusion Matrix (Embeddings)")
|