Skip to content

Instantly share code, notes, and snippets.

View greed2411's full-sized avatar
:octocat:
chilling at some local minima ...

Jaivarsan greed2411

:octocat:
chilling at some local minima ...
View GitHub Profile
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
import uvicorn
app = Starlette()
@app.route('/')
async def homepage(request):
return PlainTextResponse('')
@greed2411
greed2411 / dice_coefficient.py
Created October 4, 2018 10:24
dice coefficient
def dice_loss(input, target):
smooth = 1.
iflat = input.view(-1)
tflat = target.view(-1)
intersection = (iflat * tflat).sum()
return 1 - ((2. * intersection + smooth) /
(iflat.sum() + tflat.sum() + smooth))
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.utils.np_utils import to_categorical
from keras.models import Sequential
from keras.layers.embeddings import Embedding
from keras.layers.core import Dense, Dropout
from keras.layers import LSTM
from keras.regularizers import l2
from keras.optimizers import Adam
from vibora import Vibora, Response
app = Vibora()
@app.route('/')
async def index():
return Response(b'', headers={'content-type': 'html'})
@app.route("/user/<int:id>", methods=['GET'])
async def user_info(id):
@greed2411
greed2411 / data.csv
Created June 18, 2018 13:27
torch text
name age
bob 47
richard 48
# onehot2labels()
def onehot2labels(y):
labels = []
for row_element in y:
labels.append(np.argmax(row_element))
return np.array(labels)
@greed2411
greed2411 / extract_zip.py
Last active May 30, 2018 08:25
colab extras
import zipfile
zip_ref = zipfile.ZipFile(path_to_zip_file, 'r')
zip_ref.extractall(directory_to_extract_to)
zip_ref.close()
import os
import img2pdf
# takes all the images in the current working directory and puts as one centered image per page
with open("output.pdf", "wb") as f:
f.write(img2pdf.convert([i for i in os.listdir(os.getcwd()) if i.endswith(".jpg")]))
@greed2411
greed2411 / unique_id.py
Created February 18, 2018 16:38
A unique cookie secret.
import base64, uuid
def cookie_secret():
return base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)
if __name__ == "__main__":
print(base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes))
@greed2411
greed2411 / model_validating.py
Created January 2, 2018 13:32
script for loading the pytorch model, and processing incoming image and get the output for the skin cancer detection.
import torch
import torchvision
from torchvision import datasets, transforms, models
import torch.nn as nn
from torch.autograd import Variable
from PIL import Image
import numpy as np
# >>> torch.__version__
# '0.2.0_4'