Spaces:
Running
Running
Sadjad Alikhani
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -371,21 +371,28 @@ def plot_confusion_matrix(y_true, y_pred, title):
|
|
371 |
# Return the saved image
|
372 |
return Image.open(f"{title}.png")
|
373 |
|
374 |
-
def identical_train_test_split(output_emb, output_raw, labels,
|
375 |
N = output_emb.shape[0] # Get the total number of samples
|
376 |
|
377 |
# Generate the indices for shuffling and splitting
|
378 |
indices = torch.randperm(N) # Randomly shuffle the indices
|
379 |
|
380 |
-
# Calculate the split index
|
381 |
-
|
382 |
-
|
383 |
-
|
|
|
384 |
|
385 |
-
#
|
386 |
-
|
387 |
-
test_indices = indices[split_index:] # Remaining 20% for testing
|
388 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
389 |
# Select the same indices from both output_emb and output_raw
|
390 |
train_emb = output_emb[train_indices]
|
391 |
test_emb = output_emb[test_indices]
|
@@ -446,7 +453,7 @@ def process_hdf5_file(uploaded_file, percentage):
|
|
446 |
|
447 |
# Step 5: Load the HDF5 file and extract the channels and labels
|
448 |
with h5py.File(uploaded_file.name, 'r') as f:
|
449 |
-
channels =
|
450 |
labels = torch.tensor(f['labels']).long() # Assuming 'labels' dataset in the HDF5 file
|
451 |
print(f"Loaded dataset with {channels.shape[0]} samples.")
|
452 |
|
|
|
371 |
# Return the saved image
|
372 |
return Image.open(f"{title}.png")
|
373 |
|
374 |
+
def identical_train_test_split(output_emb, output_raw, labels, train_percentage):
|
375 |
N = output_emb.shape[0] # Get the total number of samples
|
376 |
|
377 |
# Generate the indices for shuffling and splitting
|
378 |
indices = torch.randperm(N) # Randomly shuffle the indices
|
379 |
|
380 |
+
# Calculate the split index for test (10% of the data)
|
381 |
+
test_split_index = int(N * 0.10)
|
382 |
+
|
383 |
+
# Test indices (first 10% of the data)
|
384 |
+
test_indices = indices[:test_split_index]
|
385 |
|
386 |
+
# Remaining indices for training
|
387 |
+
remaining_indices = indices[test_split_index:]
|
|
|
388 |
|
389 |
+
# Calculate the split index for training from the remaining 90%
|
390 |
+
train_split_index = int(len(remaining_indices) * train_percentage / 100)
|
391 |
+
print(f'Training Size: {train_split_index} out of remaining {len(remaining_indices)}')
|
392 |
+
|
393 |
+
# Train indices (based on the provided percentage from the remaining 90%)
|
394 |
+
train_indices = remaining_indices[:train_split_index]
|
395 |
+
|
396 |
# Select the same indices from both output_emb and output_raw
|
397 |
train_emb = output_emb[train_indices]
|
398 |
test_emb = output_emb[test_indices]
|
|
|
453 |
|
454 |
# Step 5: Load the HDF5 file and extract the channels and labels
|
455 |
with h5py.File(uploaded_file.name, 'r') as f:
|
456 |
+
channels = torch.tensor(f['channels']).float() #astype(np.float32) # Assuming 'channels' dataset in the HDF5 file
|
457 |
labels = torch.tensor(f['labels']).long() # Assuming 'labels' dataset in the HDF5 file
|
458 |
print(f"Loaded dataset with {channels.shape[0]} samples.")
|
459 |
|