Skip to content

Instantly share code, notes, and snippets.

View jkjung-avt's full-sized avatar

JK Jung jkjung-avt

View GitHub Profile
@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 / 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 / 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 / .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 / 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 / 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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
""" 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