Skip to content

Instantly share code, notes, and snippets.

@tetebueno
tetebueno / google_photos_takeout_metadata_resolver.py
Created February 18, 2021 13:39
Google Photos Takeout archive holds a JSON file with photo/video metadata, thing is that the naming for this JSON file is not always so obvious. This takes care of resolving the name with all the variants I found so far.
import re as _re
import json as _json
JSON_EXTENSION = '.json'
def find_json_for_file(file: Path):
try:
if file.with_name(file.name + JSON_EXTENSION).is_file():
# file.jpg -> file.jpg.json
the_json_path = file.with_name(file.name + JSON_EXTENSION)
@wassname
wassname / jaccard_coef_loss.py
Last active January 30, 2024 15:45
jaccard_coef_loss for keras. This loss is usefull when you have unbalanced classes within a sample such as segmenting each pixel of an image. For example you are trying to predict if each pixel is cat, dog, or background. You may have 80% background, 10% dog, and 10% cat. Should a model that predicts 100% background be 80% right, or 30%? Categor…
from keras import backend as K
def jaccard_distance_loss(y_true, y_pred, smooth=100):
"""
Jaccard = (|X & Y|)/ (|X|+ |Y| - |X & Y|)
= sum(|A*B|)/(sum(|A|)+sum(|B|)-sum(|A*B|))
The jaccard distance loss is usefull for unbalanced datasets. This has been
shifted so it converges on 0 and is smoothed to avoid exploding or disapearing
gradient.