Skip to content

Instantly share code, notes, and snippets.

Avatar

Gu Wang wangg12

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

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: https://github.com/Psiphon-Labs/psiphon-tunnel-core/pull/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 Nov 5, 2018 — 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
View CoordConvLayer.py
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 Nov 5, 2018 — forked from Dref360/coordconv2d.py
Un-scaled version of CoordConv2D
View coordconv2d.py
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)
View Tensorflow_py_func_with_grad.py
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 Aug 2, 2018 — 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
View recursive_glob.py
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 Jul 6, 2017 — forked from saitodev/deep_MNIST_for_experts.py
Tensorflow tutorial "Deep MNIST for Experts"
View deep_MNIST_for_experts.py
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 Jun 7, 2017 — forked from hyqneuron/pytorch_visualize.py
PyTorch graph visualization
View pytorch_visualize.py
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 — forked from mjdietzx/ResNeXt_pytorch.py
pyt🔥rch implementation of ResNeXt
View ResNeXt_pytorch.py
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 — forked from tomokishii/mnist_cnn_bn.py
MNIST using Batch Normalization - TensorFlow tutorial
View mnist_cnn_bn.py
#
# 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
View co_classes.py
"""
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