Skip to content

Instantly share code, notes, and snippets.

View Compuholic's full-sized avatar

C. E. Compuholic

  • Germany
View GitHub Profile
@Compuholic
Compuholic / augmentations.py
Created May 12, 2025 12:59
Tensorflow Image Augmentation Collection
import tensorflow as tf
def random_mask_boxes(image, num_boxes, box_area_fraction, aspect_ratio_range=(0.3, 3.0), seed=12345):
"""
Applies random black box masks to an RGB image tensor.
Args:
image: A TensorFlow tensor of shape [H, W, 3] representing an RGB image.
num_boxes: Integer, the number of black boxes to place.
@Compuholic
Compuholic / focal_loss.py
Created March 24, 2025 13:53
Multi-class Focal Loss with label smoothing for Tensorflow
import tensorflow as tf
class FocalCrossentropy(tf.keras.losses.Loss):
def __init__(self,
from_logits=False,
alpha=0.25,
gamma=2.0,
label_smoothing=0.0,
axis=-1,