Skip to content

Instantly share code, notes, and snippets.

View innat's full-sized avatar
:octocat:
Working from home

Mohammed Innat innat

:octocat:
Working from home
View GitHub Profile
import tensorflow as tf
from tensorflow import keras
class RGBShift(keras.layers.Layer):
"""RGBShift class randomly shift values for each channel of the input RGB image.
"""
def __init__(
self,
factor,
seed=None,
import tensorflow as tf
from tensorflow import keras
class ColorJitter(keras.layers.Layer):
def __init__(
self,
brightness_factor=0.5,
contrast_factor=(0.5, 0.9),
saturation_factor=(0.5, 0.9),
hue_factor=0.5,
import tensorflow as tf
from tensorflow import keras
class ChannelShuffle(keras.layers.Layer):
def __init__(self, groups=3, seed=None, **kwargs):
super().__init__(**kwargs)
self.groups = groups
self.seed = seed
def _channel_shuffling(self, images):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@innat
innat / tf_clahe.py
Created February 21, 2023 13:07
CLAHE implemented in TensorFlow 2
```
# original repo: https://github.com/isears/tf_clahe
# check https://github.com/isears/tf_clahe/issues/1#issuecomment-1356676495
!pip install -q --no-deps /kaggle/input/tfpackages/tf_clahe-0.1.0-py3-none-any.whl
```
import tf_clahe
class CLAHE(keras.layers.Layer):
def __init__(
@innat
innat / WeightedBinaryCrossEntropy.py
Last active April 3, 2023 07:50
Weighted BinaryCrossEntropy Loss in Keras
import tensorflow as tf
def weighted_binary_loss(weight, from_logits=True, reduction="mean"):
def inverse_sigmoid(sigmoidal):
return - tf.math.log(1. / sigmoidal - 1.)
def weighted_loss(labels, predictions):
predictions = tf.convert_to_tensor(predictions)
labels = tf.cast(labels, predictions.dtype)
num_samples = tf.cast(tf.shape(labels)[-1], dtype=labels.dtype)
# Base Image: Ubuntu + Cuda
FROM nvidia/cuda:11.0.3-devel-ubuntu20.04 AS python_base_cuda
# ENV SET
ENV PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
"""
Reference
# https://github.com/fuenwang/PanoramaUtility
# https://github.com/fuenwang/Equirec2Perspec
# https://github.com/fuenwang/PanoramaUtility
# https://github.com/timy90022/Perspective-and-Equirectangular
"""
import os
import sys