Skip to content

Instantly share code, notes, and snippets.

# Assume labels is a possibly multidimensional array of categories / token indices
_, label_counts = np.unique(labels, axis=None, return_counts=True) # Will flatten multidimensional arrays
# For multi-label classification you should normalize by the number of samples instead
label_frequencies = label_counts.astype(np.float) / np.sum(label_counts)
label_logprobs = np.log(label_frequencies)
# Now you just need to assign the values in label_logprobs to your bias vector!
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alpercalisir
alpercalisir / xmlAnnotation.py
Created November 24, 2018 13:58
Creates PASCAL VOC formatted XML given a csv file
import pandas as pd
import numpy as np
from lxml import etree
import xmlAnnotation.etree.cElementTree as ET
fields = ['NAME_ID', 'XMIN', 'YMIN', 'W', 'H', 'XMAX', 'YMAX']
df = pd.read_csv('loose_bb_test.csv', usecols=fields)
# Change the name of the file.
@stefanonardo
stefanonardo / early_stopping.py
Last active February 28, 2024 19:21
Early Stopping PyTorch
# MIT License
#
# Copyright (c) 2018 Stefano Nardo https://gist.github.com/stefanonardo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@douglasrizzo
douglasrizzo / tf_obj_tutorial.md
Last active November 15, 2023 22:36
TensorFlow Object Detection Model Training
@soply
soply / disp_multiple_images.py
Last active January 9, 2024 14:52
Plot multiple images with matplotlib in a single figure. Titles can be given optionally as second argument.
import matplotlib.pyplot as plt
import numpy as np
def show_images(images, cols = 1, titles = None):
"""Display a list of images in a single figure with matplotlib.
Parameters
---------
images: List of np.arrays compatible with plt.imshow.