Skip to content

Instantly share code, notes, and snippets.

View wangg12's full-sized avatar

Gu Wang wangg12

View GitHub Profile
@wangg12
wangg12 / Local PR test and merge.md
Created December 12, 2018 13:50 — forked from adam-p/Local PR test and merge.md
Testing a pull request, then merging locally; and avoiding TOCTOU

It's not immediately obvious how to pull down the code for a PR and test it locally. But it's pretty easy. (This assumes you have a remote for the main repo named upstream.)

Getting the PR code

  1. Make note of the PR number. For example, Rod's latest is PR #37: Psiphon-Labs/psiphon-tunnel-core#37

  2. Fetch the PR's pseudo-branch (or bookmark or rev pointer whatever the word is), and give it a local branch name. Here we'll name it pr37:

$ git fetch upstream pull/37/head:pr37
@wangg12
wangg12 / CoordConvLayer.py
Created November 5, 2018 15:31 — forked from gcusso/CoordConvLayer.py
Extracted CordConvs tensorflow implementation from (An intriguing failing of convolutional neural networks and the CoordConv solution) https://arxiv.org/pdf/1807.03247.pdf
from tensorflow.python.layers import base
import tensorflow as tf
class AddCoords(base.Layer):
"""Add coords to a tensor"""
def __init__(self, x_dim=64, y_dim=64, with_r=False):
super(AddCoords, self).__init__()
self.x_dim = x_dim
self.y_dim = y_dim
@wangg12
wangg12 / coordconv2d.py
Created November 5, 2018 15:02 — forked from Dref360/coordconv2d.py
Un-scaled version of CoordConv2D
import keras.backend as K
import tensorflow as tf
from keras.layers import Layer
"""Not tested, I'll play around with GANs soon with it."""
class CoordConv2D(Layer):
def __init__(self, channel, kernel, padding='valid', **kwargs):
self.layer = Conv2D(channel, kernel, padding=padding)
import tensorflow as tf
from tensorflow.python.framework import ops
import numpy as np
# Define custom py_func which takes also a grad op as argument:
def py_func(func, inp, Tout, stateful=True, name=None, grad=None):
# Need to generate a unique name to avoid duplicates:
rnd_name = 'PyFuncGrad' + str(np.random.randint(0, 1E+8))
@wangg12
wangg12 / recursive_glob.py
Created August 2, 2018 02:55 — forked from whophil/recursive_glob.py
Recursive glob in Python: Find all files matching a glob-style pattern. Adapted from http://stackoverflow.com/a/2186565/6191541
import os
import fnmatch
def recursive_glob(rootdir='.', pattern='*'):
"""Search recursively for files matching a specified pattern.
Adapted from http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python
"""
matches = []
@wangg12
wangg12 / deep_MNIST_for_experts.py
Created July 6, 2017 14:54 — forked from saitodev/deep_MNIST_for_experts.py
Tensorflow tutorial "Deep MNIST for Experts"
from __future__ import print_function
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
import tensorflow as tf
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
@wangg12
wangg12 / pytorch_visualize.py
Created June 7, 2017 12:28 — forked from hyqneuron/pytorch_visualize.py
PyTorch graph visualization
import torch
import torch.nn as nn
from torch.nn import Parameter
from torch.autograd import Variable, Function
from collections import defaultdict
import graphviz
"""
This is a rather distorted implementation of graph visualization in PyTorch.
@wangg12
wangg12 / ResNeXt_pytorch.py
Created May 16, 2017 04:11 — forked from mjdietzx/ResNeXt_pytorch.py
pyt🔥rch implementation of ResNeXt
import torch
from torch.autograd import Variable
import torch.nn as nn
class Bottleneck(nn.Module):
cardinality = 32 # the size of the set of transformations
def __init__(self, nb_channels_in, nb_channels, nb_channels_out, stride=1):
super().__init__()
@wangg12
wangg12 / mnist_cnn_bn.py
Created May 14, 2017 13:52 — forked from tomokishii/mnist_cnn_bn.py
MNIST using Batch Normalization - TensorFlow tutorial
#
# mnist_cnn_bn.py date. 5/21/2016
#
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import numpy as np
"""
Custom datasets from both in-memory and out-of-memory data
"""
import torch.utils.data as data
from PIL import Image
import os
import os.path