Skip to content

Instantly share code, notes, and snippets.

View mihirkhandekar's full-sized avatar
💻

Mihir Khandekar mihirkhandekar

💻
View GitHub Profile
@mihirkhandekar
mihirkhandekar / sg_pincodes.csv
Created November 28, 2024 13:49
CSV of all pincodes in Singapore
We can't make this file beautiful and searchable because it's too large.
PostalCode,Latitude,Longitude
118547,1.2762,103.7931
118552,1.2765,103.7924
118546,1.2761,103.7931
118549,1.2769,103.7932
118555,1.2773,103.7908
118553,1.2766,103.792
118551,1.2764,103.7928
118554,1.277,103.7909
118556,1.2775,103.7897
dataset_path = "datasets/purchase100.txt"
datahandler = advreg_wrapper.get_datahandler(dataset_path=dataset_path,
batch_size=128,
training_size=20000)
def classification_nn_model(input_features):
initializer = tf.compat.v1.keras.initializers.random_normal(0.0, 0.01)
model = tf.keras.Sequential(
[
keraslayers.Dense(
512,
activation = tf.nn.tanh,
input_shape = (input_features,),
kernel_initializer = initializer,
bias_initializer = 'zeros'
# `saved_path` is required for obtaining the training data that was used to
# train the target classification model, in "npy" format
saved_path = "datasets/purchase100.txt.npy"
# Similar to `saved_path` being used to form the memberset for attack model,
# `dataset_path` is used for forming the non-member set of the training data of
# attack model.
dataset_path = 'datasets/purchase100.txt'
datahandlerA = ml_privacy_meter.utils.attack_data.attack_data(dataset_path=dataset_path,
# Load the classification model by passing the model, that
# you'd like to train, in `model` argument
advreg_wrapper.load_classification(model=cmodel,
optimizer="adam",
learning_rate=0.001)
advreg_wrapper.load_inference(optimizer="adam", learning_rate=0.0001)
# begins training in an adversarial manner (with defense if _lambda > 0)
advreg_wrapper.begin_advreg_training(datahandler=datahandler,
attackobj = ml_privacy_meter.attack.meminf.initialize(
target_train_model=cmodelA,
target_attack_model=cmodelA,
train_datahandler=datahandlerA,
attack_datahandler=datahandlerA,
layers_to_exploit=[3, 4],
gradients_to_exploit=[4])
attackobj.train_attack()
def classification_nn_model(input_features):
initializer = tf.compat.v1.keras.initializers.random_normal(0.0, 0.01)
model = tf.keras.Sequential(
[
keraslayers.Dense(
512,
activation = tf.nn.tanh,
input_shape = (input_features,),
kernel_initializer = initializer,
bias_initializer = 'zeros'