Skip to content

Instantly share code, notes, and snippets.

Avatar

Dmitry Ulyanov DmitryUlyanov

View GitHub Profile
View wget_drive.py
import requests
def download_file_from_google_drive(id, destination):
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
View sample_entropy.py
import torch
import torch.nn
from torch.autograd import Variable
def pairwise_euclidean(samples):
B = samples.size(0)
samples_norm = samples.mul(samples).sum(1)
samples_norm = samples_norm.expand(B, B)
View Springleaf.html
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" />
<title>Feats_work-clean</title><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<style type="text/css">
/*!
*
@DmitryUlyanov
DmitryUlyanov / html_server.py
Created May 11, 2017
Do not remember why, but starting server this correct is better
View html_server.py
from flask import Flask, request, render_template
app = Flask(__name__, static_url_path='', static_folder='')
@app.route('/')
def root():
return app.send_static_file('sr_set5.html')
@app.route('/readme')
@DmitryUlyanov
DmitryUlyanov / imscatter.py
Last active May 11, 2017
draws images at given 2d coordinates like T-SNE of MNIST
View imscatter.py
def imscatter(images, positions):
positions = np.array(positions)
bottoms = positions[:,1] - np.array([im.shape[1]/2.0 for im in images])
tops = bottoms + np.array([im.shape[1] for im in images])
lefts = positions[:,0] - np.array([im.shape[0]/2.0 for im in images])
rigths = lefts + np.array([im.shape[0] for im in images])
View trilinear_interpolation.py
import numba
def FindLowAndHighIndices(x, m):
xf = np.floor(x)
l = np.clip(xf, 0, m-1).astype(int)
h = np.clip(xf + 1, 0, m-1).astype(int)
return l, h
View get_sample_grid.py
import random
from PIL import Image
import glob
import numpy as np
def get_sample_grid_(paths, grid_w=4, grid_h=4, imsize_w=256, imsize_h=256):
imgs = []
for p in paths:
imgs.append(np.array(Image.open(p).convert('RGB').resize([imsize_w,imsize_h])))
View run_batch.py
from joblib import Parallel, delayed
import Queue
import os
# Define number of GPUs available
N_GPU = 4
# Put indices in queue
q = Queue.Queue(maxsize=N_GPU)
for i in range(N_GPU):
View run_batch2.py
from __future__ import print_function
import threading
from joblib import Parallel, delayed
import Queue
import os
# Fix print
_print = print
_rlock = threading.RLock()
def print(*args, **kwargs):
View test_backend.py
from __future__ import print_function
import threading
from joblib import Parallel, delayed
import Queue
# Fix print
_print = print
_rlock = threading.RLock()
def print(*args, **kwargs):
with _rlock: