Skip to content

Instantly share code, notes, and snippets.

View thetonus's full-sized avatar

Tony Hammack thetonus

View GitHub Profile
@thetonus
thetonus / verify_image.py
Created January 26, 2024 16:36
Verify an image in python
import contextlib
from pathlib import PATH
from PIL import Image
def _is_valid_image(file: Path) -> bool:
"""Determine if the image is valid
References: https://stackoverflow.com/a/53470882
@thetonus
thetonus / split.py
Created March 3, 2023 18:11
Create train/test/val subsets for a YOLO labeled dataset
""" Create train/test/val subsets for a YOLO labeled dataset for CV projects.
This is inspired by https://github.com/akashAD98/Train_val_Test_split/blob/main/train_val_test.py.
"""
import os
import random
from pathlib import Path
from tqdm import tqdm
@thetonus
thetonus / test.go
Last active July 13, 2021 03:41
Go JSONify Helper
func Jsonify(input interface{}) (string, error) {
var stringifiedJson string
var prettyJson bytes.Buffer
body, err := json.Marshal(input)
if err != nil {
return stringifiedJson, err
}
err = json.Indent(&prettyJson, body, "", " ")
if err != nil {
return stringifiedJson, err
@thetonus
thetonus / background_awaitable.py
Created November 24, 2020 18:54
CPU bound code running efficiently in async mode
"""Background tasks functionality.
Reference: https://eng.lifion.com/navigating-cpu-bound-code-in-an-async-world-a9dcdbfbab5c
"""
import asyncio
from typing import Optional, Union
from functools import wraps, partial
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
@thetonus
thetonus / main.py
Last active July 30, 2020 16:14
Get audio from video where audio levels are above a certain level
import logging
import re
import subprocess
import sys
import ffmpeg
logging.basicConfig(level=logging.INFO, format="%(message)s")
logger = logging.getLogger(__file__)
logger.setLevel(logging.INFO)
@thetonus
thetonus / download.py
Last active October 18, 2022 15:29
Download file with Asyncio and Aiofiles
import asyncio
import os
from typing import List
import aiofiles
import httpx
async def download(client: httpx.AsyncClient, link: str, filename: str) -> None:
""" Download link """
@thetonus
thetonus / timer.py
Last active January 13, 2020 17:27
Timing Decorator
""" Simple timing decorator """
from functools import wraps
from time import time
__all__ = ("timer")
def timer(f):
@wraps(f)
def wrap(*args, **kwargs):
start = time()
""" Convert Keras .h5 model to .tflite """
from tensorflow.contrib import lite
def main(model_path: str) -> None:
try:
converter = lite.TFLiteConverter.from_keras_model_file(model_path)
model = converter.convert()
except Exception as e:
print(e)
@thetonus
thetonus / lambda-stack.sh
Created December 5, 2019 00:06
Deep learning install....
# After install Ubuntu 18.04, run this script by the folks of Lambda Labs.
# Better to let the pros set up your machine - they handle everything, including CUDA and NVIDIA stuff.
# https://lambdalabs.com/lambda-stack-deep-learning-software
LAMBDA_REPO=$(mktemp) && \
wget -O${LAMBDA_REPO} https://lambdalabs.com/static/misc/lambda-stack-repo.deb && \
sudo dpkg -i ${LAMBDA_REPO} && rm -f ${LAMBDA_REPO} && \
sudo apt-get update && sudo apt-get install -y lambda-stack-cuda