Skip to content

Instantly share code, notes, and snippets.

View Erotemic's full-sized avatar
An eroteme is a question mark

Jon Crall Erotemic

An eroteme is a question mark
View GitHub Profile
@Erotemic
Erotemic / kwcoco_vectorized_demo.py
Created December 15, 2021 16:36
kwcoco_vectorized_demo.py
def demo_vectorized_interface():
"""
This demonstrates how to use the kwcoco vectorized interface for images /
categories / annotations.
"""
import kwcoco
import ubelt as ub
# Dummy data for the demo
coco_dset = kwcoco.CocoDataset.demo('vidshapes3', num_frames=5)
# Reroot to make file-paths more readable in this demo as relative paths
@Erotemic
Erotemic / normalize_quotes.py
Created September 8, 2021 03:06
Normalize quote
import redbaron
import ubelt as ub
import re
import xdev
# INPUT:
# fpath = <path-to-the-file>
text = open(fpath).read()
@Erotemic
Erotemic / benchmark_first_generator.py
Last active September 1, 2021 22:55
benchmark_first_generator.py
"""
References:
https://github.com/willmcgugan/rich/blob/master/rich/_loop.py
https://twitter.com/graingert/status/1432827783357607937
"""
from typing import Iterable, Tuple, TypeVar
T = TypeVar("T")
@Erotemic
Erotemic / napkin_math_hospotializations_by_age_2021.py
Created July 30, 2021 01:59
Napkin Math Hospitalizations By Age
# https://gis.cdc.gov/grasp/covidnet/COVID19_5.html
# 2020-21
import ubelt as ub
US_POP_APPROX = 330e6
SAMPLE_SIZE = US_POP_APPROX * 0.1
print(SAMPLE_SIZE)
# NOTE: These are lab-verified COVID numbers. The sample size is 190509. This
# represents about 10% of the US population. This chart says total observed
@Erotemic
Erotemic / autogen_skimage_filters_init.py
Created December 24, 2020 19:39
Demo auto-generated version of skimage.filters
def lazy_install(module_name, submodules, submod_attrs):
"""
Defines gettr for lazy import via PEP 562
https://www.python.org/dev/peps/pep-0562/
"""
import sys
import importlib
import importlib.util
all_funcs = []
for mod, funcs in submod_attrs.items():
"""
Experiment Script Related to Pytorch Memory Leak Issue
References:
https://github.com/pytorch/pytorch/issues/13246
https://gist.github.com/mprostock/2850f3cd465155689052f0fa3a177a50
"""
from torch.utils.data import Dataset, DataLoader
import numpy as np
import torch
@Erotemic
Erotemic / gist:244890e27b37aa2219ac2f3414f8c302
Created February 9, 2019 17:44
cant find temp ninja error
(py36) joncrall@Ooo:~/code/netharn$ python setup.py build
--------------------------------------------------------------------------------
-- Trying "Ninja" generator
--------------------------------
---------------------------
----------------------
-----------------
------------
@Erotemic
Erotemic / gist:1f9b19ad1d116c9731ce7f446f020ce4
Created February 9, 2019 17:41
cant find numpy error with pip install
(py36) joncrall@Ooo:~/code/netharn$ ./setup.py clean && pip install -e .
Deleting directory="./__pycache__"
Deleting directory="./_skbuild"
Not deleting non-existant path="./__pycache__/skbuild_pr.cpython-36.pyc"
Obtaining file:///home/joncrall/code/netharn
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: torch in /home/joncrall/.local/conda/envs/py36/lib/python3.6/site-packages (from netharn==0.1.8.dev0) (1.0.0)
Requirement already satisfied: tqdm in /home/joncrall/.local/conda/envs/py36/lib/python3.6/site-packages (from netharn==0.1.8.dev0) (4.23.4)
# -*- coding: utf-8 -*-
"""
This module can be used as both a script and an importable module.
Run `python ggr_matching.py --help` for more details.
See docstring in fit for more details on the importable module.
conda install opencv
conda install pytorch torchvision -c pytorch
@Erotemic
Erotemic / ubuntu_setup_venv3_standalone.sh
Last active December 19, 2018 16:46
The setup_venv3 bash command sets up a python3 virtual environment on a fresh ubuntu install. The file contains quite a few helper functions that make the actual implementation of setup_venv3 rather short.
__heredoc__(){ NOOP=; }
has_pymodule(){
__heredoc__ '''
Check if a python module is installed. Echos "True" or "False" to the
command line depending on the result.
Example:
source $HOME/local/init/utils.sh