Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jiqiujia
jiqiujia / dcgan.py
Created January 30, 2017 13:43 — forked from soumith/dcgan.py
import torch
import torch.nn as nn
import torch.nn.parallel
class DCGAN_D(nn.Container):
def __init__(self, isize, nz, nc, ndf, ngpu, n_extra_layers=0):
super(DCGAN_D, self).__init__()
self.ngpu = ngpu
assert isize % 16 == 0, "isize has to be a multiple of 16"
@jiqiujia
jiqiujia / utils.py
Last active April 1, 2017 09:15
keras
#adjust learning rate policy by callbacks
def scheduler(epoch):
if epoch == 5:
model.lr.set_value(.02)
return model.lr.get_value()
change_lr = LearningRateScheduler(scheduler)
model.fit(x_embed, y, nb_epoch=1, batch_size = batch_size, show_accuracy=True,
callbacks=[chage_lr])
@jiqiujia
jiqiujia / ncut.py
Last active December 24, 2016 08:39
graph util functions in python, from https://github.com/mdeff/ntds_2016
# ### python_ncut_lib.py
# Copyright (C) 2010 R. Cameron Craddock ([email protected])
#
# This script is a part of the pyClusterROI python toolbox for the spatially constrained clustering of fMRI
# data. It provides the library functions for performing normalized cut clustering according to:
#
# Shi, J., & Malik, J. (2000). Normalized cuts and image segmentation. IEEE Transactions on Pattern Analysis
# and Machine Intelligence, 22(8), 888-905. doi: 10.1109/34.868688.
#
# Yu, S. X., & Shi, J. (2003). Multiclass spectral clustering. Proceedings Ninth IEEE International Conference
"Pathogen
execute pathogen#infect()
syntax on
filetype plugin indent on
"NERDtree
" open NERDTree with ctrl+n
map <F2> :NERDTreeToggle<CR>
" close vim if the only window left open is a NERDTree
autocmd bufenter * if(winnr("$")==1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
@jiqiujia
jiqiujia / tmux.conf
Last active March 14, 2017 08:04
tmux2.3 configuration file
#设置前缀为Ctrl + a
unbind ^b
set -g prefix 'C-a'
#将r 设置为加载配置文件,并显示信息
bind r source-file ~/.tmux.conf \; display-message "Config reloaded"
#up
bind-key k select-pane -U
#down
bind-key j select-pane -D
@jiqiujia
jiqiujia / magnet_loss_utils.py
Created November 21, 2016 11:28
util functions of paper 'metric learning with adaptive density discrimination'
from math import ceil
import numpy as np
from sklearn.cluster import KMeans
import theano
import theano.tensor as T
def compute_reps(extract_fn, X, chunk_size):
"""Compute representations for input in chunks."""
chunks = int(ceil(float(X.shape[0]) / chunk_size))
@jiqiujia
jiqiujia / learn.lua
Created November 7, 2016 14:03 — forked from tylerneylon/learn.lua
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@jiqiujia
jiqiujia / clustering.py
Last active June 5, 2017 08:55
python util functions/preprocessing
def create_conf_matrix(expected, predicted, n_classes):
m = np.zeros((n_classes, n_classes))
for pred, exp in zip(predicted, expected):
m[pred][exp] += 1
return m
def calc_accuracy(conf_matrix):
t = sum(sum(l) for l in conf_matrix)
return sum(conf_matrix[i][i] for i in range(len(conf_matrix))) / t
@jiqiujia
jiqiujia / layers.py
Last active February 15, 2017 15:07
theano
class BatchNormLayer(lasagne.layers.Layer):
def __init__(self, incoming, b=lasagne.init.Constant(0.), g=lasagne.init.Constant(1.),
W=lasagne.init.Normal(0.05), nonlinearity=relu, **kwargs):
super(BatchNormLayer, self).__init__(incoming, **kwargs)
self.nonlinearity = nonlinearity
k = self.input_shape[1]
if b is not None:
self.b = self.add_param(b, (k,), name="b", regularizable=False)
if g is not None:
self.g = self.add_param(g, (k,), name="g")