Skip to content

Instantly share code, notes, and snippets.

View Dref360's full-sized avatar

Frédéric Branchaud-Charron Dref360

View GitHub Profile
@Dref360
Dref360 / README.md
Created November 21, 2021 17:25
Code for the blog post "Improving trust in text classification using HF and BaaL"

The code should run as is with the following dependencies:

pip install transformers datasets baal matplotlib tqdm

@Dref360
Dref360 / Dockerfile
Last active August 11, 2024 04:44
How to use BaaL in Label Studio
FROM python:3.7
WORKDIR /tmp
COPY requirements.txt .
RUN pip install --no-cache \
-r requirements.txt \
uwsgi==2.0.19.1 \
supervisor==4.2.2 \
label-studio==1.0.2 \
@Dref360
Dref360 / ignite_baal.py
Last active April 8, 2020 12:53
Example on how to use BaaL inside ignite!
import numpy as np
import torch
from ignite.engine import Engine, Events, create_supervised_trainer
from pydantic import BaseModel
from torch.utils.data import DataLoader
from torchvision.datasets import CIFAR10
from torchvision.models import vgg16
from torchvision.transforms import transforms
from tqdm import tqdm
@Dref360
Dref360 / semisupervised.py
Last active April 8, 2020 06:57
Semi-supervised iterator
from typing import Optional
import numpy as np
import torch
from torch.utils.data import DataLoader, TensorDataset
from baal.active import ActiveLearningDataset
class AlternateIterator:
import gc
import os
import shutil
import tracemalloc
from pathlib import Path
import numpy as np
from keras import backend as K
from keras import callbacks
@Dref360
Dref360 / pre-commit
Created September 21, 2018 16:19
pre-commit for VITAL. to plate in .git/hooks/pre-commit and chmod +x
#!/usr/bin/env python
import subprocess
import sys
def get_staged():
proc = subprocess.Popen(['git', 'diff', '--name-only', '--cached'], stdout=subprocess.PIPE)
staged_files = proc.stdout.readlines()
staged_files = [f.decode('utf-8') for f in staged_files]
staged_files = [f.strip() for f in staged_files]
staged_files = [f for f in staged_files if f.endswith('.py')]
@Dref360
Dref360 / coordconv2d.py
Last active February 11, 2020 14:40
Un-scaled version of CoordConv2D
import keras.backend as K
import tensorflow as tf
from tensorflow.keras.layers import Layer
"""Not tested, I'll play around with GANs soon with it."""
from tensorflow.keras.layers import Conv2D
import numpy as np
class CoordConv2D(Layer):
@Dref360
Dref360 / keras2.2.0_aug.py
Last active December 18, 2019 07:27
Simple example for a DA pipeline using Sequences
import cv2
import numpy as np
from keras.preprocessing.image import ImageDataGenerator
from keras.utils import Sequence
class MySequence(Sequence):
def __init__(self):
self.path = '~/Images/cat.jpg'
self.imgaug = ImageDataGenerator(rotation_range=20,
@Dref360
Dref360 / weights_converter.py
Last active March 12, 2018 20:11
Convert a Keras weight checkpoint train on multigpu to a regular Keras weight checkpoint
import os
from collections import defaultdict
import h5py
import numpy as np
pjoin = os.path.join
def convert_multi_to_single(multipath, fp):
@Dref360
Dref360 / exemple.py
Created February 2, 2018 16:46
Exemple for my class on the importance of clearability
"""Good example"""
def random_shift(x, wrg, hrg, row_axis=1, col_axis=2, channel_axis=0,
fill_mode='nearest', cval=0., tx=None, ty=None):
"""Performs a random spatial shift of a Numpy image tensor.
# Arguments
x: Input tensor. Must be 3D.
wrg: Width shift range, as a float fraction of the width.
hrg: Height shift range, as a float fraction of the height.
row_axis: Index of axis for rows in the input tensor.
col_axis: Index of axis for columns in the input tensor.