Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired from https://github.com/JohannesBuchner/imagehash repository | |
import imagehash | |
from PIL import Image | |
def alpharemover(image): | |
if image.mode != 'RGBA': | |
return image | |
canvas = Image.new('RGBA', image.size, (255,255,255,255)) | |
canvas.paste(image, mask=image) | |
return canvas.convert('RGB') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
class CustomEarlyStopping(tf.keras.callbacks.Callback): | |
""" | |
Custom Early Stopping callback to monitor multiple metrics by combining them using a harmonic mean calculation. | |
Adapted from (TensorFlow EarlyStopping source)[https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/keras/callbacks.py#L1683-L1823]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.utils.class_weight import compute_class_weight | |
from sklearn.preprocessing import MultiLabelBinarizer | |
def generate_class_weights(class_series, multi_class=True, one_hot_encoded=False): | |
""" | |
Method to generate class weights given a set of multi-class or multi-label labels, both one-hot-encoded or not. | |
Some examples of different formats of class_series and their outputs are: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_dataset_partitions_pd(df, train_split=0.8, val_split=0.1, test_split=0.1): | |
assert (train_split + test_split + val_split) == 1 | |
# Only allows for equal validation and test splits | |
assert val_split == test_split | |
# Specify seed to always have the same split distribution between runs | |
df_sample = df.sample(frac=1, random_state=12) | |
indices_or_sections = [int(train_split * len(df)), int((1 - val_split - test_split) * len(df))] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_dataset_partitions_tf(ds, ds_size, train_split=0.8, val_split=0.1, test_split=0.1, shuffle=True, shuffle_size=10000): | |
assert (train_split + test_split + val_split) == 1 | |
if shuffle: | |
# Specify seed to always have the same split distribution between runs | |
ds = ds.shuffle(shuffle_size, seed=12) | |
train_size = int(train_split * ds_size) | |
val_size = int(val_split * ds_size) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import tensorboard as tb | |
import statistics | |
def get_best_epoch_per_model( | |
experiment_id, | |
metrics, | |
format_as_percentage = False, | |
sort_values = False, | |
group_by_model_names = False, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add custom language selector field for XProfileFields Buddypress | |
// Author: Angel Igareta, adapted from https://tulipemedia.com/en/buddypress-auto-bulk-import-countries-profile-field/ | |
function bp_add_custom_language_list() { | |
if ( !xprofile_get_field_id_from_name('Languages Spoken') && 'bp-profile-setup' == $_GET['page'] ) { | |
$language_list_args = array( | |
'field_group_id' => 1, | |
'name' => 'Languages Spoken', | |
'description' => 'Please select the languages you speak', | |
'can_delete' => true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
👉🏼<⚫>👈🏼 |