Few interesting model on reflection removal algorithm.
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 | |
from tensorflow import keras | |
from tensorflow.keras import Model | |
from tensorflow.keras import layers | |
class ConvoBlocks(tf.keras.layers.Layer): | |
def __init__(self, num_filters=256, | |
kernel_size=3, dilation_rate=1, | |
padding="same", use_bias=False, **kwargs): | |
super(ConvoBlocks, self).__init__(**kwargs) |
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
# Reference: https://keras.io/examples/structured_data/deep_neural_decision_forests/ | |
import tensorflow as tf | |
from tensorflow.keras import layers | |
from tensorflow import keras | |
class NeuralDecisionTree(keras.Model): | |
def __init__(self, depth, num_features, used_features_rate, num_classes): | |
super(NeuralDecisionTree, self).__init__() | |
self.depth = depth |
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 | |
from tensorflow.keras import layers | |
from tensorflow import keras | |
print('TensorFlow', tf.__version__) | |
class ResidualBlock(layers.Layer): | |
def __init__(self, block_type=None, n_filters=None): | |
super(ResidualBlock, self).__init__() | |
self.n_filters = n_filters | |
if block_type == 'identity': |
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
import tensorflow as tf | |
from tensorflow.keras.layers import * | |
from tensorflow.keras.models import Model | |
from tensorflow.keras.utils import plot_model | |
class Conv3DBatchNorm(tf.keras.layers.Layer): | |
def __init__(self, nb_filters, kernel_size, padding, strides): | |
super(Conv3DBatchNorm, self).__init__() | |
# parameters | |
self.nb_filters = nb_filters |
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 vis(path1, path2, n_images, is_random=True, figsize=(16, 16)): | |
''' | |
https://github.com/innat | |
''' | |
plt.figure(figsize=figsize) | |
image_names = os.listdir(path1) | |
masks_names = os.listdir(path2) | |
for i in range(n_images): | |
if is_random: |
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
""" | |
pip install tensorflow | |
pip install tf2onnx keras2onnx onnxmltools | |
""" | |
import os | |
import pdb | |
import json | |
import traceback | |
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" |
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 | |
# credit: https://stackoverflow.com/a/66524901/9215780 | |
class CustomTrainStep(tf.keras.Model): | |
def __init__(self, n_gradients, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.n_gradients = tf.constant(n_gradients, dtype=tf.int32) | |
self.n_acum_step = tf.Variable(0, dtype=tf.int32, trainable=False) | |
self.gradient_accumulation = [tf.Variable(tf.zeros_like(v, dtype=tf.float32), | |
trainable=False) for v in self.trainable_variables] |
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 | |
import random, math | |
from scipy.stats import beta | |
def binarise_mask(mask, lam, in_shape, max_soft=0.0): | |
""" Binarises a given low frequency image such that it has mean lambda. | |
:param mask: Low frequency image, usually the result of `make_low_freq_image` | |
:param lam: Mean value of final mask | |
:param in_shape: Shape of inputs | |
:param max_soft: Softening value between 0 and 0.5 which smooths hard edges in the mask. |