-
Notifications
You must be signed in to change notification settings - Fork 5
/
Grayscaler.py
42 lines (29 loc) · 1.01 KB
/
Grayscaler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
"""
from tensorflow.keras.layers import Layer
from tensorflow.keras import backend as K
import tensorflow as tf
import numpy as np
class Grayscaler(Layer):
"""Converts input to grayscale
Only active at training time since it is a regularization layer.
# Arguments
attenuation: how much to attenuate the input
# Input shape
Arbitrary.
# Output shape
Same as the input shape.
"""
def __init__(self, **kwargs):
super(Grayscaler, self).__init__(**kwargs)
self.supports_masking = True
def call(self, inputs, training=None):
def augmented():
return tf.image.rgb_to_grayscale(inputs)
return K.in_train_phase(augmented, augmented, training=training)
def get_config(self):
config = {}
base_config = super(Grayscaler, self).get_config()
return dict(list(base_config.items()) + list(config.items()))