Skip to content

Instantly share code, notes, and snippets.

@purva91
purva91 / augment_ResNet.py
Last active Oct 29, 2021
Pretrained_Image.py
View augment_ResNet.py
# Add our data-augmentation parameters to ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255., rotation_range = 40, width_shift_range = 0.2, height_shift_range = 0.2, shear_range = 0.2, zoom_range = 0.2, horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1.0/255.)
train_generator = train_datagen.flow_from_directory(train_dir, batch_size = 20, class_mode = 'binary', target_size = (224, 224))
validation_generator = test_datagen.flow_from_directory( validation_dir, batch_size = 20, class_mode = 'binary', target_size = (224, 224))
View 10_roc_curve.py
y_pred_proba = knn.predict_proba(X_test)[:,1]
fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba)
View SBert1_loadmodel.py
from sentence_transformers import SentenceTransformer
sbert_model = SentenceTransformer('bert-base-nli-mean-tokens')
View InferSent2_loadmodel.py
from models import InferSent
import torch
V = 2
MODEL_PATH = 'encoder/infersent%s.pkl' % V
params_model = {'bsize': 64, 'word_emb_dim': 300, 'enc_lstm_dim': 2048,
'pool_type': 'max', 'dpout_model': 0.0, 'version': V}
model = InferSent(params_model)
model.load_state_dict(torch.load(MODEL_PATH))
View 1_tokenize.py
from nltk.tokenize import word_tokenize
# Tokenization of each document
tokenized_sent = []
for s in sentences:
tokenized_sent.append(word_tokenize(d.lower()))
tokenized_sent
View USE1_install.py
!pip3 install --upgrade tensorflow-gpu
# Install TF-Hub.
!pip3 install tensorflow-hub
View SE1_setup.py
import nltk
nltk.download('punkt')
from nltk.tokenize import word_tokenize
import numpy as np
View train_test_k_20.txt
train_score = []
test_score = []
k_vals = []
for k in range(1, 21):
k_vals.append(k)
knn = KNeighborsClassifier(n_neighbors = k)
knn.fit(X_train, y_train)
tr_score = knn.score(X_train, y_train)
View read_info
data_file_path = 'diabetes.csv'
data_df = pd.read_csv(data_file_path)
data_df.head()
View import_packages.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline