Skip to content

Instantly share code, notes, and snippets.

@yunlongdong
yunlongdong / GenPDF2d.py
Last active April 6, 2019 05:53
generate PDF from a gray image
import numpy as np
from skimage.data import camera
import matplotlib.pyplot as plt
img = camera().astype('float32')
f = (img/img.sum()).ravel()
p = np.cumsum(f)
ys = np.random.rand(500)
xs = np.searchsorted(p, ys)
buf = np.zeros(img.shape)
@yunlongdong
yunlongdong / trans_utils.py
Created March 24, 2019 05:15
Transfromation between quternion and euler angle
from math import *
def euler2q(roll, pitch, yaw):
"""
https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
"""
cy = cos(yaw * 0.5)
sy = sin(yaw * 0.5)
cp = cos(pitch * 0.5)
sp = sin(pitch * 0.5)
@yunlongdong
yunlongdong / dataloader.py
Created December 24, 2018 10:28
Pytorch Generic Dataloader
import torch
import torch.nn as nn
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms
from PIL import Image as Image
import os
import pdb
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])
@yunlongdong
yunlongdong / classifier_from_little_data_script_3.py
Created November 1, 2018 14:05 — forked from fchollet/classifier_from_little_data_script_3.py
Fine-tuning a Keras model. Updated to the Keras 2.0 API.
'''This script goes along the blog post
"Building powerful image classification models using very little data"
from blog.keras.io.
It uses data that can be downloaded at:
https://www.kaggle.com/c/dogs-vs-cats/data
In our setup, we:
- created a data/ folder
- created train/ and validation/ subfolders inside data/
- created cats/ and dogs/ subfolders inside train/ and validation/
- put the cat pictures index 0-999 in data/train/cats
@yunlongdong
yunlongdong / get_batch.py
Created November 1, 2018 12:28
get batch items from a list obj
my_list = ['geeks', 'for', 'geeks', 'like',
'geeky','nerdy', 'geek', 'love',
'questions','words', 'life']
# Yield successive n-sized
# chunks from L.
def divide_chunks(L, n):
# looping till length l
for i in range(0, len(L), n):
@yunlongdong
yunlongdong / DrawPolyLIne.py
Created August 18, 2018 11:30
Draw polygen around the line
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
x = np.arange(10)
y = np.random.rand(10)
ymax = y + np.random.rand(10)/5
ymin = y - np.random.rand(10)/5
xy = list(zip(x, ymin)) + list(zip(x, ymax))[::-1]