This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zipfile | |
zip_ref = zipfile.ZipFile(path_to_zip_file, 'r') | |
zip_ref.extractall(directory_to_extract_to) | |
zip_ref.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# onehot2labels() | |
def onehot2labels(y): | |
labels = [] | |
for row_element in y: | |
labels.append(np.argmax(row_element)) | |
return np.array(labels) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name | age | |
---|---|---|
bob | 47 | |
richard | 48 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from starlette.applications import Starlette | |
from starlette.responses import PlainTextResponse | |
import uvicorn | |
app = Starlette() | |
@app.route('/') | |
async def homepage(request): | |
return PlainTextResponse('') |
OlderNewer