Skip to content

Instantly share code, notes, and snippets.

View pmeier's full-sized avatar

Philip Meier pmeier

View GitHub Profile
from metadata_filter import MetadataFilterOperator
OPERATOR_MAP = {
MetadataFilterOperator.AND: "$and",
MetadataFilterOperator.OR: "$or",
MetadataFilterOperator.EQ: "$eq",
}
def translate(filter):
@pmeier
pmeier / remove_annotations.py
Created January 12, 2023 10:51
Remove Python 3 annotations from a codebase
import functools
import pathlib
import sys
import libcst as cst
def main(root):
root = pathlib.Path(root)
fn = functools.partial(remove_annotations, annotations_remover=AnnotationRemover())

Benchmark script and results for torchvision.transforms.functional v1 vs v2

Run benchmark.py to reproduce the results.

To add a new benchmark, add a BenchmarkConfig to BENCHMARK_CONFIGS in configs.py

@pmeier
pmeier / download.py
Created June 9, 2022 19:05
Simple download function in Python using requests and tqdm
import pathlib
from urllib.parse import urlparse
import requests
import tqdm
def download(url, root=".", *, name=None, chunk_size=32 * 1024):
root = pathlib.Path(root)
root.mkdir(exist_ok=True, parents=True)
@pmeier
pmeier / README.md
Created July 16, 2021 14:42
Hi Tony!

Hope this works!

Hopefully you can read this 🎉

@pmeier
pmeier / revert_submodule_updates.py
Created June 14, 2021 06:39
Revert submodule commits accidentally included in the most recent commit
import os
import pathlib
import re
import shlex
import subprocess
import sys
def main():
if git("status", "--porcelain"):
@pmeier
pmeier / type_promotion_array_api.py
Created May 21, 2021 09:51
Check inter-category type promotion behavior of 0d-tensors for array API compatibility
import itertools
from typing import Collection
import networkx as nx
# overwrite this with the array API that you want to test
import numpy as array_api
def maybe_add_dtype(
@pmeier
pmeier / pytorch_pytest.md
Created April 1, 2021 08:26
A case for pytest in PyTorch

A case for pytest in PyTorch

This is a short post about why I think it would be beneficial for PyTorch to not only use pytest as test runner, but also rely on the other features it provides.

Disclaimer

My experience with the PyTorch test suite is limited as of now. Thus, it might very well be that my view on things is too naive. In that case I'm happy to hear about examples where and adoption of pytest would make a use case significantly harder or outright impossible.

Setup

@pmeier
pmeier / torchvision_datasets_transforms.md
Created February 11, 2021 14:05
Availability of (target_)?transform(s)? arguments in torchvision.datasets

This is an overview over the usage of the availability of the transform, target_transform, and transforms arguments for all datasets from torchvision.datasets.

Dataset transform target_transform transforms
Caltech101 x x
Caltech256 x x
CelebA x x
CIFAR10 x x
CIFAR100 x x
Cityscapes x x x
@pmeier
pmeier / blub.py
Last active November 19, 2020 08:12
test gist
80:
################################################################################
81:
#################################################################################
82:
##################################################################################
83:
###################################################################################
84:
####################################################################################