Skip to content

Instantly share code, notes, and snippets.

View wangg12's full-sized avatar

Gu Wang wangg12

View GitHub Profile
@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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wangg12
wangg12 / example.py
Created February 21, 2017 15:43 — forked from mrdrozdov/example.py
Logging in Tensorflow
from tf_logger import TFLogger
""" Example of using TFLogger to save train & dev statistics. To visualize
in tensorboard simply do:
tensorboard --logdir /path/to/summaries
This code does depend on Tensorflow, but does not require that your model
is built using Tensorflow. For instance, could build a model in Chainer, then