Skip to content

Instantly share code, notes, and snippets.

View ashhadulislam's full-sized avatar

Ashhad ashhadulislam

View GitHub Profile
# import from selenium
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = '/Applications/Tor Browser.app/Contents/MacOS/firefox'
# the location of
if os.path.exists(binary) is False:
raise ValueError("The binary path to Tor firefox does not exist.")
firefox_binary = FirefoxBinary(binary)
browser = None
# import from selenium
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = '/Applications/Tor Browser.app/Contents/MacOS/firefox'
# the location of firefox package inside Tor
if os.path.exists(binary) is False:
raise ValueError("The binary path to Tor firefox does not exist.")
firefox_binary = FirefoxBinary(binary)
# import from selenium
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = '/Applications/Tor Browser.app/Contents/MacOS/firefox'
# the location of firefox package inside Tor
if os.path.exists(binary) is False:
raise ValueError("The binary path to Tor firefox does not exist.")
firefox_binary = FirefoxBinary(binary)
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options
# path to the firefox binary inside the Tor package
binary = '/Applications/Tor Browser.app/Contents/MacOS/firefox'
if os.path.exists(binary) is False:
raise ValueError("The binary path to Tor firefox does not exist.")
firefox_binary = FirefoxBinary(binary)
from sklearn.datasets import load_breast_cancer
import numpy as np
import collections
from knnor import data_augment
dataset = load_breast_cancer()
(unique, counts) = np.unique(dataset['target'], return_counts=True)
knnor=data_augment.KNNOR()
X_new,y_new,_,_=knnor.fit_resample(X,y)
print("Shape after augmentation",X_new.shape,y_new.shape)
elements_count = collections.Counter(y_new)
# printing the element and the frequency
print("Final distribution:")
for key, value in elements_count.items():
print(f"{key}: {value}")
X_new,y_new,_,_=knnor.fit_resample(X,y,
num_neighbors=10, # the number of neighbors that will be used for generation of each artificial point
max_dist_point=0.01, # the maximum distance at which the new point will be placed
proportion_minority=0.3, # proportion of the minority population that will be used to generate the artificial point
final_proportion=2 # final number of minority datapoints
# example, if num majority =15 and num minority =5,
# putting final_proportion as 1 will add 10 artificial minority points
)
print("Shape after augmentation",X_new.shape,y_new.shape)
elements_count = collections.Counter(y_new)
import torch
import torch.nn as nn
import torch.nn.functional as F
class MNISTNet(nn.Module):
"""Feedfoward neural network with 1 hidden layer"""
def __init__(self):
super(MNISTNet, self).__init__()
self.fc1 = nn.Linear(28*28, 256)
from torchsummary import summary
model=MNISTNet()
print("MOdel summary")
print(summary(model, input_size=(1, 28, 28), batch_size=-1))
print("Model details")
for nm, params in model.named_parameters():
if "weight" in nm and "bn" not in nm and "linear" not in nm:
print(nm, params.data.shape)
for nm, params in model.named_parameters():
if "weight" in nm and "bn" not in nm and "linear" not in nm:
print(nm, "\n", params.data)
print(params.data.shape)
print("*"*20)