This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Simple timing decorator """ | |
from functools import wraps | |
from time import time | |
__all__ = ("timer") | |
def timer(f): | |
@wraps(f) | |
def wrap(*args, **kwargs): | |
start = time() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder