Skip to content

Instantly share code, notes, and snippets.

View zengyu714's full-sized avatar

Yu Zeng zengyu714

  • Amazon Web Services
  • Seattle
View GitHub Profile
@zengyu714
zengyu714 / check_checkpoints.py
Last active April 19, 2017 02:18
TensorFlow utils
from tensorflow.python import pywrap_tensorflow
# Get weights or whatever you want.
# Notice the filename should be full pathname, e.g. './model-7000'
def get_weights(filename):
reader = pywrap_tensorflow.NewCheckpointReader(filename)
var_to_shape_map = reader.get_variable_to_shape_map()
weights = [reader.get_tensor(key) for key in var_to_shape_map if 'weights' in key]
return weights
@zengyu714
zengyu714 / easy_initialize.py
Last active April 19, 2017 16:25
Python gist
class Structure:
# Class variable that specifies expected fields.
_fields= []
def __init__(self, *args):
if len(args) != len(self._fields):
raise TypeError('Expected {} arguments'.format(len(self._fields)))
# Set the arguments.
for name, value in zip(self._fields, args):
#!/usr/bin/env python
"""Simple HTTP Server With Upload implemented by Python 2.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
@zengyu714
zengyu714 / iradon.m
Created May 7, 2017 09:41
Algorithms
%% Direct reconstruction
I = iradon(proj, 1);
subplot(211)
imshow(I)
title('Reconstructed `iradon`');
%% Manually implement
# Fintune models while add some new modules.
class Customize(nn.Module):
def __init__(self, pre_model):
"""Load the pretrained model, replace the last fc layers and add some new layers."""
super(Customize, self).__init__()
self.features = pre_model
# If freeze previous weights
# -------------------------------------------
@zengyu714
zengyu714 / Lecture_8: Profanity Editor.py
Last active August 30, 2017 06:19
Udacity - Full Stack Web Developer
import urllib
from tqdm import tqdm
def check_profanity(filename='./notes.txt'):
bad_words = []
with open(filename, 'r') as notes:
for line in notes:
# See whether read words well
for word in tqdm(line.split()):
# Check profanity
@zengyu714
zengyu714 / zoom-inset-axes.py
Last active November 4, 2017 01:31
plot-utils
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
# E.g., plot focal loss
def focal_loss(p, gamma):
return -np.power((1 - p), gamma) * np.log(p)
fig, ax = plt.subplots(figsize=[16, 5])
[ax.plot(xs, focal_loss(xs, g), label='$\gamma = {}$'.format(g)) for g in [0, 0.5, 1, 2, 5]]
ax.set_xlabel('')
@zengyu714
zengyu714 / loc_qrcode.ipynb
Created April 11, 2018 07:34
localize-qrcode
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zengyu714
zengyu714 / convert_to_odgt.py
Created April 25, 2018 08:05
light-head-rcnn
import json
from pathlib import Path
from tqdm import tqdm
from itertools import groupby
train_data_root = Path('/data1/kimmyzeng/dataset/Detect_COCO/train/JPEGIMAGES')
train_json_file = Path('../data/Detect_COCO/train_instances.json')
trainall_odgt = Path('../data/Detect_COCO/odformat/vehicle_trainall.odgt')
@zengyu714
zengyu714 / snippets.cson
Created August 16, 2018 16:42
atom snippets
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#