Skip to content

Instantly share code, notes, and snippets.

View thunderInfy's full-sized avatar
📈

Aditya Rastogi thunderInfy

📈
View GitHub Profile
# defining our deep learning architecture
resnetq = resnet18(pretrained=False)
classifier = nn.Sequential(OrderedDict([
('fc1', nn.Linear(resnetq.fc.in_features, 100)),
('added_relu1', nn.ReLU(inplace=True)),
('fc2', nn.Linear(100, 50)),
('added_relu2', nn.ReLU(inplace=True)),
('fc3', nn.Linear(50, 25))
]))
class LinearNet(nn.Module):
def __init__(self):
super(LinearNet, self).__init__()
self.fc1 = torch.nn.Linear(50, 5)
def forward(self, x):
x = self.fc1(x)
return(x)
import matplotlib.pyplot as plt
from sklearn.manifold import TSNE
import seaborn as sns
tsne = TSNE()
def plot_vecs_n_labels(v,labels,fname):
fig = plt.figure(figsize = (10, 10))
plt.axis('off')
sns.set_style("darkgrid")
sns.scatterplot(v[:,0], v[:,1], hue=labels, legend='full', palette=sns.color_palette("bright", 5))
resnet = resnet18(pretrained=False)
classifier = nn.Sequential(OrderedDict([
('fc1', nn.Linear(resnet.fc.in_features, 100)),
('added_relu1', nn.ReLU(inplace=True)),
('fc2', nn.Linear(100, 50)),
('added_relu2', nn.ReLU(inplace=True)),
('fc3', nn.Linear(50, 25))
]))
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(){
srand(getpid());
int N = 10;
all:
flex flexcode.l
bison -d bisoncode.y
gcc -o executable bisoncode.tab.c lex.yy.c -lfl
clean:
rm -f bisoncode.tab.c
rm -f bisoncode.tab.h
rm -f bisoncode.output
rm -f lex.yy.c
%{
#include <stdio.h>
#include <string.h>
int yylex();
int yyerror(char *s);
%}
%token STRING NUMBER SEMICOLON OTHER
%type <name> STRING
%union{
%{
#include <stdio.h>
#include "bisoncode.tab.h"
%}
STRING ([a-zA-Z])+
NUMBER [0-9]+
%%
{STRING} {sscanf(yytext, "%s", yylval.name); return STRING;}
def loss(a,b):
a_norm = torch.norm(a,dim=1).reshape(-1,1)
a_cap = torch.div(a,a_norm)
b_norm = torch.norm(b,dim=1).reshape(-1,1)
b_cap = torch.div(b,b_norm)
a_cap_b_cap = torch.cat([a_cap,b_cap],dim=0)
a_cap_b_cap_transpose = torch.t(a_cap_b_cap)
b_cap_a_cap = torch.cat([b_cap,a_cap],dim=0)
sim = torch.mm(a_cap_b_cap,a_cap_b_cap_transpose)
sim_by_tau = torch.div(sim,tau)
def get_color_distortion(s=1.0):
# s is the strength of color distortion.
color_jitter = T.ColorJitter(0.8 * s, 0.8 * s, 0.8 * s, 0.2 * s)
rnd_color_jitter = T.RandomApply([color_jitter], p=0.8)
rnd_gray = T.RandomGrayscale(p=0.2)
color_distort = T.Compose([rnd_color_jitter, rnd_gray])
return color_distort
class MyDataset(Dataset):