Created
March 28, 2023 11:17
-
-
Save Shamim-38/f92d0211e9eebaea49d30ba5fe90b180 to your computer and use it in GitHub Desktop.
Data Preprocessing for Authentication/Verification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import train_test_split | |
import numpy as np | |
a = ["1", "3", "4", "1", "3", "4"] | |
b = [[2, 4, 3],[0, 4, 5], [8, 9, 5], [5, 4, 5],[8, 4, 5], [2, 9, 5]] | |
y_train = np.array(a) | |
x_train = np.array(b) | |
# Step 2: Select 2 random classes for training | |
random_words = np.random.choice(np.unique(y_train), size=2, replace=False) | |
train_indices = np.isin(y_train, random_words) | |
x_train_random = x_train[train_indices] | |
y_train_random = y_train[train_indices] | |
#print(len(train_indices)) | |
#print(train_indices) | |
#print(x_train_random) | |
#print(len(x_train_random)) | |
#print(y_train_random) | |
# Step 3: Select the remaining 1 class for the gallery set | |
remaining_words = np.setdiff1d(np.unique(y_train), random_words) | |
gallery_indices = np.isin(y_train, remaining_words) | |
x_gallery_probe = x_train[gallery_indices] | |
y_gallery_probe = y_train[gallery_indices] | |
#print(x_gallery_probe) | |
#print(len(x_gallery_probe)) | |
#print(y_gallery_probe) | |
#print(len(y_gallery_probe)) | |
# Create a list containing both arrays | |
data1 = [x_train_random, y_train_random] | |
data2 = [x_gallery_probe, y_gallery_probe] | |
gallery, probe = train_test_split( | |
x_gallery_probe, test_size=0.50, random_state=42, stratify=y_gallery_probe) | |
print(gallery) | |
print(probe) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment