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 / install_tensorflow-2.6.0.sh
Last active October 19, 2023 13:58
Scripts for installing tensorflow-2.6.0 on JetPack-4.6
s#!/bin/bash
set -e
# tensorflow version
version=2.6.0
if [[ ! $(head -1 /etc/nv_tegra_release) =~ R32.*6\.1 ]] ; then
echo "ERROR: not JetPack-4.6"
exit 1
@jkjung-avt
jkjung-avt / crawl_salaries.py
Last active July 18, 2022 09:10
從公開資訊觀測站下載108年度台灣上市、上櫃公司 "非擔任主管職務之全時員工薪資資訊"
"""crawl_salaries.py
For crawling average salaries of all public listed companies on Taiwan
Stock Exchange. Data source: https://mops.twse.com.tw/mops/web/t100sb15
Source code reference:
https://blog.techbridge.cc/2019/07/26/how-to-use-taiwan-salary-data-to-do-python-data-analytics-and-data-visualization/
Usage:
$ python3 crawl_salaries.py
@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 / 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 / caffemodel_nv_to_bvlc.py
Last active August 29, 2022 08:21
Script to convert a nv-caffe saved caffemodel file into another file which could be read by bvlc-caffe
"""caffemodel_nv_to_bvlc.py
1. compile the nv-caffe's caffe.proto to caffe_pb2.py
2. use caffemodel_nv_to_bvlc.py to convert the nv-caffe caffemodel file
into bvlc-caffe compatible format.
Example usage:
$ cd ${HOME}/project/nv-caffe
$ protoc src/caffe/proto/caffe.proto --python_out=.
$ python3 ./caffemodel_nv_to_bvlc.py <in.caffemodel> <out.caffemodel>
@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
@jkjung-avt
jkjung-avt / gcp-run.sh
Created September 29, 2018 06:35
Example command to initiate a GCP ML training job
# export YOUR_GCS_BUCKET=oxford-iiit-pets-dataset
gcloud ml-engine jobs submit training `whoami`_object_detection_pets_`date +%m_%d_%Y_%H_%M_%S` \
--runtime-version 1.9 \
--job-dir=gs://${YOUR_GCS_BUCKET}/model_dir \
--packages /home/jkjung/src/tensorflow/models/research/dist/object_detection-0.1.tar.gz,/home/jkjung/src/tensorflow/models/research/slim/dist/slim-0.1.tar.gz,/tmp/pycocotools/pycocotools-2.0.tar.gz \
--module-name object_detection.model_main \
--region asia-east1 \
--config cloud-ssd_mobilenet_v1_pets.yml \
-- \
@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 / camera-ssd-threaded.py
Last active June 20, 2023 15:11 — forked from ck196/ssd_500_detect.py
Capture live video from camera and do Single-Shot Multibox Detector (SSD) object detetion in Caffe on Jetson TX2/TX1.
# --------------------------------------------------------
# Camera Single-Shot Multibox Detector (SSD) sample code
# for Tegra X2/X1
#
# This program captures and displays video from IP CAM,
# USB webcam, or the Tegra onboard camera, and do real-time
# object detection with Single-Shot Multibox Detector (SSD)
# in Caffe. Refer to the following blog post for how to set
# up and run the code:
#