Skip to content

Instantly share code, notes, and snippets.

View yptheangel's full-sized avatar
Working from home

Choo Wilson yptheangel

Working from home
View GitHub Profile
@yptheangel
yptheangel / generateLmdbfromImagefolder.errlog
Created February 3, 2020 17:48
traceback of errors from generate lmdb from imagefolder
(base) D:\Efficient-PyTorch\tools>python folder2lmdb.py -f "C:\Users\ChooWilson\.fastai\data\kaggle-cat-dog" -s train
Loading dataset from C:\Users\ChooWilson\.fastai\data\kaggle-cat-dog\train
Generate LMDB to C:\Users\ChooWilson\.fastai\data\kaggle-cat-dog\train.lmdb
2000 2000
Traceback (most recent call last):
File "folder2lmdb.py", line 181, in <module>
folder2lmdb(args.folder, num_workers=args.procs, name=args.split)
File "folder2lmdb.py", line 150, in folder2lmdb
for idx, data in enumerate(data_loader):
File "C:\Users\ChooWilson\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 279, in __iter__
@yptheangel
yptheangel / getConvexHull.py
Created January 12, 2020 14:29
get convex hull of an image
#Original source from https://github.com/opencv/opencv/blob/master/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py
from __future__ import print_function
import cv2 as cv
import numpy as np
import argparse
import random as rng
rng.seed(12345)
@yptheangel
yptheangel / TensorflowCallbackExample.py
Created January 5, 2020 13:51
TensorflowCallbackExample
class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
if(logs.get('acc')>0.6):
print("\nReached 60% accuracy so cancelling training!")
self.model.stop_training = True
@yptheangel
yptheangel / YOLO2DL4J.java
Last active September 13, 2020 14:06
YOLOV2 Object detection and using Colormap for annotating bounding box
import org.bytedeco.ffmpeg.global.avcodec;
import org.bytedeco.ffmpeg.global.avutil;
import org.bytedeco.javacv.*;
import org.bytedeco.opencv.opencv_core.*;
import static org.bytedeco.opencv.global.opencv_imgproc.*;
import static org.bytedeco.opencv.helper.opencv_core.RGB;
import org.bytedeco.opencv.opencv_videoio.VideoWriter;
import org.datavec.image.loader.NativeImageLoader;
import org.datavec.image.transform.ColorConversionTransform;
import org.deeplearning4j.nn.graph.ComputationGraph;
@yptheangel
yptheangel / putText_with_background.java
Last active October 21, 2019 09:20
draw_text_with_background_opencv
int baseline[]={0};
Size textSize=getTextSize("Hello World", FONT_HERSHEY_DUPLEX, 1,1,baseline);
int textwidth=textSize.get(0);
int textheight=textSize.get(1);
rectangle(yourMat, new Point(x1 + 2, y2 - 2), new Point(x1 + 2+textwidth, y2 - 2-textheight),RGB(255,255,0), FILLED,0,0);
putText(yourMat, "Hello World", new Point(x1 + 2, y2 - 2), FONT_HERSHEY_DUPLEX, 1, RGB(0,0,0));
@yptheangel
yptheangel / putText_with_background.java
Created October 21, 2019 08:44
draw_text_with_background_opencv
int baseline[]={0};
Size textSize=getTextSize("Hello World", FONT_HERSHEY_DUPLEX, 1,1,baseline);
int textwidth=textSize.get(0);
int textheight=textSize.get(1);
rectangle(yourMat, new Point(x1 + 2, y2 - 2), new Point(x1 + 2+textwidth, y2 - 2-textheight),RGB(255,255,0), FILLED,0,0);
import timeit
import time
start_time = timeit.default_timer()
# Using time module to create the delay, you can replce this line with your process
time.sleep(1)
end_time = timeit.default_timer()
elapsed_time = end_time - start_time
# Round the elapsed time to 2 decimal points
print("Elapsed time: {}".format(round(elapsed_time,2)))
@yptheangel
yptheangel / JavaTimer.java
Created September 1, 2019 10:40
Use a timer to count the time to complete a function in Java
import java.util.concurrent.TimeUnit;
public class JavaTimer{
public static void main(String []args){
long start_time =System.nanoTime();
//Create a delay of 1 second or 1000milliseconds
try{
Thread.sleep(1000);
@yptheangel
yptheangel / build.gradle
Created August 27, 2019 08:37
Gradle for DL4J TinyYOLO inference
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.yptheangel.dl4jandroid.yolo_objdetection"
minSdkVersion 24
targetSdkVersion 24
versionCode 1
@yptheangel
yptheangel / TinyYoloObjDetectionVideo.java
Created August 27, 2019 08:32
An activity code that streams Camera frames and run Tiny YOLO object detection in real time on Android OS
package com.yptheangel.dl4jandroid.yolo_objdetection;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import com.yptheangel.dl4jandroid.yolo_objdetection.utils.VOCLabelsAndroid;
import static android.os.Environment.getExternalStoragePublicDirectory;