Skip to content

Instantly share code, notes, and snippets.

@akrylysov
akrylysov / asyncio_producer_consumer.py
Last active June 30, 2024 09:20
Python 3 asyncio basic producer / consumer example
import asyncio
import random
q = asyncio.Queue()
async def producer(num):
while True:
await q.put(num + random.random())
await asyncio.sleep(random.random())
@kylemcdonald
kylemcdonald / Keras 1D and 2D.ipynb
Created January 30, 2016 05:26
A bug in Keras?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@autosquid
autosquid / opencvyaml1-1.py
Last active September 26, 2022 08:08
pyyaml loading opencv yaml
# construct node
def opencv_matrix(loader, node):
mapping = loader.construct_mapping(node, deep=True)
mat = np.array(mapping["data"])
mat.resize(mapping["rows"], mapping["cols"])
return mat
yaml.add_constructor(u"tag:yaml.org,2002:opencv-matrix", opencv_matrix)
# loading
@jnlaia
jnlaia / script.py
Created December 9, 2015 14:00
keras MLP script to show different results between versions
import keras
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.optimizers import SGD
from keras.wrappers.scikit_learn import KerasClassifier
import numpy as np
def target2classes(y):
@andreaskoepf
andreaskoepf / SpatialUnpooling.lua
Last active December 3, 2015 08:25
A simple lena-denoising auto-encoder SpatialUnpooling test.
local SpatialUnpooling, parent = torch.class('nn.SpatialUnpooling', 'nn.Module')
function SpatialUnpooling:__init(kW, kH, dW, dH, padW, padH)
parent.__init(self)
self.dW = dW or kW
self.dH = dH or kH
self.padW = padW or 0
self.padH = padH or 0
self.indices = torch.LongTensor()
self._indexTensor = torch.LongTensor()
@karpathy
karpathy / min-char-rnn.py
Last active May 8, 2025 09:24
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@Newmu
Newmu / simple_gan.py
Created July 10, 2015 20:39
Simple Generative Adversarial Network Demo
import os
import numpy as np
from matplotlib import pyplot as plt
from time import time
from foxhound import activations
from foxhound import updates
from foxhound import inits
from foxhound.theano_utils import floatX, sharedX
@craffel
craffel / draw_neural_net.py
Created January 10, 2015 04:59
Draw a neural network diagram with matplotlib!
import matplotlib.pyplot as plt
def draw_neural_net(ax, left, right, bottom, top, layer_sizes):
'''
Draw a neural network cartoon using matplotilb.
:usage:
>>> fig = plt.figure(figsize=(12, 12))
>>> draw_neural_net(fig.gca(), .1, .9, .1, .9, [4, 7, 2])
@bravegnu
bravegnu / head.py
Last active August 25, 2016 01:19
Implementation of head using docopt
"""
Usage: head [options] [FILE]...
-c K, --bytes=K print the first K bytes of each file;
with the leading `-', print all but the last
K bytes of each file
-n K, --lines=K print the first K lines instead of the first 10;
with the leading `-', print all but the last
K lines of each file [default: 10]
-q, --quiet, --silent never print headers giving file names
@tylerneylon
tylerneylon / copy.lua
Last active March 5, 2025 13:56
How to deep copy Lua values.
-- copy.lua
--
-- Lua functions of varying complexity to deep copy tables.
--
-- 1. The Problem.
--
-- Here's an example to see why deep copies are useful. Let's
-- say function f receives a table parameter t, and it wants to