Skip to content

Instantly share code, notes, and snippets.

View jkjung-avt's full-sized avatar

JK Jung jkjung-avt

View GitHub Profile
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
#import cPickle as pickle
import _pickle 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jkjung-avt
jkjung-avt / extract_features.py
Created February 25, 2018 02:31
Example OpenCV feature extracteor
# Feature extractor
def extract_features(image_path, vector_size=32):
image = imread(image_path, mode="RGB")
try:
# Using KAZE, cause SIFT, ORB and other was moved to additional module
# which is adding addtional pain during install
alg = cv2.KAZE_create()
# Dinding image keypoints
kps = alg.detect(image)
# Getting first 32 of them.
@jkjung-avt
jkjung-avt / disjoint_set.py
Last active April 5, 2020 11:37
I practiced coding a maze generator with the Disjoint Set data structure
"""disjoint_set.py
"""
import random
class DisjointSet(object):
"""DisjointSet
@jkjung-avt
jkjung-avt / .vimrc
Last active June 19, 2021 03:25
My .vimrc file
" JK Jung's .vmirc
"
" Reference:
"
" 1. Sample .vimrc by Martin Brochhaus, presented at PyCon APAC 2012
" https://github.com/mbrochh/vim-as-a-python-ide
" 2. https://realpython.com/vim-and-python-a-match-made-in-heaven/
" 3. https://github.com/fisadev/fisa-vim-config
" 4. https://github.com/thesheff17/youtube/blob/master/vim/vimrc
" 5. https://github.com/amix/vimrc
@jkjung-avt
jkjung-avt / tegra-cam-rec.py
Last active August 20, 2021 03:10
A Tegra X2/X1 camera recorder, implemented in python
# --------------------------------------------------------
# Camera Recorder for Tegra X2/X1
#
# This program captures video from IP CAM, USB webcam,
# or the Tegra onboard camera, adds some watermark on
# the video frames and then records it into a TS file.
# The code demonstrates how to use cv2.VideoWriter()
# while taking advantage of TX2/TX1's H.264 H/W encoder
# capabilities.
#
@jkjung-avt
jkjung-avt / build_pytorch-v1.3.1.sh
Last active August 20, 2021 08:04
Scripts for building/installing opencv, pytorch, and tensorflow on my Ubuntu-18.04 x86_64 PC
# Reference: https://michhar.github.io/how-i-built-pytorch-gpu/
# I have a GTX-1080 and a GTX-2080 Ti, thus CUDA_ARCH "6.1" and "7.5".
# Patch cmake if necessary: https://github.com/arrayfire/arrayfire/issues/2330
git clone https://github.com/pytorch/pytorch.git pytorch-v1.3.1
cd pytorch-v1.3.1
git checkout v1.3.1
git submodule update --init --recursive
@jkjung-avt
jkjung-avt / calib_to_float.py
Created October 12, 2021 09:23
Example code for handling TensorRT INT8 calibration file
from pathlib import Path
import struct
lines = Path('calib_yolov4-int8-608.bin').read_text().splitlines()
for line in lines:
pair = line.split(':')
if len(pair) != 2:
continue
assert len(pair[1]) == 9
bstr = bytes.fromhex(pair[1][1:]) # convert to byte string
@jkjung-avt
jkjung-avt / data_generator.py
Created August 31, 2018 12:14
An example multiprocessing-ready data generator for Keras, taken from https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly
import numpy as np
import keras
class DataGenerator(keras.utils.Sequence):
'Generates data for Keras'
def __init__(self, list_IDs, labels, batch_size=32, dim=(32,32,32), n_channels=1,
n_classes=10, shuffle=True):
'Initialization'
self.dim = dim
self.batch_size = batch_size
@jkjung-avt
jkjung-avt / dcgan_mnist.py
Created October 28, 2018 09:44
A simple DCGAN with MNIST
"""dcgan_mnist.py
This script was orginally written by Rowel Atienza (see below), and
was modified by JK Jung <jkjung13@gmail.com>.
------
DCGAN on MNIST using Keras
Author: Rowel Atienza
Project: https://github.com/roatienza/Deep-Learning-Experiments