The below article will cover the intricacies of setting up databases and heroku in respect to a flask app. This is more like a memo and will have out of sequence instructions or solutions to errors so read thoroughly.
You'll need the packages
#!pip install faiss-gpu | |
import faiss | |
faiss_index = faiss.IndexFlatL2(1000) # build the index | |
# storing the image representations | |
im_indices = [] | |
with torch.no_grad(): | |
for f in glob.glob(os.path.join(PATH_TRAIN, '*/*')): | |
im = Image.open(f) | |
im = im.resize((224,224)) |
class TripletLoss(nn.Module): | |
def __init__(self, margin=1.0): | |
super(TripletLoss, self).__init__() | |
self.margin = margin | |
def calc_euclidean(self, x1, x2): | |
return (x1 - x2).pow(2).sum(1) | |
# Distances in embedding space is calculated in euclidean | |
def forward(self, anchor, positive, negative): |
class TripletData(Dataset): | |
def __init__(self, path, transforms, split="train"): | |
self.path = path | |
self.split = split # train or valid | |
self.cats = 102 # number of categories | |
self.transforms = transforms | |
def __getitem__(self, idx): | |
# our positive class for the triplet | |
idx = str(idx%self.cats + 1) |
import keras.backend as K | |
from keras.legacy import interfaces | |
from keras.optimizers import Optimizer | |
class AdamAccumulate(Optimizer): | |
def __init__(self, lr=0.001, beta_1=0.9, beta_2=0.999, | |
epsilon=None, decay=0., amsgrad=False, accum_iters=1, **kwargs): | |
if accum_iters < 1: |
model.zero_grad() # Reset gradients tensors | |
for i, (inputs, labels) in enumerate(training_set): | |
predictions = model(inputs) # Forward pass | |
loss = loss_function(predictions, labels) # Compute loss function | |
loss = loss / accumulation_steps # Normalize our loss (if averaged) | |
loss.backward() # Backward pass | |
if (i+1) % accumulation_steps == 0: # Wait for several backward steps | |
optimizer.step() # Now we can do an optimizer step | |
model.zero_grad() # Reset gradients tensors | |
if (i+1) % evaluation_steps == 0: # Evaluate the model when we... |
import pandas as pd | |
import numpy as np | |
data = pd.read_csv('movielens100k.csv') | |
data['userId'] = data['userId'].astype('string') | |
data['movieId'] = data['movieId'].astype('string') | |
users = list(set(data['userId'])) #list of all users |
The below article will cover the intricacies of setting up databases and heroku in respect to a flask app. This is more like a memo and will have out of sequence instructions or solutions to errors so read thoroughly.
You'll need the packages
Movies Recommendation:
Music Recommendation: