Skip to content

Instantly share code, notes, and snippets.

View jaeoh2's full-sized avatar
๐Ÿ˜ƒ

Jaeoh Lee jaeoh2

๐Ÿ˜ƒ
View GitHub Profile
@jaeoh2
jaeoh2 / pg-pong.py
Created June 2, 2016 01:30 — forked from karpathy/pg-pong.py
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@jaeoh2
jaeoh2 / argparse.py
Created December 6, 2016 03:53
python argparse
from argparse import ArgumentParser
def get_options():
parser = ArgumentParser()
parser.add_argument('--MAX_SIZE', type=int, default=100,
help='max number os size')
parser.add_argument('--GAMMA', type=float, defatult=0.9,
help='disount factor')
options = parser.parse_args()
@jaeoh2
jaeoh2 / read_mat.py
Created December 7, 2016 15:29
read .mat(hdf5) file to python
import h5py
import numpy as np
with h5py.File('mydatafile.mat','r') as hf:
print('List of arrays in this file:{}'.format(hf.keys()))
data = hf.get('dataset_1')
np_data = np.array(data)
print('Shape of the array dataset_1:{}.format(np_data.shape))
@jaeoh2
jaeoh2 / kerasRNN_model.py
Created December 8, 2016 00:26
keras RNN model (TimeDistributed wrapper)
#build model many to one
embedding_vector_length = 32
model = Sequential()
model.add(Embedding(input_dim=top_words,
output_dim=embedding_vector_length,
input_length=max_review_length))
model.add(LSTM(100, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(100, return_sequences=True))
model.add(Dropout(0.2))
@jaeoh2
jaeoh2 / tf_cmp_cpu_gpu.py
Created January 4, 2017 06:58
Tensorflow CNN performance comparison (CPU vs GPU) with mnist dataset
"""
Based from : https://github.com/sjchoi86/tensorflow-101/blob/master/notebooks/cnn_mnist_simple.ipynb
"""
import tensorflow as tf
import os
import sys
import time
from tensorflow.examples.tutorials.mnist import input_data
from __future__ import print_function
'''
Basic Multi GPU computation example using TensorFlow library.
Author: Aymeric Damien
Project: https://github.com/aymericdamien/TensorFlow-Examples/
'''
'''
This tutorial requires your machine to have 2 GPUs
"/cpu:0": The CPU of your machine.
@jaeoh2
jaeoh2 / CAN.cpp
Created February 14, 2019 07:49
CAN bitfield parser for ROS callback
typedef struct CAN_msgTag
{
uint8_t Sig_1 : 8;
uint8_t Sig_2 : 8;
uint8_t Sig_3 : 8;
uint8_t Sig_4 : 8;
uint8_t Sig_5 : 8;
uint8_t Sig_6 : 8;
uint8_t Sig_7 : 8;
uint8_t Sig_8 : 8;
@jaeoh2
jaeoh2 / 2s_comp.cpp
Created March 6, 2019 02:27
Two's complement Upscaler
template <typename Target, size_t Length>
// https://www.codeproject.com/Tips/1079637/Twos-Complement-for-Unusual-Integer-Sizes
class TwosComplementUpscaler
{
Target bitfield : Length;
TwosComplementUpscaler(Target value) : bitfield(value){}
TwosComplementUpscaler();
public:
@jaeoh2
jaeoh2 / python_thread_test.py
Created April 13, 2021 14:13
Python threading Timer callback example
import time
import threading
ser = 0
start_time = time.time()
def callback():
global ser, start_time
if ser == 1:
@jaeoh2
jaeoh2 / joystick.py
Last active July 20, 2022 02:00
python_xbox_controller
# ref from : https://stackoverflow.com/questions/46506850/how-can-i-get-input-from-an-xbox-one-controller-in-python
from inputs import get_gamepad
import math
import threading
class XboxController(object):
MAX_TRIG_VAL = math.pow(2, 8)
MAX_JOY_VAL = math.pow(2, 15)
def __init__(self):