Skip to content

Instantly share code, notes, and snippets.

Avatar

João Felipe Santos jfsantos

View GitHub Profile
View logistic_regression_with_checkpointing.py
'''
A logistic regression example using the meta-graph checkpointing
features of Tensorflow.
Author: João Felipe Santos, based on code by Aymeric Damien
(https://github.com/aymericdamien/TensorFlow-Examples/)
'''
from __future__ import print_function
View example_hdf5matrix.py
from keras.models import Sequential
from keras.layers import Dense
from keras.utils.io_utils import HDF5Matrix
import numpy as np
def create_dataset():
import h5py
X = np.random.randn(200,10).astype('float32')
y = np.random.randint(0, 2, size=(200,1))
f = h5py.File('test.h5', 'w')
@jfsantos
jfsantos / AudioDisplay.jl
Created Nov 4, 2014
Rendering audio in IJulia notebooks
View AudioDisplay.jl
using WAV
function inline_audioplayer(filepath)
markup = """<audio controls="controls" {autoplay}>
<source src="$filepath" />
Your browser does not support the audio element.
</audio>"""
display(MIME("text/html") ,markup)
end
@jfsantos
jfsantos / test_ccall.jl
Last active Oct 16, 2018
Passing structures and arrays back and forth in Julia with ccall
View test_ccall.jl
immutable Cdvec
val::Ptr{Cdouble}
len::Clong
end
a = [1.0, 2.0, 3.0]
b = [3.1, 4.2, 7.3]
Ca = Cdvec(pointer(a), length(a))
Cb = Cdvec(pointer(b), length(b))
View pytorch_train_with_masking.py
def train_fn(model, optimizer, criterion, batch):
x, y, lengths = batch
x = Variable(x.cuda())
y = Variable(y.cuda(), requires_grad=False)
mask = Variable(torch.ByteTensor(x.size()).fill_(1).cuda(),
requires_grad=False)
for k, l in enumerate(lengths):
mask[:l, k, :] = 0
View audio_utils.py
import glob
import logging
import os
import numpy as np
import re
import soundfile
from numpy.lib.stride_tricks import as_strided
from maracas.maracas import asl_meter
from audio_tools import iterate_invert_spectrogram
View train_loop.py
import torch
from torch.autograd import Variable
import numpy as np
import pickle
import os
from glob import glob
from tqdm import tqdm
@jfsantos
jfsantos / error.log
Created Apr 11, 2017
Issue when compiling PyTorch on a crouton env (ASUS Chromebook Flip)
View error.log
-- Build files have been written to: /home/jfsantos/pytorch/torch/lib/build/libshm
[ 50%] Built target torch_shm_manager
[ 75%] Building CXX object CMakeFiles/shm.dir/core.cpp.o
/home/jfsantos/pytorch/torch/lib/libshm/core.cpp:149:1: error: invalid conversion from 'void* (*)(void*, long int)' to 'void* (*)(void*, ptrdiff_t) {aka void* (*)(void*, int)}' [-fpermissive]
};
^
/home/jfsantos/pytorch/torch/lib/libshm/core.cpp:149:1: error: invalid conversion from 'void* (*)(void*, void*, long int)' to 'void* (*)(void*, void*, ptrdiff_t) {aka void* (*)(void*, void*, int)}' [-fpermissive]
CMakeFiles/shm.dir/build.make:62: recipe for target 'CMakeFiles/shm.dir/core.cpp.o' failed
make[2]: *** [CMakeFiles/shm.dir/core.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/shm.dir/all' failed
View pairwise_distance.py
from __future__ import division
import multiprocessing
import scipy.spatial.distance
import numpy as np
import sklearn.datasets
from time import time
from multiprocessing import Pool
from itertools import combinations
View dummy_dataset.py
from torch.utils.data import Dataset
class DummyDataset(Dataset):
def __init__(self, items):
super(DummyDataset, self).__init__()
self.items = items
def __getitem__(self, index):
return self.items[index]