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
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates.
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@zengyu714
zengyu714 / git_rebase.md
Created December 22, 2021 18:05 — forked from ravibhure/git_rebase.md
Git rebase from remote fork repo

In your local clone of your forked repository, you can add the original GitHub repository as a "remote". ("Remotes" are like nicknames for the URLs of repositories - origin is one, for example.) Then you can fetch all the branches from that upstream repository, and rebase your work to continue working on the upstream version. In terms of commands that might look like:

Add the remote, call it "upstream":

git remote add upstream https://github.com/whoever/whatever.git

Fetch all the branches of that remote into remote-tracking branches, such as upstream/master:

git fetch upstream

@zengyu714
zengyu714 / setup.sh
Last active November 30, 2021 02:46 — forked from bradp/setup.sh
New Mac Setup Script
# echo "Creating an SSH key for you..."
# ssh-keygen -t rsa
# setup github key following https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
echo "Installing xcode-stuff"
xcode-select --install
# Check for Homebrew,
# Install if we don't have it
if test ! $(which brew); then
@zengyu714
zengyu714 / disjoint-set-union.py
Last active September 4, 2019 14:34
Algorithms
class DSU:
"""
Disjoint set union with union-by-rank
"""
def __init__(self, n):
# may need to alter the total number, like (n + 1)
self.parent = list(range(n))
self.rank = [0] * n
# count of dsu
self.count = n
@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:
#
@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 / 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 / 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 / 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
# 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
# -------------------------------------------