Skip to content

Instantly share code, notes, and snippets.

View iaverypadberg's full-sized avatar

Isaac Padberg iaverypadberg

View GitHub Profile
@iaverypadberg
iaverypadberg / break_frames_2.sh
Created February 14, 2023 14:17
Use FFMPEG to break a viddeo in to 320x320 crops at 3fps
ffmpeg -i bg_3.mp4 -vb 30M -filter:v "crop=320:320:200:600, fps=3" frames/office_2_%04d.jpg
@iaverypadberg
iaverypadberg / run_tflite_on_folder.py
Created November 8, 2022 13:35
A python script for running tflite inference on a folder of images
from sqlite3 import adapt
import numpy as np
from PIL import Image
import glob
import cv2
import numpy as np
import tflite_runtime.interpreter as tflite
@iaverypadberg
iaverypadberg / background_dataset.md
Created September 29, 2022 19:46
Building a Background Dataset From Scratch

Building a background dataset from scratch

For object detection models with very few classes (<5) and no background images, most models will struggle with false positives. The model is only learning what the thing is that it needs to detect. This is only half the problem.

The other half is that the model needs to learn what not to detect. Heres where background images come in.

Aquire background images

The easiest way to get some background images is to take a video with a smart phone and chop it into individual frames.

@iaverypadberg
iaverypadberg / scratch.kt
Created September 8, 2022 20:54
Kotlin Scratch File
import org.jetbrains.kotlinx.multik.api.toNDArray
import org.jetbrains.kotlinx.multik.ndarray.data.get
import org.jetbrains.kotlinx.multik.ndarray.data.slice
import org.jetbrains.kotlinx.multik.ndarray.operations.last
import org.jetbrains.kotlinx.multik.ndarray.operations.minus
import org.jetbrains.kotlinx.multik.ndarray.operations.plus
import org.jetbrains.kotlinx.multik.ndarray.operations.toList
// Filter out all items
val startList = listOf(Pair(1,.2),Pair(2,.4),Pair(3,.6),Pair(4,.3))
@iaverypadberg
iaverypadberg / argsort.kt
Created September 6, 2022 20:39
Argsort in Kotlin
private fun argsort(needsSorting : Array<Int>){
val theRange = IntRange(0,needsSorting.size-1)
val idxs = theRange.toList().sortedBy { needsSorting[it] }
}
@iaverypadberg
iaverypadberg / find_wrong_labels.py
Last active August 2, 2022 17:38
Find wrong labels in dataset
#from importlib.metadata import files
import xml.etree.ElementTree as ET
import glob
# Sort through a dataset's xml files and print out file names that contain labels which are invalid
valid_labels = ["frodo","baggins"]
# Loop through all xml files
files = glob.glob('/home/isaac/Desktop/work_area/working_on/*.xml')
@iaverypadberg
iaverypadberg / shrink_images.py
Created May 19, 2022 18:09
Changes the scales down the image size and the corresponding bounding box.
import random
from re import S
import xml.etree.ElementTree as ET
from glob import glob
import cv2
input_dir ='/home/isaac/Desktop/work_area/working_on/'
files = glob(input_dir+'*.png')
# For each file with a .png extension
@iaverypadberg
iaverypadberg / ssd_mobilenet training on ubuntu 20.04-with gpu - conda & pip.MD
Last active May 10, 2022 15:47
ssd_mobilenet training on ubuntu 20.04-with gpu - conda & pip

Configuring a tensorflow environment to work with gpu's is really annoying. Thankfully, conda & pipmake it a lot less annoying.

Here are the core dependencies for getting this to work.

  • cudatoolkit=11.6.0
  • cudnn=8.2.1.32
  • tensorflow=2.7.0
  • tensorflow-gpu=2.7.0
  • tensorflow-io=0.25.0
  • python=3.9
@iaverypadberg
iaverypadberg / remove_annotation_label.py
Last active April 26, 2022 13:50
Remove annotation label from an xml file
import xml.etree.ElementTree as ET
from glob import glob
labels = [
"labels",
"to",
"be",
"removed"]
files = glob('directory/with/xml/files/*.xml')
for file in files:
@iaverypadberg
iaverypadberg / copy_xml_and_jpg.py
Created April 25, 2022 21:01
Copy corresponding xml and jpg files(predicated on labels)
from re import T
import os
import subprocess
from glob import glob
import xml.etree.ElementTree as ET
labels = [
"some",
"labels",