Skip to content

Instantly share code, notes, and snippets.

View ceshine's full-sized avatar

CeShine Lee ceshine

View GitHub Profile
@ceshine
ceshine / resize_and_pad.py
Created July 7, 2018 05:35
Resize and Pad the image to Square Size
from torchvision import transforms
from PIL import ImageOps
class ResizeAndPad(object):
def __init__(self, size, interpolation=Image.BILINEAR):
assert isinstance(size, int)
self.size = size
self.interpolation = interpolation
def __call__(self, img):
@ceshine
ceshine / stlr.py
Last active March 5, 2023 12:13
Pytorch Slanted Triangular Learning Rate Scheduler
class STLR(torch.optim.lr_scheduler._LRScheduler):
def __init__(self, optimizer, max_mul, ratio, steps_per_cycle, decay=1, last_epoch=-1):
self.max_mul = max_mul - 1
self.turning_point = steps_per_cycle // (ratio + 1)
self.steps_per_cycle = steps_per_cycle
self.decay = decay
super().__init__(optimizer, last_epoch)
def get_lr(self):
residual = self.last_epoch % self.steps_per_cycle
@ceshine
ceshine / bactrader_sample.py
Last active May 4, 2023 12:38
A Simple Strategy Trading Two Stocks (back trader)
"""A Simple Strategy Trading Two Stocks
Original code: https://blog.csdn.net/qq_26948675/article/details/80016633
Modified based on: https://www.backtrader.com/blog/posts/2018-04-22-improving-code/improving-code.html
Replaced the local CSV files with online data from IEX.
Unfortunately, this strategy is not profitable for the two stocks picked.
"""
@ceshine
ceshine / python_in_visual_studio_code.md
Last active August 5, 2019 09:30
How To Develop Python Programs in Visual Studio Code

How To Develop Python Programs in Visual Studio Code

Prerequisites

You have to already have these in your system:

@ceshine
ceshine / keras-fashion-mnist-cpu.ipynb
Created October 8, 2018 08:48
Keras Fashion MNIST - CPU
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / keras-fashion-mnist-gpu.ipynb
Created October 8, 2018 08:53
Keras Fashion MNIST - GPU
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / keras-fashion-mnist-tpu.ipynb
Created October 8, 2018 08:53
Keras Fashion MNIST - TPU
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / plotting.R
Created October 8, 2018 10:33
Plotting Script for the TPU blog psot
library(ggplot2)
library(ggthemes)
dat <- data.frame(
name = c("CPU", "GPU", "TPU"),
time = c(3 * 3600 + 6 * 60 + 4, 3 * 60 + 16, 1 * 60 + 42)
)
dat$log_time = log(dat$time)
ggplot(data=dat, aes(x=name, y=log_time)) +
@ceshine
ceshine / extract.py
Last active October 29, 2018 04:01
Scripts to scrape and extract data from the Tourism Bureau of Taiwan
# WARNING: this script is out-dated since the last update of the Tourism Bureau website.
from pathlib import Path
import pandas as pd
SCHEMAS = [
(201201, "schema/residence-2012-01.csv"),
(201101, "schema/residence-2011-01.csv")
]
DATA_FILE_PATTERN = "raw_data/{year}-{month}.xls"