Skip to content

Instantly share code, notes, and snippets.

View keuv-grvl's full-sized avatar

Keuv Grvl keuv-grvl

  • Bordeaux, France
View GitHub Profile
@keuv-grvl
keuv-grvl / profile_with_kernprof.py
Last active April 28, 2023 06:50
Profile a fonction with cProfile
@profile
def func1(i: float):
import time
time.sleep(i)
@profile
def func_mother():
func1(1.2)
a = 2 + 3
@keuv-grvl
keuv-grvl / app.py
Created November 7, 2022 11:31
Add helpers to Flask to mimic fastapi decorators
from fast_flask import Flask
app = Flask(__name__)
@app.get("/users/") # equivalent to `@app.route("/users/")` from flask.Flask
def get_user_details(user_id: int = 123):
return {"123": "bob"}
if __name__ == "__main__":
@keuv-grvl
keuv-grvl / gradio_example.py
Created June 2, 2022 07:55
Gradio example for image classification
import gradio as gr
import numpy as np
import tensorflow as tf
import requests
# Load a classification model
model = tf.keras.applications.MobileNetV3Large(
input_shape=None,
alpha=1.0,
minimalistic=False,
-- Learn Lua in 15 Minutes
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
@keuv-grvl
keuv-grvl / wrap_tfop.py
Created October 20, 2021 08:09
Wrap TF op in Keras layer with lambda and closure
import tensorflow as tf
ReduceMean = lambda axis=1: tf.keras.layers.Lambda(lambda x: tf.reduce_mean(x, axis=axis))
i = tf.keras.layers.Input(shape=(5,15)) # shape: [BATCHSIZE, 5, 15]
m = ReduceMean(i) # shape: [BATCHSIZE, 15]
# TODO would be nice to have a wrapping function for any TF op with arbitrary
@keuv-grvl
keuv-grvl / .autoenv.sh
Created February 18, 2021 14:56
Autoactivate Conda env when entering a directory (using dir name or provided name).
# ln -s /path/to/this/.autoenv.sh /path/to/workdir/
if test -f .autoenv_conda_env_name ; then
TARGET_CONDA_ENV="$(cat .autoenv_conda_env_name)"
if [[ $TARGET_CONDA_ENV != $CONDA_DEFAULT_ENV ]]; then
conda activate "$TARGET_CONDA_ENV" 2&>1 2> /dev/null
fi
else
CUR_DIR=$(basename $(pwd))
conda activate "$CUR_DIR-dev" 2> /dev/null \
def perfboxplot(
setup,
kernels,
labels,
n=3,
xlabel="Performances",
equality_check=None,
save_path=None,
log_scale=True,
):
import numpy as np
import pandas as pd
import seaborn as sbn
from matplotlib import pyplot as plt
from scipy.stats import anderson
from sklearn import datasets
from sklearn.cluster import MiniBatchKMeans
from sklearn.preprocessing import scale, LabelEncoder
# TODO doc, memoization
[user]
name = Keuv Grvl
email = k***@***m
[core]
quotepath = false
editor = vim
pager = less -F -x2
[init]
defaultBranch = main
[push]
@keuv-grvl
keuv-grvl / fitsne_wrapper.py
Created March 8, 2019 16:55
FItSNE wrapper
class FItSNE_wrapper:
"""
Wrapper class for FItSNE `fast_tsne.fast_tsne` v1.1.0.
It is currently designed to work in a Conda environment with Python 3.7 and FFTW 3.
Install and compile as follow:
$ conda create -n YOUR-ENV python=3.7 fftw=3
$ source activate YOUR-ENV